diff options
Diffstat (limited to 'src/protocols')
| -rw-r--r-- | src/protocols/DataDeviceWlr.cpp | 84 | ||||
| -rw-r--r-- | src/protocols/core/DataDevice.cpp | 2 |
2 files changed, 85 insertions, 1 deletions
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<CZwlrDataControlOfferV1> resource_, SP<IDataSour return; } else if (PERM == PERMISSION_RULE_ALLOW_MODE_PENDING) { LOGM(Log::INFO, "Clipboard read permission pending for client {:x}", (uintptr_t)CLIENT); + const auto PROMISE = g_pDynamicPermissionManager->promiseFor(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<CFileDescriptor>(std::move(sendFd)); + PROMISE->then([this, mime = std::string(mime ? mime : ""), sharedFd](SP<CPromiseResult<eDynamicPermissionAllowMode>> 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<CZwlrDataControlDeviceV1> 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<CPromiseResult<eDynamicPermissionAllowMode>> 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<CZwlrDataControlDeviceV1> 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<CPromiseResult<eDynamicPermissionAllowMode>> 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; } diff --git a/src/protocols/core/DataDevice.cpp b/src/protocols/core/DataDevice.cpp index d0ccd123..e61f6776 100644 --- a/src/protocols/core/DataDevice.cpp +++ b/src/protocols/core/DataDevice.cpp @@ -97,7 +97,7 @@ CWLDataOfferResource::CWLDataOfferResource(SP<CWlDataOffer> resource_, SP<IDataS return; } - LOGM(Log::INFO, "Offer {:x} asks to send data from source {:x}", (uintptr_t)this, (uintptr_t)m_source.get()); + LOGM(Log::DEBUG, "Offer {:x} asks to send data from source {:x}", (uintptr_t)this, (uintptr_t)m_source.get()); if (!m_accepted) { LOGM(Log::WARN, "Offer was never accepted, sending accept first"); |
