Skip to content

Commit b62f00d

Browse files
authored
Enforce xcb platform on Wayland (#1850)
Wayland support for Ogre was only added in version 14. Thus, when running on Wayland with older Ogre, we need to explicitly enforce Qt's xcb platform protocol, essentially running X11 through Xwayland. Backported with adaptations from ros2/rviz#847.
1 parent a6fe99c commit b62f00d

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/rviz/main.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,35 @@
2828
*/
2929

3030
#include <QApplication>
31+
#include <QProcessEnvironment>
3132

3233
#include <rviz/visualizer_app.h>
3334

3435
int main(int argc, char** argv)
3536
{
37+
#if !OGRE_USE_WAYLAND
38+
// If Ogre does not support wayland, but we are running on wayland,
39+
// explicitly enforce the xcb platform for Qt unless the user set the platform
40+
std::vector<char*> args;
41+
for (int i = 0; i < argc; ++i)
42+
{
43+
args.push_back(argv[i]);
44+
}
45+
46+
auto env = QProcessEnvironment::systemEnvironment();
47+
if (env.value("XDG_SESSION_TYPE") == "wayland" &&
48+
std::find(args.begin(), args.end(), "-platform") == args.end() && // no -platform arg
49+
!env.contains("QT_QPA_PLATFORM")) // no env setting of platform
50+
{
51+
std::cout << "Enforcing xcb platform instead of wayland." << std::endl;
52+
static const char* xcb_platform_args[] = {"-platform", "xcb"};
53+
args.push_back(const_cast<char*>(xcb_platform_args[0]));
54+
args.push_back(const_cast<char*>(xcb_platform_args[1]));
55+
argc = static_cast<int>(args.size());
56+
argv = args.data();
57+
}
58+
#endif
59+
3660
QApplication qapp(argc, argv);
3761

3862
rviz::VisualizerApp vapp;

0 commit comments

Comments
 (0)