From 94c20a186372aace78b188842848b873eb3ebbd7 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Mon, 13 May 2024 21:47:59 +0100 Subject: primary-selection: move to hyprland impl --- src/protocols/DataDeviceWlr.cpp | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) (limited to 'src/protocols/DataDeviceWlr.cpp') diff --git a/src/protocols/DataDeviceWlr.cpp b/src/protocols/DataDeviceWlr.cpp index a518b0ae..c039d3b4 100644 --- a/src/protocols/DataDeviceWlr.cpp +++ b/src/protocols/DataDeviceWlr.cpp @@ -145,7 +145,7 @@ CWLRDataDevice::CWLRDataDevice(SP resource_) : resourc source->markUsed(); LOGM(LOG, "wlr manager requests primary selection to {:x}", (uintptr_t)source.get()); - g_pSeatManager->setCurrentSelection(source); + g_pSeatManager->setCurrentPrimarySelection(source); }); } @@ -170,6 +170,10 @@ void CWLRDataDevice::sendSelection(SP selection) { resource->sendSelection(selection->resource.get()); } +void CWLRDataDevice::sendPrimarySelection(SP selection) { + resource->sendPrimarySelection(selection->resource.get()); +} + CWLRDataControlManagerResource::CWLRDataControlManagerResource(SP resource_) : resource(resource_) { if (!good()) return; @@ -259,9 +263,14 @@ void CDataDeviceWLRProtocol::destroyResource(CWLRDataOffer* resource) { std::erase_if(m_vOffers, [&](const auto& other) { return other.get() == resource; }); } -void CDataDeviceWLRProtocol::sendSelectionToDevice(SP dev, SP sel) { - if (!sel) +void CDataDeviceWLRProtocol::sendSelectionToDevice(SP dev, SP sel, bool primary) { + if (!sel) { + if (primary) + dev->resource->sendPrimarySelectionRaw(nullptr); + else + dev->resource->sendSelectionRaw(nullptr); return; + } const auto OFFER = m_vOffers.emplace_back(makeShared(makeShared(dev->resource->client(), dev->resource->version(), 0), sel)); @@ -271,34 +280,41 @@ void CDataDeviceWLRProtocol::sendSelectionToDevice(SP dev, SPprimary = primary; + + LOGM(LOG, "New {}offer {:x} for data source {:x}", primary ? "primary " : " ", (uintptr_t)OFFER.get(), (uintptr_t)sel.get()); dev->sendDataOffer(OFFER); OFFER->sendData(); - dev->sendSelection(OFFER); + if (primary) + dev->sendPrimarySelection(OFFER); + else + dev->sendSelection(OFFER); } -void CDataDeviceWLRProtocol::setSelection(SP source) { +void CDataDeviceWLRProtocol::setSelection(SP source, bool primary) { for (auto& o : m_vOffers) { if (o->source && o->source->hasDnd()) continue; + if (o->primary != primary) + continue; o->dead = true; } if (!source) { - LOGM(LOG, "resetting selection"); + LOGM(LOG, "resetting {}selection", primary ? "primary " : " "); for (auto& d : m_vDevices) { - sendSelectionToDevice(d, nullptr); + sendSelectionToDevice(d, nullptr, primary); } return; } - LOGM(LOG, "New selection for data source {:x}", (uintptr_t)source.get()); + LOGM(LOG, "New {}selection for data source {:x}", primary ? "primary" : "", (uintptr_t)source.get()); for (auto& d : m_vDevices) { - sendSelectionToDevice(d, source); + sendSelectionToDevice(d, source, primary); } } -- cgit v1.2.3