From 37adc06603f260c4f145b442a6e63cc13434253a Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Fri, 30 Dec 2022 01:57:25 +0000 Subject: [PATCH] wayland: Send tilt and rotation events, if supported While tilt is sent on X11, we're currently only sending pressure events and not tilt/rotation events on Wayland. Since Krita is still running in X11, and it's running through XWayland - it's technically a Wayland client and gets no tilt/rotation. This fixes that issue :-) I saw !3231 which was working on complete Wayland tablet support, but it's been stagnating. I just wanted tilt & rotation support now, so I added a way to query capabilities from the `m_capabilities` variable on the private interface we already fetched. Tested on Krita using the Tablet Debug Log. --- src/input.cpp | 14 +++++++++++++- src/wayland/tablet_v2_interface.cpp | 5 +++++ src/wayland/tablet_v2_interface.h | 2 ++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/input.cpp b/src/input.cpp index eda4d1ec99..8024ab060a 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -2143,6 +2143,8 @@ public: bool tabletToolEvent(TabletEvent *event) override { + using namespace KWaylandServer; + if (!workspace()) { return false; } @@ -2205,7 +2207,17 @@ public: break; } const quint32 MAX_VAL = 65535; - tool->sendPressure(MAX_VAL * event->pressure()); + + if (tool->hasCapability(TabletToolV2Interface::Pressure)) { + tool->sendPressure(MAX_VAL * event->pressure()); + } + if (tool->hasCapability(TabletToolV2Interface::Tilt)) { + tool->sendTilt(event->xTilt(), event->yTilt()); + } + if (tool->hasCapability(TabletToolV2Interface::Rotation)) { + tool->sendRotation(event->rotation()); + } + tool->sendFrame(event->timestamp()); return true; } diff --git a/src/wayland/tablet_v2_interface.cpp b/src/wayland/tablet_v2_interface.cpp index e9630acabe..0f93fdbf16 100644 --- a/src/wayland/tablet_v2_interface.cpp +++ b/src/wayland/tablet_v2_interface.cpp @@ -222,6 +222,11 @@ TabletToolV2Interface::~TabletToolV2Interface() } } +bool TabletToolV2Interface::hasCapability(Capability capability) const +{ + return d->m_capabilities.contains(capability); +} + void TabletToolV2Interface::setCurrentSurface(SurfaceInterface *surface) { if (d->m_surface == surface) diff --git a/src/wayland/tablet_v2_interface.h b/src/wayland/tablet_v2_interface.h index 47fd21a120..a4e5a73b6d 100644 --- a/src/wayland/tablet_v2_interface.h +++ b/src/wayland/tablet_v2_interface.h @@ -83,6 +83,8 @@ public: }; Q_ENUM(Capability) + bool hasCapability(Capability capability) const; + /** * Sets the surface the events will be sent to. *