Restore wl-copy clipboard clearing on Wayland

Fixes #13809
This commit is contained in:
Christian authored and Janek Bevendorff committed 2026-10-20 17:49:51 +02:00
1 parent 6c686af438
commit 9b4632a8da
1 file changed
+11 -14
+11 -14
View File
@@ -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;
}