From 9b4632a8da6131874eb8a78af2ed097f487f4286 Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 19 Oct 2026 20:14:51 +0200 Subject: [PATCH] Restore wl-copy clipboard clearing on Wayland Fixes #13809 --- src/gui/osutils/nixutils/NixUtils.cpp | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/gui/osutils/nixutils/NixUtils.cpp b/src/gui/osutils/nixutils/NixUtils.cpp index 3b350583f..96746d497 100644 --- a/src/gui/osutils/nixutils/NixUtils.cpp +++ b/src/gui/osutils/nixutils/NixUtils.cpp @@ -407,16 +407,11 @@ bool NixUtils::setClipboardText(const QString& text) bool NixUtils::clearClipboardText(const QString& text) { // The remote desktop portal tracks whether KeePassXC owns the selection, so - // NixUtils does not need the copied text to decide whether clearing is safe. - Q_UNUSED(text) - - if (!autoType()->isAvailable() || !autoType()->usesDesktopPortal()) { - return false; - } - + // it does not need the copied text to decide whether clearing is safe. auto* portal = m_remoteDesktopPortal; - if (portal && autoType()->isAvailable() && config()->get(Config::AutoTypeDesktopPortalUseClipboard).toBool() - && portal->isClipboardAvailable() && portal->hasSession()) { + if (portal && autoType()->isAvailable() && autoType()->usesDesktopPortal() + && config()->get(Config::AutoTypeDesktopPortalUseClipboard).toBool() && portal->isClipboardAvailable() + && portal->hasSession()) { if (portal->clearClipboardText()) { return true; } @@ -425,12 +420,14 @@ bool NixUtils::clearClipboardText(const QString& text) return false; } + if (!qEnvironmentVariableIsSet("WAYLAND_DISPLAY")) { + return false; + } + + // Don't clear data another application has put into the clipboard in the meantime. auto* clipboard = QApplication::clipboard(); - auto hasClipboardData = clipboard && clipboard->mimeData(QClipboard::Clipboard) - && !clipboard->mimeData(QClipboard::Clipboard)->formats().isEmpty(); - auto hasSelectionData = clipboard && clipboard->supportsSelection() && clipboard->mimeData(QClipboard::Selection) - && !clipboard->mimeData(QClipboard::Selection)->formats().isEmpty(); - if (hasClipboardData || hasSelectionData) { + auto* mimeData = clipboard ? clipboard->mimeData(QClipboard::Clipboard) : nullptr; + if (mimeData && !mimeData->formats().isEmpty() && mimeData->text() != text) { return false; }