diff --git a/src/plugins/platformthemes/gtk3/qgtk3theme.cpp b/src/plugins/platformthemes/gtk3/qgtk3theme.cpp index 22a079732a7..51e19175d6f 100644 --- a/src/plugins/platformthemes/gtk3/qgtk3theme.cpp +++ b/src/plugins/platformthemes/gtk3/qgtk3theme.cpp @@ -6,6 +6,7 @@ #include "qgtk3menu.h" #include #include +#include #undef signals #include @@ -14,6 +15,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + const char *QGtk3Theme::name = "gtk3"; template @@ -49,6 +52,14 @@ void gtkMessageHandler(const gchar *log_domain, QGtk3Theme::QGtk3Theme() { + // Ensure gtk uses the same windowing system, but let it + // fallback in case GDK_BACKEND environment variable + // filters the preferred one out + if (QGuiApplication::platformName().startsWith("wayland"_L1)) + gdk_set_allowed_backends("wayland,x11"); + else if (QGuiApplication::platformName() == "xcb"_L1) + gdk_set_allowed_backends("x11,wayland"); + // gtk_init will reset the Xlib error handler, and that causes // Qt applications to quit on X errors. Therefore, we need to manually restore it. int (*oldErrorHandler)(Display *, XErrorEvent *) = XSetErrorHandler(nullptr);