From 92665565102c9b7a70c89cd5677b9676a229ca6d Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Thu, 11 May 2023 23:50:42 +0200 Subject: [PATCH] mousepad: Implement relative mouse movements Somehow it wasn't done. --- app/qml/mousepad.qml | 2 +- declarativeplugin/CMakeLists.txt | 6 +++ declarativeplugin/pointerlockerwayland.cpp | 51 +++++++++++++++++++++- declarativeplugin/pointerlockerwayland.h | 6 ++- 4 files changed, 62 insertions(+), 3 deletions(-) diff --git a/app/qml/mousepad.qml b/app/qml/mousepad.qml index 4f514c6c4..83edddc1e 100644 --- a/app/qml/mousepad.qml +++ b/app/qml/mousepad.qml @@ -61,7 +61,7 @@ Kirigami.Page Connections { target: PointerLocker - function onPointerMoved() { + function onPointerMoved(delta) { if (!PointerLocker.isLocked) { return; } diff --git a/declarativeplugin/CMakeLists.txt b/declarativeplugin/CMakeLists.txt index cc8ef8d51..2ebd0e1f6 100644 --- a/declarativeplugin/CMakeLists.txt +++ b/declarativeplugin/CMakeLists.txt @@ -21,9 +21,15 @@ if(UNIX AND NOT APPLE) PROTOCOL ${WaylandProtocols_DATADIR}/unstable/pointer-constraints/pointer-constraints-unstable-v1.xml BASENAME pointer-constraints-unstable-v1 ) + ecm_add_qtwayland_client_protocol(wayland_SRCS + PROTOCOL ${WaylandProtocols_DATADIR}/unstable/relative-pointer/relative-pointer-unstable-v1.xml + BASENAME relative-pointer-unstable-v1 + ) else() qt6_generate_wayland_protocol_client_sources(kdeconnectdeclarativeplugin FILES ${WaylandProtocols_DATADIR}/unstable/pointer-constraints/pointer-constraints-unstable-v1.xml) + qt6_generate_wayland_protocol_client_sources(kdeconnectdeclarativeplugin FILES + ${WaylandProtocols_DATADIR}/unstable/relative-pointer/relative-pointer-unstable-v1.xml) endif() target_sources(kdeconnectdeclarativeplugin PRIVATE ${wayland_SRCS}) diff --git a/declarativeplugin/pointerlockerwayland.cpp b/declarativeplugin/pointerlockerwayland.cpp index aa0ca982c..ed3c81fb9 100644 --- a/declarativeplugin/pointerlockerwayland.cpp +++ b/declarativeplugin/pointerlockerwayland.cpp @@ -10,6 +10,7 @@ #include #include "qwayland-pointer-constraints-unstable-v1.h" +#include "qwayland-relative-pointer-unstable-v1.h" #include #include @@ -50,9 +51,52 @@ private: } }; +class RelativePointerManagerV1 : public QWaylandClientExtensionTemplate, public QtWayland::zwp_relative_pointer_manager_v1 +{ +public: + explicit RelativePointerManagerV1() + : QWaylandClientExtensionTemplate(1) + { + } + + ~RelativePointerManagerV1() + { + destroy(); + } +}; + +class RelativePointerV1 : public QtWayland::zwp_relative_pointer_v1 +{ +public: + explicit RelativePointerV1(PointerLockerWayland *locker, struct ::zwp_relative_pointer_v1 *p) + : QtWayland::zwp_relative_pointer_v1(p) + , locker(locker) + { + } + + ~RelativePointerV1() + { + destroy(); + } + + void zwp_relative_pointer_v1_relative_motion(uint32_t /*utime_hi*/, + uint32_t /*utime_lo*/, + wl_fixed_t dx, + wl_fixed_t dy, + wl_fixed_t /*dx_unaccel*/, + wl_fixed_t /*dy_unaccel*/) override + { + locker->pointerMoved({wl_fixed_to_double(dx), wl_fixed_to_double(dy)}); + } + +private: + PointerLockerWayland *const locker; +}; + PointerLockerWayland::PointerLockerWayland(QObject *parent) : AbstractPointerLocker(parent) { + m_relativePointerMgr = std::make_unique(); m_pointerConstraints = new PointerConstraints; } @@ -84,6 +128,11 @@ void PointerLockerWayland::enforceLock() return; } + auto pointer = getPointer(); + if (!m_relativePointer) { + m_relativePointer.reset(new RelativePointerV1(this, m_relativePointerMgr->get_relative_pointer(pointer))); + } + wl_surface *wlSurface = [](QWindow *window) -> wl_surface * { if (!window) { return nullptr; @@ -98,7 +147,7 @@ void PointerLockerWayland::enforceLock() }(m_window); m_lockedPointer = - new LockedPointer(m_pointerConstraints->lock_pointer(wlSurface, getPointer(), nullptr, PointerConstraints::lifetime::lifetime_persistent), this); + new LockedPointer(m_pointerConstraints->lock_pointer(wlSurface, pointer, nullptr, PointerConstraints::lifetime::lifetime_persistent), this); if (!m_lockedPointer) { qDebug() << "ERROR when receiving locked pointer!"; diff --git a/declarativeplugin/pointerlockerwayland.h b/declarativeplugin/pointerlockerwayland.h index f2658b229..4a28d4130 100644 --- a/declarativeplugin/pointerlockerwayland.h +++ b/declarativeplugin/pointerlockerwayland.h @@ -10,8 +10,10 @@ #include "pointerlocker.h" class PointerConstraints; +class RelativePointerManagerV1; +class RelativePointerV1; class LockedPointer; -class wl_pointer; +struct wl_pointer; class PointerLockerWayland : public AbstractPointerLocker { @@ -44,6 +46,8 @@ private: PointerConstraints *m_pointerConstraints; LockedPointer *m_lockedPointer = nullptr; + std::unique_ptr m_relativePointerMgr; + std::unique_ptr m_relativePointer; }; #endif