From 3d45f23b022878444454ec1a47c25678b88868c6 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Sat, 2 Jul 2022 13:56:00 +0400 Subject: [PATCH] QGtk3Theme: Ensure gtk uses the same windowing system as Qt Fixes: QTBUG-69354 Pick-to: 6.4 6.3 6.2 5.15 Change-Id: I254c5bf98bc3b2cc2577159e475a2105438bb96b Reviewed-by: Liang Qi --- src/plugins/platformthemes/gtk3/qgtk3theme.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) 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);