diff --git a/src/plugins/platforms/xcb/qxcbconnection.h b/src/plugins/platforms/xcb/qxcbconnection.h index b62d461170..1e402a37de 100644 --- a/src/plugins/platforms/xcb/qxcbconnection.h +++ b/src/plugins/platforms/xcb/qxcbconnection.h @@ -78,7 +78,7 @@ class QXcbScreen; class QXcbWindow; class QXcbDrag; class QXcbKeyboard; -class QXcbScrollingDevicePrivate; +class QXcbScrollingDevice; class QXcbClipboard; class QXcbWMSupport; class QXcbNativeInterface; @@ -316,8 +316,8 @@ private: TabletData *tabletDataForDevice(int id); #endif // QT_CONFIG(tabletevent) void xi2HandleScrollEvent(void *event, const QPointingDevice *scrollingDevice); - void xi2UpdateScrollingDevice(QXcbScrollingDevicePrivate *scrollingDevice); - QXcbScrollingDevicePrivate *scrollingDeviceForId(int id); + void xi2UpdateScrollingDevice(QInputDevice *scrollingDevice); + QXcbScrollingDevice *scrollingDeviceForId(int id); static bool xi2GetValuatorValueIfSet(const void *event, int valuatorNum, double *value); diff --git a/src/plugins/platforms/xcb/qxcbconnection_xi2.cpp b/src/plugins/platforms/xcb/qxcbconnection_xi2.cpp index 03c45dfc3e..04d2c57e9e 100644 --- a/src/plugins/platforms/xcb/qxcbconnection_xi2.cpp +++ b/src/plugins/platforms/xcb/qxcbconnection_xi2.cpp @@ -433,7 +433,7 @@ void QXcbConnection::xi2SetupSlavePointerDevice(void *info, bool removeExisting, scrollingDeviceP->buttonCount = buttonCount; if (master) scrollingDeviceP->seatName = master->seatName(); - QWindowSystemInterface::registerInputDevice(new QXcbScrollingMouse(*scrollingDeviceP, master)); + QWindowSystemInterface::registerInputDevice(new QXcbScrollingDevice(*scrollingDeviceP, master)); } else { QWindowSystemInterface::registerInputDevice(new QPointingDevice( name, deviceInfo->deviceid, @@ -991,8 +991,13 @@ void QXcbConnection::xi2HandleDeviceChangedEvent(void *event) } } -void QXcbConnection::xi2UpdateScrollingDevice(QXcbScrollingDevicePrivate *scrollingDevice) +void QXcbConnection::xi2UpdateScrollingDevice(QInputDevice *dev) { + QXcbScrollingDevice *scrollDev = qobject_cast(dev); + if (!scrollDev || !scrollDev->capabilities().testFlag(QInputDevice::Capability::Scroll)) + return; + QXcbScrollingDevicePrivate *scrollingDevice = QXcbScrollingDevice::get(scrollDev); + auto reply = Q_XCB_REPLY(xcb_input_xi_query_device, xcb_connection(), scrollingDevice->systemId); if (!reply || reply->num_infos <= 0) { qCDebug(lcQpaXInputDevices, "scrolling device %lld no longer present", scrollingDevice->systemId); @@ -1026,30 +1031,27 @@ void QXcbConnection::xi2UpdateScrollingDevices() { const auto &devices = QInputDevice::devices(); for (const QInputDevice *dev : devices) { - if (dev->capabilities().testFlag(QInputDevice::Capability::Scroll)) { - const auto devPriv = QPointingDevicePrivate::get(static_cast(const_cast(dev))); - xi2UpdateScrollingDevice(static_cast(devPriv)); - } + if (dev->capabilities().testFlag(QInputDevice::Capability::Scroll)) + xi2UpdateScrollingDevice(const_cast(dev)); } } -QXcbScrollingDevicePrivate *QXcbConnection::scrollingDeviceForId(int id) +QXcbScrollingDevice *QXcbConnection::scrollingDeviceForId(int id) { const QPointingDevice *dev = QPointingDevicePrivate::pointingDeviceById(id); - if (!dev) + if (!dev|| !dev->capabilities().testFlag(QInputDevice::Capability::Scroll)) return nullptr; - if (!dev->capabilities().testFlag(QInputDevice::Capability::Scroll)) - return nullptr; - auto devPriv = QPointingDevicePrivate::get(const_cast(dev)); - return static_cast(devPriv); + return qobject_cast(const_cast(dev)); } void QXcbConnection::xi2HandleScrollEvent(void *event, const QPointingDevice *dev) { auto *xiDeviceEvent = reinterpret_cast(event); - if (!dev->capabilities().testFlag(QInputDevice::Capability::Scroll)) + + const QXcbScrollingDevice *scrollDev = qobject_cast(dev); + if (!scrollDev || !scrollDev->capabilities().testFlag(QInputDevice::Capability::Scroll)) return; - const auto scrollingDevice = static_cast(QPointingDevicePrivate::get(dev)); + const QXcbScrollingDevicePrivate *scrollingDevice = QXcbScrollingDevice::get(scrollDev); if (xiDeviceEvent->event_type == XCB_INPUT_MOTION && scrollingDevice->orientations) { if (QXcbWindow *platformWindow = platformWindowFromId(xiDeviceEvent->event)) { diff --git a/src/plugins/platforms/xcb/qxcbscrollingdevice_p.h b/src/plugins/platforms/xcb/qxcbscrollingdevice_p.h index 26839e3129..6222e92ff2 100644 --- a/src/plugins/platforms/xcb/qxcbscrollingdevice_p.h +++ b/src/plugins/platforms/xcb/qxcbscrollingdevice_p.h @@ -44,11 +44,6 @@ QT_BEGIN_NAMESPACE -/*! \internal - On the xcb platform, if a device's QPointingDevice::capabilities() includes - QInputDevice::Capability::Scroll, then its d-pointer must point to - an instance of this subclass, which tracks the scrolling valuators. -*/ class QXcbScrollingDevicePrivate : public QPointingDevicePrivate { Q_DECLARE_PUBLIC(QPointingDevice) @@ -67,11 +62,23 @@ public: // end of scrolling-related data }; -class QXcbScrollingMouse : public QPointingDevice +class QXcbScrollingDevice : public QPointingDevice { + Q_OBJECT public: - QXcbScrollingMouse(QXcbScrollingDevicePrivate &d, QObject *parent) + QXcbScrollingDevice(QXcbScrollingDevicePrivate &d, QObject *parent) : QPointingDevice(d, parent) {} + + inline static QXcbScrollingDevicePrivate *get(QXcbScrollingDevice *q) + { + return static_cast(QObjectPrivate::get(q)); + } + + inline static const QXcbScrollingDevicePrivate *get(const QXcbScrollingDevice *q) + { + return static_cast(QObjectPrivate::get(q)); + } + }; QT_END_NAMESPACE