From 5d77ed0258b7e4125efc37b9649439270fc102f3 Mon Sep 17 00:00:00 2001 From: Nicolas Fella Date: Sun, 7 Jul 2024 18:35:49 +0200 Subject: [PATCH] Client: Properly handle tablet manager being announced after wl_seat When wl_seat is announced we create QWaylandInputDevice and there check whether the tablet manager is available, create the tablet seat, and store it in mTabletSeat. If zwp_tablet_manager_v2 is announced after wl_seat, which happens e.g. on Weston, we created the tablet seat in the QWaylandTabletManagerV2 ctor, but didn't update mTabletSeat. To address this, we move the handling to QWaylandDisplay and pass the manager to QWaylandInputDevice, similar to how we do it e.g. for text-input. Pick-to: 6.8 6.7 Change-Id: I902375ec0085d34ba99cbe59bbbc4051e7d1e802 Reviewed-by: David Edmundson Reviewed-by: Liang Qi Reviewed-by: Shawn Rutledge --- src/plugins/platforms/wayland/qwaylanddisplay.cpp | 3 +++ .../platforms/wayland/qwaylandinputdevice.cpp | 12 ++++++++++++ src/plugins/platforms/wayland/qwaylandtabletv2.cpp | 10 ---------- src/plugins/platforms/wayland/qwaylandtabletv2_p.h | 1 - 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/plugins/platforms/wayland/qwaylanddisplay.cpp b/src/plugins/platforms/wayland/qwaylanddisplay.cpp index f78bf2dd2a0..79cec09af93 100644 --- a/src/plugins/platforms/wayland/qwaylanddisplay.cpp +++ b/src/plugins/platforms/wayland/qwaylanddisplay.cpp @@ -652,6 +652,9 @@ void QWaylandDisplay::registry_global(uint32_t id, const QString &interface, uin #if QT_CONFIG(tabletevent) } else if (interface == QLatin1String(QWaylandTabletManagerV2::interface()->name)) { mGlobals.tabletManager.reset(new QWaylandTabletManagerV2(this, id, qMin(1, int(version)))); + for (QWaylandInputDevice *inputDevice : std::as_const(mInputDevices)) + inputDevice->setTabletSeat( + new QWaylandTabletSeatV2(mGlobals.tabletManager.get(), inputDevice)); #endif } else if (interface == QLatin1String(QWaylandPointerGestures::interface()->name)) { mGlobals.pointerGestures.reset(new QWaylandPointerGestures(this, id, 1)); diff --git a/src/plugins/platforms/wayland/qwaylandinputdevice.cpp b/src/plugins/platforms/wayland/qwaylandinputdevice.cpp index 416894fd439..c72c2a81452 100644 --- a/src/plugins/platforms/wayland/qwaylandinputdevice.cpp +++ b/src/plugins/platforms/wayland/qwaylandinputdevice.cpp @@ -563,6 +563,18 @@ void QWaylandInputDevice::setTextInput(QWaylandTextInputInterface *textInput) mTextInput.reset(textInput); } +#if QT_CONFIG(tabletevent) +void QWaylandInputDevice::setTabletSeat(QWaylandTabletSeatV2 *tabletSeat) +{ + mTabletSeat.reset(tabletSeat); +} + +QWaylandTabletSeatV2 *QWaylandInputDevice::tabletSeat() const +{ + return mTabletSeat.get(); +} +#endif + void QWaylandInputDevice::setTextInputMethod(QWaylandTextInputMethod *textInputMethod) { mTextInputMethod.reset(textInputMethod); diff --git a/src/plugins/platforms/wayland/qwaylandtabletv2.cpp b/src/plugins/platforms/wayland/qwaylandtabletv2.cpp index be8f1977008..e15185f08ef 100644 --- a/src/plugins/platforms/wayland/qwaylandtabletv2.cpp +++ b/src/plugins/platforms/wayland/qwaylandtabletv2.cpp @@ -13,11 +13,6 @@ namespace QtWaylandClient { QWaylandTabletManagerV2::QWaylandTabletManagerV2(QWaylandDisplay *display, uint id, uint version) : zwp_tablet_manager_v2(display->wl_registry(), id, qMin(version, uint(1))) { - // Create tabletSeats for all seats. - // This only works if we get the manager after all seats - const auto seats = display->inputDevices(); - for (auto *seat : seats) - createTabletSeat(seat); } QWaylandTabletManagerV2::~QWaylandTabletManagerV2() @@ -25,11 +20,6 @@ QWaylandTabletManagerV2::~QWaylandTabletManagerV2() destroy(); } -QWaylandTabletSeatV2 *QWaylandTabletManagerV2::createTabletSeat(QWaylandInputDevice *seat) -{ - return new QWaylandTabletSeatV2(this, seat); -} - QWaylandTabletSeatV2::QWaylandTabletSeatV2(QWaylandTabletManagerV2 *manager, QWaylandInputDevice *seat) : QtWayland::zwp_tablet_seat_v2(manager->get_tablet_seat(seat->wl_seat())) , m_seat(seat) diff --git a/src/plugins/platforms/wayland/qwaylandtabletv2_p.h b/src/plugins/platforms/wayland/qwaylandtabletv2_p.h index 20a8a4f5a24..f6f1daa9886 100644 --- a/src/plugins/platforms/wayland/qwaylandtabletv2_p.h +++ b/src/plugins/platforms/wayland/qwaylandtabletv2_p.h @@ -43,7 +43,6 @@ class Q_WAYLANDCLIENT_EXPORT QWaylandTabletManagerV2 : public QtWayland::zwp_tab public: explicit QWaylandTabletManagerV2(QWaylandDisplay *display, uint id, uint version); ~QWaylandTabletManagerV2() override; - QWaylandTabletSeatV2 *createTabletSeat(QWaylandInputDevice *seat); }; class Q_WAYLANDCLIENT_EXPORT QWaylandTabletSeatV2 : public QObject, public QtWayland::zwp_tablet_seat_v2