From 4a01350f7e6fa039ca6269506e9e3876c6dce422 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Wed, 23 Oct 2024 18:02:28 +0300 Subject: [PATCH] Don't store TabletV2Interface in libinput device group user data Device group user data is a libinput specific concept, and it's not portable to other platforms/backends, which we need to support in long term for proper testing of tablet stuff in CI, etc. Note that tablet input still heavily pokes libinput specific things, this is going to be addressed later. --- src/input.cpp | 6 +----- src/tablet_input.cpp | 32 +++++++++++++++++++++++--------- src/tablet_input.h | 2 ++ 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/input.cpp b/src/input.cpp index ead15bffbd..7db9fa4200 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -2151,11 +2151,7 @@ public: // NOTE: tablet may be nullptr when the device is removed (see ::removeDevice) but events from the tool // may still happen. - TabletV2Interface *tablet = nullptr; - if (auto libinputDevice = qobject_cast(device)) { - auto deviceGroup = libinput_device_get_device_group(libinputDevice->device()); - tablet = static_cast(libinput_device_group_get_user_data(deviceGroup)); - } + TabletV2Interface *tablet = input()->tablet()->tabletForPad(device); if (!tablet) { return nullptr; } diff --git a/src/tablet_input.cpp b/src/tablet_input.cpp index 989c064319..bb23003731 100644 --- a/src/tablet_input.cpp +++ b/src/tablet_input.cpp @@ -134,10 +134,7 @@ void TabletInputRedirection::integrateDevice(InputDevice *inputDevice) struct udev_device *const udev_device = libinput_device_get_udev_device(device->device()); const char *devnode = udev_device_get_syspath(udev_device); - TabletV2Interface *tablet = tabletSeat->addTablet(device->vendor(), device->product(), device->sysName(), device->name(), {QString::fromUtf8(devnode)}); - - auto deviceGroup = libinput_device_get_device_group(device->device()); - libinput_device_group_set_user_data(deviceGroup, tablet); + tabletSeat->addTablet(device->vendor(), device->product(), device->sysName(), device->name(), {QString::fromUtf8(devnode)}); } if (device->isTabletPad()) { @@ -157,11 +154,6 @@ void TabletInputRedirection::removeDevice(InputDevice *inputDevice) { auto device = qobject_cast(inputDevice); if (device) { - if (inputDevice->isTabletTool()) { - auto deviceGroup = libinput_device_get_device_group(device->device()); - libinput_device_group_set_user_data(deviceGroup, nullptr); - } - TabletSeatV2Interface *tabletSeat = findTabletSeat(); if (tabletSeat) { tabletSeat->removeDevice(device->sysName()); @@ -268,6 +260,28 @@ TabletToolV2Interface *TabletInputRedirection::ensureTabletTool(const TabletTool return tool; } +TabletV2Interface *TabletInputRedirection::tabletForPad(InputDevice *device) const +{ + auto pad = qobject_cast(device); + if (!pad) { + return nullptr; + } + + const auto candidates = input()->devices(); + for (InputDevice *candidate : candidates) { + if (!candidate->isTabletTool()) { + continue; + } + if (auto libinputDevice = qobject_cast(candidate)) { + if (libinput_device_get_device_group(pad->device()) == libinput_device_get_device_group(libinputDevice->device())) { + return findTabletSeat()->tabletByName(libinputDevice->sysName()); + } + } + } + + return nullptr; +} + void TabletInputRedirection::tabletToolEvent(KWin::InputRedirection::TabletEventType type, const QPointF &pos, qreal pressure, int xTilt, int yTilt, qreal rotation, bool tipDown, bool tipNear, const TabletToolId &toolId, diff --git a/src/tablet_input.h b/src/tablet_input.h index 135a70a554..7b707c3b9f 100644 --- a/src/tablet_input.h +++ b/src/tablet_input.h @@ -21,6 +21,7 @@ class Cursor; class Window; class TabletToolId; class TabletToolV2Interface; +class TabletV2Interface; namespace Decoration { @@ -64,6 +65,7 @@ public: } TabletToolV2Interface *ensureTabletTool(const TabletToolId &id); + TabletV2Interface *tabletForPad(InputDevice *device) const; private: void cleanupDecoration(Decoration::DecoratedClientImpl *old,