From 1958c523e9dc1f7fd47ca8614b7e0ce15497d480 Mon Sep 17 00:00:00 2001 From: Jan Grulich Date: Tue, 11 Jan 2022 15:38:08 +0100 Subject: [PATCH] Gtk3Theme: set XCURSOR_SIZE and XCURSOR_THEME for wayland sessions GNOME doesn't set these for Wayland session and without those env variables set users might experience broken cursor with Qt apps as QWayland reads them to setup QWaylandInputDevice. There is no cursor protocol available on Wayland yet, see also https://gitlab.freedesktop.org/wayland/wayland-protocols/-/issues/58 Qt Wayland QPA plugin still tries to load from those two envs. Fixes: QTBUG-67579 Fixes: QTBUG-87778 Change-Id: I4e7f6871b56599170b12e796858238b1df6d47d1 Reviewed-by: Liang Qi Reviewed-by: Eskil Abrahamsen Blomfeldt (cherry picked from commit c0b0c7bebb73e1aa609196ce33668a54bd5e0aef) Reviewed-by: Qt Cherry-pick Bot --- src/plugins/platformthemes/gtk3/qgtk3theme.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/plugins/platformthemes/gtk3/qgtk3theme.cpp b/src/plugins/platformthemes/gtk3/qgtk3theme.cpp index ab607a0c6d6..b00d618f7e2 100644 --- a/src/plugins/platformthemes/gtk3/qgtk3theme.cpp +++ b/src/plugins/platformthemes/gtk3/qgtk3theme.cpp @@ -102,6 +102,20 @@ QGtk3Theme::QGtk3Theme() SETTING_CONNECT("gtk-application-prefer-dark-theme"); SETTING_CONNECT("gtk-theme-name"); #undef SETTING_CONNECT + + /* Set XCURSOR_SIZE and XCURSOR_THEME for Wayland sessions */ + if (QGuiApplication::platformName().startsWith("wayland"_L1)) { + if (qEnvironmentVariableIsEmpty("XCURSOR_SIZE")) { + const int cursorSize = gtkSetting("gtk-cursor-theme-size"); + if (cursorSize > 0) + qputenv("XCURSOR_SIZE", QString::number(cursorSize).toUtf8()); + } + if (qEnvironmentVariableIsEmpty("XCURSOR_THEME")) { + const QString cursorTheme = gtkSetting("gtk-cursor-theme-name"); + if (!cursorTheme.isEmpty()) + qputenv("XCURSOR_THEME", cursorTheme.toUtf8()); + } + } } static inline QVariant gtkGetLongPressTime()