summaryrefslogtreecommitdiff
path: root/src/protocols/RelativePointer.cpp
diff options
context:
space:
mode:
authorVaxry <vaxry@vaxry.net>2024-04-21 19:30:23 +0100
committerVaxry <vaxry@vaxry.net>2024-04-21 19:30:23 +0100
commit4954dcbbb352a72d41b43a6ab107388c17a0b21b (patch)
treec6023964f0a100eee801f44fc587d794f358c99f /src/protocols/RelativePointer.cpp
parent55f1f3fedfc6dc5da7f304bdfc8296a0a056f781 (diff)
relative-pointer: move to new impl
Diffstat (limited to 'src/protocols/RelativePointer.cpp')
-rw-r--r--src/protocols/RelativePointer.cpp72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/protocols/RelativePointer.cpp b/src/protocols/RelativePointer.cpp
new file mode 100644
index 00000000..c09ad0cf
--- /dev/null
+++ b/src/protocols/RelativePointer.cpp
@@ -0,0 +1,72 @@
+#include "RelativePointer.hpp"
+#include <algorithm>
+
+CRelativePointer::CRelativePointer(SP<CZwpRelativePointerV1> resource_) : resource(resource_) {
+ if (!resource_->resource())
+ return;
+
+ pClient = wl_resource_get_client(resource_->resource());
+
+ resource->setDestroy([this](CZwpRelativePointerV1* pMgr) { PROTO::relativePointer->destroyRelativePointer(this); });
+ resource->setOnDestroy([this](CZwpRelativePointerV1* pMgr) { PROTO::relativePointer->destroyRelativePointer(this); });
+}
+
+bool CRelativePointer::good() {
+ return resource->resource();
+}
+
+wl_client* CRelativePointer::client() {
+ return pClient;
+}
+
+void CRelativePointer::sendRelativeMotion(uint64_t time, const Vector2D& delta, const Vector2D& deltaUnaccel) {
+ resource->sendRelativeMotion(time >> 32, time & 0xFFFFFFFF, wl_fixed_from_double(delta.x), wl_fixed_from_double(delta.y), wl_fixed_from_double(deltaUnaccel.x),
+ wl_fixed_from_double(deltaUnaccel.y));
+}
+
+CRelativePointerProtocol::CRelativePointerProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
+ ;
+}
+
+void CRelativePointerProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
+ const auto RESOURCE = m_vManagers.emplace_back(std::make_unique<CZwpRelativePointerManagerV1>(client, ver, id)).get();
+ RESOURCE->setOnDestroy([this](CZwpRelativePointerManagerV1* p) { this->onManagerResourceDestroy(p->resource()); });
+
+ RESOURCE->setDestroy([this](CZwpRelativePointerManagerV1* pMgr) { this->onManagerResourceDestroy(pMgr->resource()); });
+ RESOURCE->setGetRelativePointer([this](CZwpRelativePointerManagerV1* pMgr, uint32_t id, wl_resource* pointer) { this->onGetRelativePointer(pMgr, id, pointer); });
+}
+
+void CRelativePointerProtocol::onManagerResourceDestroy(wl_resource* res) {
+ std::erase_if(m_vManagers, [&](const auto& other) { return other->resource() == res; });
+}
+
+void CRelativePointerProtocol::destroyRelativePointer(CRelativePointer* pointer) {
+ std::erase_if(m_vRelativePointers, [&](const auto& other) { return other.get() == pointer; });
+}
+
+void CRelativePointerProtocol::onGetRelativePointer(CZwpRelativePointerManagerV1* pMgr, uint32_t id, wl_resource* pointer) {
+ const auto CLIENT = wl_resource_get_client(pMgr->resource());
+ const auto RESOURCE =
+ m_vRelativePointers.emplace_back(std::make_unique<CRelativePointer>(std::make_shared<CZwpRelativePointerV1>(CLIENT, wl_resource_get_version(pMgr->resource()), id))).get();
+
+ if (!RESOURCE->good()) {
+ wl_resource_post_no_memory(pMgr->resource());
+ m_vRelativePointers.pop_back();
+ return;
+ }
+}
+
+void CRelativePointerProtocol::sendRelativeMotion(uint64_t time, const Vector2D& delta, const Vector2D& deltaUnaccel) {
+
+ if (!g_pCompositor->m_sSeat.seat->pointer_state.focused_client)
+ return;
+
+ const auto FOCUSED = g_pCompositor->m_sSeat.seat->pointer_state.focused_client->client;
+
+ for (auto& rp : m_vRelativePointers) {
+ if (FOCUSED != rp->client())
+ continue;
+
+ rp->sendRelativeMotion(time, delta, deltaUnaccel);
+ }
+} \ No newline at end of file