client: Wait to create QPointingDevice; give seat name to ctor

Wait until both the seat name and capabilities are known, to avoid
depending on the order of messages. On Weston, seat_name() is called
after seat_capabilities(), while it's the other way around on others.

Pass the seat name along in each place where the QPointingDevice ctor is
invoked.

This gets us closer to multi-seat support on Wayland: at least
qtdecl/examples/quick/pointerhandlers/singlePointHandlerProperties.qml
can see the seat name of the device provided with each QTouchEvent or
QTabletEvent. Followup to bb151390240c1f20a6464adbefa497f3559554dd and
e168e1fc80231c0e2751b4f6f2a736efadff92fa

Pick-to: 6.8
Task-number: QTBUG-72167
Task-number: QTBUG-115207
Change-Id: Ife25cfec0307893d949a2a50a9b49a8f560a60e0
Reviewed-by: David Edmundson <davidedmundson@kde.org>
This commit is contained in:
Shawn Rutledge 2024-09-06 17:39:05 +02:00
parent d749871d39
commit efd45d447e
3 changed files with 30 additions and 19 deletions

View File

@ -431,21 +431,35 @@ 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,
QLatin1StringView("touchpad"), 0, QInputDevice::DeviceType::TouchPad,
QPointingDevice::PointerType::Finger, QInputDevice::Capability::Position,
MaxTouchPoints, 0, mSeatName, QPointingDeviceUniqueId(), this);
QWindowSystemInterface::registerInputDevice(mTouchPadDevice);
@ -454,33 +468,28 @@ void QWaylandInputDevice::seat_capabilities(uint32_t caps)
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,
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);

View File

@ -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;

View File

@ -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)
{