From 90fd5fcb2e97527c3d10bd05087628870da0b3e7 Mon Sep 17 00:00:00 2001 From: Daniel Fox Date: Sat, 10 May 2025 18:07:12 -0700 Subject: [PATCH] Remove QT+GNOME+Wayland 'xcb' hack on fixed Qt versions (#3683) * Bypass the Qt GNOME/Wayland workaround on fixed Qt versions We implement code on GNOME desktops to force the QT_QPA_PLATFORM to be 'xcb'; this works around a clipboard-related bug on GNOME+Wayland+Qt. This bug was fixed (or worked around) in Qt 5.15.2, so we implement a version check; if the runtime Qt version is < 5.15.2, still force the workaround; otherwise, we don't need the workaround so we skip it. * Reformat with clang-format --- src/main.cpp | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 5e8766fa..e7c1675f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -37,10 +37,28 @@ // source: https://github.com/ksnip/ksnip/issues/416 void wayland_hacks() { - // Workaround to https://github.com/ksnip/ksnip/issues/416 + int suffixIndex; DesktopInfo info; - if (info.windowManager() == DesktopInfo::GNOME) { - qputenv("QT_QPA_PLATFORM", "xcb"); + + const char* qt_version = qVersion(); + + QVersionNumber targetVersion(5, 15, 2); + QString string(qt_version); + QVersionNumber currentVersion = + QVersionNumber::fromString(string, &suffixIndex); + + if (currentVersion < targetVersion) { + if (info.windowManager() == DesktopInfo::GNOME) { + qWarning() + << "Qt versions lower than" << targetVersion.toString() + << "on GNOME using Wayland have a bug when accessing the " + "clipboard." + << "Your version is" << currentVersion.toString() + << "so we're forcing QT_QPA_PLATFORM to 'xcb'." + << "To use native Wayland, please upgrade your Qt version to" + << targetVersion.toString() << "or higher"; + qputenv("QT_QPA_PLATFORM", "xcb"); + } } } #endif