diff --git a/src/devices/IPointer.hpp b/src/devices/IPointer.hpp index 5df47c04..760ec8dc 100644 --- a/src/devices/IPointer.hpp +++ b/src/devices/IPointer.hpp @@ -106,7 +106,8 @@ class IPointer : public IHID { } pointerEvents; std::string hlName; - bool connected = false; // means connected to the cursor + bool connected = false; // means connected to the cursor + std::string boundOutput = ""; WP self; }; diff --git a/src/devices/VirtualPointer.cpp b/src/devices/VirtualPointer.cpp index f9a1c409..9223ebe1 100644 --- a/src/devices/VirtualPointer.cpp +++ b/src/devices/VirtualPointer.cpp @@ -38,6 +38,8 @@ CVirtualPointer::CVirtualPointer(SP resource) : point listeners.holdBegin = pointer->events.holdBegin.registerListener([this](std::any d) { pointerEvents.holdBegin.emit(d); }); listeners.holdEnd = pointer->events.holdEnd.registerListener([this](std::any d) { pointerEvents.holdEnd.emit(d); }); + boundOutput = resource->boundOutput ? resource->boundOutput->szName : "auto"; + deviceName = pointer->name; } diff --git a/src/managers/PointerManager.cpp b/src/managers/PointerManager.cpp index 3b425688..59c54c78 100644 --- a/src/managers/PointerManager.cpp +++ b/src/managers/PointerManager.cpp @@ -674,6 +674,16 @@ void CPointerManager::warpAbsolute(Vector2D abs, SP dev) { } break; } + case HID_TYPE_POINTER: { + IPointer* POINTER = reinterpret_cast(dev.get()); + if (!POINTER->boundOutput.empty() && POINTER->boundOutput != "auto") { + if (const auto PMONITOR = g_pCompositor->getMonitorFromString(POINTER->boundOutput); PMONITOR) { + currentMonitor = PMONITOR->self.lock(); + mappedArea = currentMonitor->logicalBox(); + } + } + break; + } default: break; } diff --git a/src/protocols/VirtualPointer.cpp b/src/protocols/VirtualPointer.cpp index bdeec32d..8626241a 100644 --- a/src/protocols/VirtualPointer.cpp +++ b/src/protocols/VirtualPointer.cpp @@ -1,8 +1,9 @@ #include "VirtualPointer.hpp" +#include "core/Output.hpp" #define LOGM PROTO::virtualPointer->protoLog -CVirtualPointerV1Resource::CVirtualPointerV1Resource(SP resource_) : resource(resource_) { +CVirtualPointerV1Resource::CVirtualPointerV1Resource(SP resource_, WP boundOutput_) : boundOutput(boundOutput_), resource(resource_) { if (!good()) return; @@ -112,10 +113,18 @@ void CVirtualPointerProtocol::bindManager(wl_client* client, void* data, uint32_ RESOURCE->setOnDestroy([this](CZwlrVirtualPointerManagerV1* p) { this->onManagerResourceDestroy(p->resource()); }); RESOURCE->setDestroy([this](CZwlrVirtualPointerManagerV1* p) { this->onManagerResourceDestroy(p->resource()); }); - RESOURCE->setCreateVirtualPointer([this](CZwlrVirtualPointerManagerV1* pMgr, wl_resource* seat, uint32_t id) { this->onCreatePointer(pMgr, seat, id); }); + RESOURCE->setCreateVirtualPointer([this](CZwlrVirtualPointerManagerV1* pMgr, wl_resource* seat, uint32_t id) { this->onCreatePointer(pMgr, seat, id, {}); }); RESOURCE->setCreateVirtualPointerWithOutput([this](CZwlrVirtualPointerManagerV1* pMgr, wl_resource* seat, wl_resource* output, uint32_t id) { - LOGM(WARN, "TODO: CreateWithOutput is not supported yet. Ignoring for now."); - this->onCreatePointer(pMgr, seat, id); + if (output) { + auto RES = CWLOutputResource::fromResource(output); + if (!RES) { + this->onCreatePointer(pMgr, seat, id, {}); + return; + } + + this->onCreatePointer(pMgr, seat, id, RES->monitor); + } else + this->onCreatePointer(pMgr, seat, id, {}); }); } @@ -127,9 +136,9 @@ void CVirtualPointerProtocol::destroyResource(CVirtualPointerV1Resource* pointer std::erase_if(m_vPointers, [&](const auto& other) { return other.get() == pointer; }); } -void CVirtualPointerProtocol::onCreatePointer(CZwlrVirtualPointerManagerV1* pMgr, wl_resource* seat, uint32_t id) { +void CVirtualPointerProtocol::onCreatePointer(CZwlrVirtualPointerManagerV1* pMgr, wl_resource* seat, uint32_t id, WP output) { - const auto RESOURCE = m_vPointers.emplace_back(makeShared(makeShared(pMgr->client(), pMgr->version(), id))); + const auto RESOURCE = m_vPointers.emplace_back(makeShared(makeShared(pMgr->client(), pMgr->version(), id), output)); if (!RESOURCE->good()) { pMgr->noMemory(); diff --git a/src/protocols/VirtualPointer.hpp b/src/protocols/VirtualPointer.hpp index ee5ee7e2..1a51d977 100644 --- a/src/protocols/VirtualPointer.hpp +++ b/src/protocols/VirtualPointer.hpp @@ -11,7 +11,7 @@ class CVirtualPointerV1Resource { public: - CVirtualPointerV1Resource(SP resource_); + CVirtualPointerV1Resource(SP resource_, WP boundOutput_); ~CVirtualPointerV1Resource(); struct { @@ -34,10 +34,12 @@ class CVirtualPointerV1Resource { CSignal holdEnd; } events; - bool good(); - wl_client* client(); + bool good(); + wl_client* client(); - std::string name; + std::string name; + + WP boundOutput; private: SP resource; @@ -60,7 +62,7 @@ class CVirtualPointerProtocol : public IWaylandProtocol { private: void onManagerResourceDestroy(wl_resource* res); void destroyResource(CVirtualPointerV1Resource* pointer); - void onCreatePointer(CZwlrVirtualPointerManagerV1* pMgr, wl_resource* seat, uint32_t id); + void onCreatePointer(CZwlrVirtualPointerManagerV1* pMgr, wl_resource* seat, uint32_t id, WP output); // std::vector> m_vManagers;