summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIkalco <73481042+ikalco@users.noreply.github.com>2025-08-29 15:16:40 -0500
committerGitHub <noreply@github.com>2025-08-29 22:16:40 +0200
commitea42041f936d5810c5cfa45d6bece12dde2fd9b6 (patch)
treed600f5a6a4fcdee8f3e24b666d1ea57ccc88cdd6 /src
parent05a1c0aa7395d19213e587c83089ecbd7b92085c (diff)
protocols: implement pointer-warp-v1 (#11469)
Diffstat (limited to 'src')
-rw-r--r--src/managers/ProtocolManager.cpp3
-rw-r--r--src/managers/SeatManager.cpp5
-rw-r--r--src/managers/SeatManager.hpp2
-rw-r--r--src/protocols/PointerWarp.cpp53
-rw-r--r--src/protocols/PointerWarp.hpp21
-rw-r--r--src/protocols/core/Seat.cpp9
-rw-r--r--src/protocols/core/Seat.hpp6
7 files changed, 96 insertions, 3 deletions
diff --git a/src/managers/ProtocolManager.cpp b/src/managers/ProtocolManager.cpp
index b70d3b7d..c9690aba 100644
--- a/src/managers/ProtocolManager.cpp
+++ b/src/managers/ProtocolManager.cpp
@@ -64,6 +64,7 @@
#include "../protocols/XDGBell.hpp"
#include "../protocols/ExtWorkspace.hpp"
#include "../protocols/ExtDataDevice.hpp"
+#include "../protocols/PointerWarp.hpp"
#include "../helpers/Monitor.hpp"
#include "../render/Renderer.hpp"
@@ -192,6 +193,7 @@ CProtocolManager::CProtocolManager() {
PROTO::xdgBell = makeUnique<CXDGSystemBellProtocol>(&xdg_system_bell_v1_interface, 1, "XDGBell");
PROTO::extWorkspace = makeUnique<CExtWorkspaceProtocol>(&ext_workspace_manager_v1_interface, 1, "ExtWorkspace");
PROTO::extDataDevice = makeUnique<CExtDataDeviceProtocol>(&ext_data_control_manager_v1_interface, 1, "ExtDataDevice");
+ PROTO::pointerWarp = makeUnique<CPointerWarpProtocol>(&wp_pointer_warp_v1_interface, 1, "PointerWarp");
if (*PENABLECM)
PROTO::colorManagement = makeUnique<CColorManagementProtocol>(&wp_color_manager_v1_interface, 1, "ColorManagement", *PDEBUGCM);
@@ -295,6 +297,7 @@ CProtocolManager::~CProtocolManager() {
PROTO::xdgBell.reset();
PROTO::extWorkspace.reset();
PROTO::extDataDevice.reset();
+ PROTO::pointerWarp.reset();
for (auto& [_, lease] : PROTO::lease) {
lease.reset();
diff --git a/src/managers/SeatManager.cpp b/src/managers/SeatManager.cpp
index bc4f2dfc..15316dc6 100644
--- a/src/managers/SeatManager.cpp
+++ b/src/managers/SeatManager.cpp
@@ -58,7 +58,7 @@ uint32_t CSeatManager::nextSerial(SP<CWLSeatResource> seatResource) {
return serial;
}
-bool CSeatManager::serialValid(SP<CWLSeatResource> seatResource, uint32_t serial) {
+bool CSeatManager::serialValid(SP<CWLSeatResource> seatResource, uint32_t serial, bool erase) {
if (!seatResource)
return false;
@@ -68,7 +68,8 @@ bool CSeatManager::serialValid(SP<CWLSeatResource> seatResource, uint32_t serial
for (auto it = container->serials.begin(); it != container->serials.end(); ++it) {
if (*it == serial) {
- container->serials.erase(it);
+ if (erase)
+ container->serials.erase(it);
return true;
}
}
diff --git a/src/managers/SeatManager.hpp b/src/managers/SeatManager.hpp
index 2d73e087..fe11f930 100644
--- a/src/managers/SeatManager.hpp
+++ b/src/managers/SeatManager.hpp
@@ -76,7 +76,7 @@ class CSeatManager {
uint32_t nextSerial(SP<CWLSeatResource> seatResource);
// pops the serial if it was valid, meaning it is consumed.
- bool serialValid(SP<CWLSeatResource> seatResource, uint32_t serial);
+ bool serialValid(SP<CWLSeatResource> seatResource, uint32_t serial, bool erase = true);
void onSetCursor(SP<CWLSeatResource> seatResource, uint32_t serial, SP<CWLSurfaceResource> surf, const Vector2D& hotspot);
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; });
+}
diff --git a/src/protocols/PointerWarp.hpp b/src/protocols/PointerWarp.hpp
new file mode 100644
index 00000000..d1ce0062
--- /dev/null
+++ b/src/protocols/PointerWarp.hpp
@@ -0,0 +1,21 @@
+#pragma once
+
+#include "WaylandProtocol.hpp"
+#include "pointer-warp-v1.hpp"
+
+class CPointerWarpProtocol : public IWaylandProtocol {
+ public:
+ CPointerWarpProtocol(const wl_interface* iface, const int& ver, const std::string& name);
+
+ virtual void bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id);
+
+ private:
+ void destroyManager(CWpPointerWarpV1* manager);
+
+ //
+ std::vector<UP<CWpPointerWarpV1>> m_managers;
+};
+
+namespace PROTO {
+ inline UP<CPointerWarpProtocol> pointerWarp;
+};
diff --git a/src/protocols/core/Seat.cpp b/src/protocols/core/Seat.cpp
index e89c49ae..0b356c6f 100644
--- a/src/protocols/core/Seat.cpp
+++ b/src/protocols/core/Seat.cpp
@@ -109,6 +109,8 @@ CWLPointerResource::CWLPointerResource(SP<CWlPointer> resource_, SP<CWLSeatResou
if UNLIKELY (!good())
return;
+ m_resource->setData(this);
+
m_resource->setRelease([this](CWlPointer* r) { PROTO::seat->destroyResource(this); });
m_resource->setOnDestroy([this](CWlPointer* r) { PROTO::seat->destroyResource(this); });
@@ -145,6 +147,11 @@ bool CWLPointerResource::good() {
return m_resource->resource();
}
+SP<CWLPointerResource> CWLPointerResource::fromResource(wl_resource* res) {
+ auto data = sc<CWLPointerResource*>(sc<CWlPointer*>(wl_resource_get_user_data(res))->data());
+ return data ? data->m_self.lock() : nullptr;
+}
+
void CWLPointerResource::sendEnter(SP<CWLSurfaceResource> surface, const Vector2D& local) {
if (!m_owner || m_currentSurface == surface || !surface->getResource()->resource())
return;
@@ -439,6 +446,8 @@ CWLSeatResource::CWLSeatResource(SP<CWlSeat> resource_) : m_resource(resource_)
return;
}
+ RESOURCE->m_self = RESOURCE;
+
m_pointers.emplace_back(RESOURCE);
});
diff --git a/src/protocols/core/Seat.hpp b/src/protocols/core/Seat.hpp
index 8b8f6004..29399a27 100644
--- a/src/protocols/core/Seat.hpp
+++ b/src/protocols/core/Seat.hpp
@@ -88,15 +88,21 @@ class CWLPointerResource {
WP<CWLSeatResource> m_owner;
+ //
+ static SP<CWLPointerResource> fromResource(wl_resource* res);
+
private:
SP<CWlPointer> m_resource;
WP<CWLSurfaceResource> m_currentSurface;
+ WP<CWLPointerResource> m_self;
std::vector<uint32_t> m_pressedButtons;
struct {
CHyprSignalListener destroySurface;
} m_listeners;
+
+ friend class CWLSeatResource;
};
class CWLKeyboardResource {