diff --git a/src/plugins/platforms/wayland/qwaylandinputdevice.cpp b/src/plugins/platforms/wayland/qwaylandinputdevice.cpp index a34ea340b81..9bfa2b0f4af 100644 --- a/src/plugins/platforms/wayland/qwaylandinputdevice.cpp +++ b/src/plugins/platforms/wayland/qwaylandinputdevice.cpp @@ -431,56 +431,65 @@ QWaylandInputDevice::~QWaylandInputDevice() void QWaylandInputDevice::seat_capabilities(uint32_t caps) { mCaps = caps; + maybeRegisterInputDevices(); +} - if (caps & WL_SEAT_CAPABILITY_KEYBOARD && !mKeyboard) { +void QWaylandInputDevice::seat_name(const QString &name) +{ + mSeatName = name; + mSeatNameKnown = true; + maybeRegisterInputDevices(); +} + +void QWaylandInputDevice::maybeRegisterInputDevices() +{ + if (!mSeatNameKnown) + return; // too early + + if (mCaps & WL_SEAT_CAPABILITY_KEYBOARD && !mKeyboard) { mKeyboard.reset(createKeyboard(this)); - } else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && mKeyboard) { + } else if (!(mCaps & WL_SEAT_CAPABILITY_KEYBOARD) && mKeyboard) { mKeyboard.reset(); } - if (caps & WL_SEAT_CAPABILITY_POINTER && !mPointer) { + if (mCaps & WL_SEAT_CAPABILITY_POINTER && !mPointer) { mPointer.reset(createPointer(this)); auto *pointerGestures = mQDisplay->pointerGestures(); if (pointerGestures) { // NOTE: The name of the device and its system ID are not exposed on Wayland. mTouchPadDevice = new QPointingDevice( - QLatin1String("touchpad"), 0, QInputDevice::DeviceType::TouchPad, - QPointingDevice::PointerType::Finger, QInputDevice::Capability::Position, - MaxTouchPoints, 0, mSeatName, QPointingDeviceUniqueId(), this); + QLatin1StringView("touchpad"), 0, QInputDevice::DeviceType::TouchPad, + QPointingDevice::PointerType::Finger, QInputDevice::Capability::Position, + MaxTouchPoints, 0, mSeatName, QPointingDeviceUniqueId(), this); QWindowSystemInterface::registerInputDevice(mTouchPadDevice); mPointerGesturePinch.reset(pointerGestures->createPointerGesturePinch(this)); mPointerGesturePinch->init(pointerGestures->get_pinch_gesture(mPointer->object())); mPointerGestureSwipe.reset(pointerGestures->createPointerGestureSwipe(this)); mPointerGestureSwipe->init(pointerGestures->get_swipe_gesture(mPointer->object())); } - } else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && mPointer) { + } else if (!(mCaps & WL_SEAT_CAPABILITY_POINTER) && mPointer) { mPointer.reset(); mPointerGesturePinch.reset(); mPointerGestureSwipe.reset(); } - if (caps & WL_SEAT_CAPABILITY_TOUCH && !mTouch) { + if (mCaps & WL_SEAT_CAPABILITY_TOUCH && !mTouch) { mTouch.reset(createTouch(this)); if (!mTouchDevice) { // TODO number of touchpoints, actual name and ID mTouchDevice = new QPointingDevice( - QLatin1String("some touchscreen"), 0, QInputDevice::DeviceType::TouchScreen, - QPointingDevice::PointerType::Finger, QInputDevice::Capability::Position, - MaxTouchPoints, 0, mSeatName, QPointingDeviceUniqueId(), this); + QLatin1StringView("touchscreen"), 0, QInputDevice::DeviceType::TouchScreen, + QPointingDevice::PointerType::Finger, QInputDevice::Capability::Position, + MaxTouchPoints, 0, mSeatName, QPointingDeviceUniqueId(), this); QWindowSystemInterface::registerInputDevice(mTouchDevice); } - } else if (!(caps & WL_SEAT_CAPABILITY_TOUCH) && mTouch) { + } else if (!(mCaps & WL_SEAT_CAPABILITY_TOUCH) && mTouch) { mTouch.reset(); } } -void QWaylandInputDevice::seat_name(const QString &name) -{ - mSeatName = name; -} - QWaylandInputDevice::Keyboard *QWaylandInputDevice::createKeyboard(QWaylandInputDevice *device) { return new Keyboard(device); diff --git a/src/plugins/platforms/wayland/qwaylandinputdevice_p.h b/src/plugins/platforms/wayland/qwaylandinputdevice_p.h index 88f2d7085a1..4e74df1e182 100644 --- a/src/plugins/platforms/wayland/qwaylandinputdevice_p.h +++ b/src/plugins/platforms/wayland/qwaylandinputdevice_p.h @@ -148,6 +148,7 @@ protected: uint32_t mId = -1; uint32_t mCaps = 0; QString mSeatName; + bool mSeatNameKnown = false; #if QT_CONFIG(cursor) struct CursorState { @@ -185,6 +186,7 @@ protected: void seat_capabilities(uint32_t caps) override; void seat_name(const QString &name) override; + void maybeRegisterInputDevices(); void handleTouchPoint(int id, QEventPoint::State state, const QPointF &surfacePosition = QPoint()); QPointingDevice *mTouchDevice = nullptr; diff --git a/src/plugins/platforms/wayland/qwaylandtabletv2.cpp b/src/plugins/platforms/wayland/qwaylandtabletv2.cpp index 1a05eb8b963..627f8746f88 100644 --- a/src/plugins/platforms/wayland/qwaylandtabletv2.cpp +++ b/src/plugins/platforms/wayland/qwaylandtabletv2.cpp @@ -95,7 +95,7 @@ void QWaylandTabletSeatV2::zwp_tablet_seat_v2_pad_added(zwp_tablet_pad_v2 *id) QWaylandTabletV2::QWaylandTabletV2(::zwp_tablet_v2 *tablet, const QString &seatName) : QPointingDevice(u"unknown"_s, -1, DeviceType::Stylus, PointerType::Pen, Capability::Position | Capability::Hover, - 1, 1) + 1, 1, seatName) , QtWayland::zwp_tablet_v2(tablet) { qCDebug(lcQpaInputDevices) << "new tablet on seat" << seatName; @@ -142,7 +142,7 @@ void QWaylandTabletV2::zwp_tablet_v2_removed() QWaylandTabletToolV2::QWaylandTabletToolV2(QWaylandTabletSeatV2 *tabletSeat, ::zwp_tablet_tool_v2 *tool) : QPointingDevice(u"tool"_s, -1, DeviceType::Stylus, PointerType::Pen, Capability::Position | Capability::Hover, - 1, 1) + 1, 1, tabletSeat->seat()->seatname()) , QtWayland::zwp_tablet_tool_v2(tool) , m_tabletSeat(tabletSeat) {