diff --git a/src/plugins/platforms/xcb/qxcbconnection.h b/src/plugins/platforms/xcb/qxcbconnection.h index 943f380d5c8..8eb6008425b 100644 --- a/src/plugins/platforms/xcb/qxcbconnection.h +++ b/src/plugins/platforms/xcb/qxcbconnection.h @@ -296,7 +296,7 @@ private: QSizeF size; // device size in mm bool providesTouchOrientation = false; }; - TouchDeviceData *populateTouchDevices(void *info, QXcbScrollingDevicePrivate *scrollingDeviceP); + TouchDeviceData *populateTouchDevices(void *info, QXcbScrollingDevicePrivate *scrollingDeviceP, bool *used = nullptr); TouchDeviceData *touchDeviceForId(int id); void xi2HandleEvent(xcb_ge_event_t *event); void xi2HandleGesturePinchEvent(void *event); diff --git a/src/plugins/platforms/xcb/qxcbconnection_xi2.cpp b/src/plugins/platforms/xcb/qxcbconnection_xi2.cpp index c9e45e623ab..d775a7ebb5f 100644 --- a/src/plugins/platforms/xcb/qxcbconnection_xi2.cpp +++ b/src/plugins/platforms/xcb/qxcbconnection_xi2.cpp @@ -280,6 +280,7 @@ void QXcbConnection::xi2SetupSlavePointerDevice(void *info, bool removeExisting, TabletData tabletData; #endif QXcbScrollingDevicePrivate *scrollingDeviceP = nullptr; + bool used = false; auto scrollingDevice = [&]() { if (!scrollingDeviceP) scrollingDeviceP = new QXcbScrollingDevicePrivate(name, deviceInfo->deviceid, @@ -439,7 +440,7 @@ void QXcbConnection::xi2SetupSlavePointerDevice(void *info, bool removeExisting, } if (!isTablet) { - TouchDeviceData *dev = populateTouchDevices(deviceInfo, scrollingDeviceP); + TouchDeviceData *dev = populateTouchDevices(deviceInfo, scrollingDeviceP, &used); if (dev && lcQpaXInputDevices().isDebugEnabled()) { if (dev->qtTouchDevice->type() == QInputDevice::DeviceType::TouchScreen) qCDebug(lcQpaXInputDevices, " it's a touchscreen with type %d capabilities 0x%X max touch points %d", @@ -462,6 +463,7 @@ void QXcbConnection::xi2SetupSlavePointerDevice(void *info, bool removeExisting, if (master) scrollingDeviceP->seatName = master->seatName(); QWindowSystemInterface::registerInputDevice(new QXcbScrollingDevice(*scrollingDeviceP, master)); + used = true; } else { QWindowSystemInterface::registerInputDevice(new QPointingDevice( name, deviceInfo->deviceid, @@ -469,6 +471,11 @@ void QXcbConnection::xi2SetupSlavePointerDevice(void *info, bool removeExisting, caps, 1, buttonCount, (master ? master->seatName() : QString()), QPointingDeviceUniqueId(), master)); } } + + if (!used && scrollingDeviceP) { + QXcbScrollingDevice *holder = new QXcbScrollingDevice(*scrollingDeviceP, master); + holder->deleteLater(); + } } void QXcbConnection::xi2SetupDevices() @@ -549,7 +556,7 @@ QXcbConnection::TouchDeviceData *QXcbConnection::touchDeviceForId(int id) return dev; } -QXcbConnection::TouchDeviceData *QXcbConnection::populateTouchDevices(void *info, QXcbScrollingDevicePrivate *scrollingDeviceP) +QXcbConnection::TouchDeviceData *QXcbConnection::populateTouchDevices(void *info, QXcbScrollingDevicePrivate *scrollingDeviceP, bool *used) { auto *deviceInfo = reinterpret_cast(info); QPointingDevice::Capabilities caps; @@ -654,6 +661,7 @@ QXcbConnection::TouchDeviceData *QXcbConnection::populateTouchDevices(void *info dev.qtTouchDevice = new QXcbScrollingDevice(*scrollingDeviceP, master); if (Q_UNLIKELY(!caps.testFlag(QInputDevice::Capability::Scroll))) qCDebug(lcQpaXInputDevices) << "unexpectedly missing RelVert/HorizWheel atoms for touchpad with scroll capability" << dev.qtTouchDevice; + *used = true; } else { dev.qtTouchDevice = new QPointingDevice(QString::fromUtf8(xcb_input_xi_device_info_name(deviceInfo), xcb_input_xi_device_info_name_length(deviceInfo)),