From 7e1807c09285a5daa3276c6eb264c5bbb181a693 Mon Sep 17 00:00:00 2001 From: Daniel Fox Date: Wed, 31 Jul 2024 15:05:14 -0700 Subject: [PATCH 1/2] 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. --- src/main.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 23d3157e01..b9361d77be 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -37,10 +37,23 @@ // 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 From bc5bd2e437c99a2902fb3304c3b048a6e835dfbb Mon Sep 17 00:00:00 2001 From: Daniel Fox Date: Tue, 1 Oct 2024 14:22:18 -0700 Subject: [PATCH 2/2] Reformat with clang-format --- src/main.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index b9361d77be..43ad27078c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -40,18 +40,23 @@ void wayland_hacks() int suffixIndex; DesktopInfo info; - const char *qt_version = qVersion(); + const char* qt_version = qVersion(); QVersionNumber targetVersion(5, 15, 2); QString string(qt_version); - QVersionNumber currentVersion = QVersionNumber::fromString(string, &suffixIndex); + 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"; + 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"); } }