Skip to content

Commit 0b23861

Browse files
committed
wayland fallback on X11-Ogre
When running on wayland with Ogre without wayland support, explicitly force Qt to use the XCB protocol running through Xwayland. Backported with adaptations from ros2/rviz#847 .
1 parent c4964de commit 0b23861

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/rviz/main.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,32 @@
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 force the xcb platform in Qt unless the user set it
40+
std::vector<char*> args;
41+
for (int i = 0; i < argc; ++i)
42+
{
43+
args.push_back(argv[i]);
44+
}
45+
auto env = QProcessEnvironment::systemEnvironment();
46+
if (env.value("XDG_SESSION_TYPE") == "wayland" &&
47+
args.end() == std::find(args.begin(), args.end(), "-platform") && !env.contains("QT_QPA_PLATFORM"))
48+
{
49+
static const char* xcb_platform_args[] = {"-platform", "xcb"};
50+
args.push_back(const_cast<char*>(xcb_platform_args[0]));
51+
args.push_back(const_cast<char*>(xcb_platform_args[1]));
52+
}
53+
argc = static_cast<int>(args.size());
54+
argv = args.data();
55+
#endif
56+
3657
QApplication qapp(argc, argv);
3758

3859
rviz::VisualizerApp vapp;

0 commit comments

Comments
 (0)