Skip to content

Commit 72c0826

Browse files
authored
Detect wayland and make sure X rendering is used. (#1253)
rviz2 does not work under wayland unless using X compatibility. The current workaround on wayland is to set the QT_QPA_PLATFORM environment variable to xcb. This patch now detects if rviz2 is started in a wayland session and if so sets that variable automatically. Signed-off-by: Matthew Elwin <[email protected]>
1 parent a38e9af commit 72c0826

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

rviz2/src/main.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <vector>
3535

3636
#include <QApplication> // NOLINT: cpplint is unable to handle the include order here
37+
#include <QProcessEnvironment> // NOLINT: cpplint is unable to hande the include order here
3738

3839
#include "rclcpp/rclcpp.hpp"
3940
#include "rviz_common/logging.hpp"
@@ -44,6 +45,20 @@ int main(int argc, char ** argv)
4445
{
4546
// remove ROS arguments before passing to QApplication
4647
std::vector<std::string> non_ros_args = rclcpp::remove_ros_arguments(argc, argv);
48+
49+
// check for wayland and if so force the use of X to render everything
50+
// but only if the user hasn't already tried to specify -platform
51+
// or override QT_QPA_PLATFORM
52+
auto env = QProcessEnvironment::systemEnvironment();
53+
if(env.value("XDG_SESSION_TYPE") == "wayland" &&
54+
non_ros_args.end() == std::find(non_ros_args.begin(), non_ros_args.end(),
55+
"-platform") &&
56+
!env.contains("QT_QPA_PLATFORM"))
57+
{
58+
non_ros_args.push_back("-platform");
59+
non_ros_args.push_back("xcb");
60+
}
61+
4762
std::vector<char *> non_ros_args_c_strings;
4863
for (auto & arg : non_ros_args) {
4964
non_ros_args_c_strings.push_back(&arg.front());

0 commit comments

Comments
 (0)