From abbdcfb0cef7c8fddf3d20fe099f4524229c140b Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Sun, 15 Feb 2026 12:30:02 +0800 Subject: fix: address copilot review comments - Fix log level from INFO to DEBUG in DataDevice.cpp for offer operations - Remove unused permissionToHumanString function - Add I18n keys for clipboard read/write permissions - Add primary selection permission check in XWM.cpp (was only checking clipboard) - Add async permission handling in DataDeviceWlr.cpp for zwlr protocol --- src/protocols/DataDeviceWlr.cpp | 84 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) (limited to 'src/protocols/DataDeviceWlr.cpp') diff --git a/src/protocols/DataDeviceWlr.cpp b/src/protocols/DataDeviceWlr.cpp index 6cf343bd..e42156fd 100644 --- a/src/protocols/DataDeviceWlr.cpp +++ b/src/protocols/DataDeviceWlr.cpp @@ -32,6 +32,32 @@ CWLRDataOffer::CWLRDataOffer(SP resource_, SPpromiseFor(CLIENT, PERMISSION_TYPE_CLIPBOARD_READ); + if (!PROMISE) { + LOGM(Log::ERR, "BUG THIS: No promise for client permission for clipboard read"); + return; + } + auto sharedFd = std::make_shared(std::move(sendFd)); + PROMISE->then([this, mime = std::string(mime ? mime : ""), sharedFd](SP> pr) { + if (pr->hasError()) { + LOGM(Log::ERR, "BUG THIS: No permission returned for clipboard read"); + return; + } + + if (pr->result() != PERMISSION_RULE_ALLOW_MODE_ALLOW) { + LOGM(Log::INFO, "Clipboard read denied by user"); + return; + } + + if (!m_source) { + LOGM(Log::WARN, "Source disappeared while waiting for permission"); + return; + } + + LOGM(Log::DEBUG, "Offer {:x} asks to send data from source {:x} (permission granted)", (uintptr_t)this, (uintptr_t)m_source.get()); + + m_source->send(mime, std::move(*sharedFd)); + }); return; } @@ -137,6 +163,35 @@ CWLRDataDevice::CWLRDataDevice(SP resource_) : m_resou return; } else if (PERM == PERMISSION_RULE_ALLOW_MODE_PENDING) { LOGM(Log::INFO, "Clipboard write permission pending for client {:x}", (uintptr_t)CLIENT); + const auto PROMISE = g_pDynamicPermissionManager->promiseFor(CLIENT, PERMISSION_TYPE_CLIPBOARD_WRITE); + if (!PROMISE) { + LOGM(Log::ERR, "BUG THIS: No promise for client permission for clipboard write"); + return; + } + PROMISE->then([source](SP> pr) mutable { + if (pr->hasError()) { + LOGM(Log::ERR, "BUG THIS: No permission returned for clipboard write"); + return; + } + + if (pr->result() != PERMISSION_RULE_ALLOW_MODE_ALLOW) { + LOGM(Log::INFO, "Clipboard write denied by user"); + return; + } + + if (!source) { + LOGM(Log::WARN, "Source disappeared while waiting for permission"); + return; + } + + if (source && source->used()) + LOGM(Log::WARN, "setSelection on a used resource. By protocol, this is a violation, but firefox et al insist on doing this."); + + source->markUsed(); + + LOGM(Log::DEBUG, "wlr manager requests selection to {:x}", (uintptr_t)source.get()); + g_pSeatManager->setCurrentSelection(source); + }); return; } @@ -164,6 +219,35 @@ CWLRDataDevice::CWLRDataDevice(SP resource_) : m_resou return; } else if (PERM == PERMISSION_RULE_ALLOW_MODE_PENDING) { LOGM(Log::INFO, "Clipboard write permission pending for client {:x}", (uintptr_t)CLIENT); + const auto PROMISE = g_pDynamicPermissionManager->promiseFor(CLIENT, PERMISSION_TYPE_CLIPBOARD_WRITE); + if (!PROMISE) { + LOGM(Log::ERR, "BUG THIS: No promise for client permission for clipboard write"); + return; + } + PROMISE->then([source](SP> pr) mutable { + if (pr->hasError()) { + LOGM(Log::ERR, "BUG THIS: No permission returned for clipboard write"); + return; + } + + if (pr->result() != PERMISSION_RULE_ALLOW_MODE_ALLOW) { + LOGM(Log::INFO, "Clipboard write denied by user"); + return; + } + + if (!source) { + LOGM(Log::WARN, "Source disappeared while waiting for permission"); + return; + } + + if (source && source->used()) + LOGM(Log::WARN, "setSelection on a used resource. By protocol, this is a violation, but firefox et al insist on doing this."); + + source->markUsed(); + + LOGM(Log::DEBUG, "wlr manager requests primary selection to {:x}", (uintptr_t)source.get()); + g_pSeatManager->setCurrentPrimarySelection(source); + }); return; } -- cgit v1.2.3