diff options
| author | Ikalco <73481042+ikalco@users.noreply.github.com> | 2025-08-29 15:16:40 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-29 22:16:40 +0200 |
| commit | ea42041f936d5810c5cfa45d6bece12dde2fd9b6 (patch) | |
| tree | d600f5a6a4fcdee8f3e24b666d1ea57ccc88cdd6 /src/protocols/PointerWarp.cpp | |
| parent | 05a1c0aa7395d19213e587c83089ecbd7b92085c (diff) | |
protocols: implement pointer-warp-v1 (#11469)
Diffstat (limited to 'src/protocols/PointerWarp.cpp')
| -rw-r--r-- | src/protocols/PointerWarp.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/protocols/PointerWarp.cpp b/src/protocols/PointerWarp.cpp new file mode 100644 index 00000000..bde0b913 --- /dev/null +++ b/src/protocols/PointerWarp.cpp @@ -0,0 +1,53 @@ +#include "PointerWarp.hpp" +#include "core/Compositor.hpp" +#include "core/Seat.hpp" +#include "../desktop/WLSurface.hpp" +#include "../managers/SeatManager.hpp" +#include "../managers/PointerManager.hpp" +#include "../desktop/Window.hpp" + +CPointerWarpProtocol::CPointerWarpProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) { + ; +} + +void CPointerWarpProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) { + const auto& RESOURCE = m_managers.emplace_back(makeUnique<CWpPointerWarpV1>(client, ver, id)); + + if UNLIKELY (!RESOURCE->resource()) { + wl_client_post_no_memory(client); + m_managers.pop_back(); + return; + } + + RESOURCE->setOnDestroy([this](CWpPointerWarpV1* pMgr) { destroyManager(pMgr); }); + RESOURCE->setDestroy([this](CWpPointerWarpV1* pMgr) { destroyManager(pMgr); }); + + RESOURCE->setWarpPointer([](CWpPointerWarpV1* pMgr, wl_resource* surface, wl_resource* pointer, wl_fixed_t x, wl_fixed_t y, uint32_t serial) { + const auto PSURFACE = CWLSurfaceResource::fromResource(surface); + if (g_pSeatManager->m_state.pointerFocus != PSURFACE) + return; + + auto SURFBOXV = CWLSurface::fromResource(PSURFACE)->getSurfaceBoxGlobal(); + if (!SURFBOXV.has_value()) + return; + + const auto SURFBOX = SURFBOXV->expand(1); + const auto LOCALPOS = Vector2D{wl_fixed_to_double(x), wl_fixed_to_double(y)}; + const auto GLOBALPOS = LOCALPOS + SURFBOX.pos(); + if (!SURFBOX.containsPoint(GLOBALPOS)) + return; + + const auto PSEAT = CWLPointerResource::fromResource(pointer)->m_owner.lock(); + if (!g_pSeatManager->serialValid(PSEAT, serial, false)) + return; + + LOGM(LOG, "warped pointer to {}", GLOBALPOS); + + g_pPointerManager->warpTo(GLOBALPOS); + g_pSeatManager->sendPointerMotion(Time::millis(Time::steadyNow()), LOCALPOS); + }); +} + +void CPointerWarpProtocol::destroyManager(CWpPointerWarpV1* manager) { + std::erase_if(m_managers, [&](const UP<CWpPointerWarpV1>& resource) { return resource.get() == manager; }); +} |
