virtualptr: allow binding to output

This commit is contained in:
Vaxry 2024-07-29 16:27:09 +02:00
parent 70468857da
commit 23a8f06594
5 changed files with 36 additions and 12 deletions

View file

@ -107,6 +107,7 @@ class IPointer : public IHID {
std::string hlName;
bool connected = false; // means connected to the cursor
std::string boundOutput = "";
WP<IPointer> self;
};

View file

@ -38,6 +38,8 @@ CVirtualPointer::CVirtualPointer(SP<CVirtualPointerV1Resource> 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;
}

View file

@ -674,6 +674,16 @@ void CPointerManager::warpAbsolute(Vector2D abs, SP<IHID> dev) {
}
break;
}
case HID_TYPE_POINTER: {
IPointer* POINTER = reinterpret_cast<IPointer*>(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;
}

View file

@ -1,8 +1,9 @@
#include "VirtualPointer.hpp"
#include "core/Output.hpp"
#define LOGM PROTO::virtualPointer->protoLog
CVirtualPointerV1Resource::CVirtualPointerV1Resource(SP<CZwlrVirtualPointerV1> resource_) : resource(resource_) {
CVirtualPointerV1Resource::CVirtualPointerV1Resource(SP<CZwlrVirtualPointerV1> resource_, WP<CMonitor> 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<CMonitor> output) {
const auto RESOURCE = m_vPointers.emplace_back(makeShared<CVirtualPointerV1Resource>(makeShared<CZwlrVirtualPointerV1>(pMgr->client(), pMgr->version(), id)));
const auto RESOURCE = m_vPointers.emplace_back(makeShared<CVirtualPointerV1Resource>(makeShared<CZwlrVirtualPointerV1>(pMgr->client(), pMgr->version(), id), output));
if (!RESOURCE->good()) {
pMgr->noMemory();

View file

@ -11,7 +11,7 @@
class CVirtualPointerV1Resource {
public:
CVirtualPointerV1Resource(SP<CZwlrVirtualPointerV1> resource_);
CVirtualPointerV1Resource(SP<CZwlrVirtualPointerV1> resource_, WP<CMonitor> boundOutput_);
~CVirtualPointerV1Resource();
struct {
@ -39,6 +39,8 @@ class CVirtualPointerV1Resource {
std::string name;
WP<CMonitor> boundOutput;
private:
SP<CZwlrVirtualPointerV1> 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<CMonitor> output);
//
std::vector<UP<CZwlrVirtualPointerManagerV1>> m_vManagers;