diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2019-05-31 08:38:16 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2020-06-16 22:06:56 +0200 |
commit | 6589f2ed0cf78c9b8a5bdffcdc458dc40a974c60 (patch) | |
tree | 61f29061a4cbaf925ef0ab7ba9fafc1db9ee4ef3 /src/plugins/platforms/windows/qwindowspointerhandler.cpp | |
parent | 0a2e3ce85ce788b8a07380a458faf4ed3817d0c0 (diff) |
Introduce QInputDevice hierarchy; replace QTouchDevice
We have seen during the Qt 5 series that QMouseEvent::source() does
not provide enough information: if it is synthesized, it could have
come from any device for which mouse events are synthesized, not only
from a touchscreen. By providing in every QInputEvent as complete
information about the actual source device as possible, we will enable
very fine-tuned behavior in the object that handles each event.
Further, we would like to support multiple keyboards, pointing devices,
and named groups of devices that are known as "seats" in Wayland.
In Qt 5, QPA plugins registered each touchscreen as it was discovered.
Now we extend this pattern to all input devices. This new requirement
can be implemented gradually; for now, if a QTWSI input event is
received wtihout a device pointer, a default "core" device will be
created on-the-fly, and a warning emitted.
In Qt 5, QTouchEvent::TouchPoint::id() was forced to be unique even when
multiple devices were in use simultaneously. Now that each event
identifies the device it came from, this hack is no longer needed.
A stub of the new QPointerEvent is added; it will be developed further
in subsequent patches.
[ChangeLog][QtGui][QInputEvent] Every QInputEvent now carries a pointer
to an instance of QInputDevice, or the subclass QPointingDevice in case
of mouse, touch and tablet events. Each platform plugin is expected to
create the device instances, register them, and provide valid pointers
with all input events. If this is not done, warnings are emitted and
default devices are created as necessary. When the device has accurate
information, it provides the opportunity to fine-tune behavior depending
on device type and capabilities: for example if a QMouseEvent is
synthesized from a touchscreen, the recipient can see which touchscreen
it came from. Each device also has a seatName to distinguish users on
multi-user windowing systems. Touchpoint IDs are no longer unique on
their own, but the combination of ID and device is.
Fixes: QTBUG-46412
Fixes: QTBUG-72167
Task-number: QTBUG-69433
Task-number: QTBUG-52430
Change-Id: I933fb2b86182efa722037b7a33e404c5daf5292a
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'src/plugins/platforms/windows/qwindowspointerhandler.cpp')
-rw-r--r-- | src/plugins/platforms/windows/qwindowspointerhandler.cpp | 70 |
1 files changed, 38 insertions, 32 deletions
diff --git a/src/plugins/platforms/windows/qwindowspointerhandler.cpp b/src/plugins/platforms/windows/qwindowspointerhandler.cpp index fba24d8696..7c6ca0a61e 100644 --- a/src/plugins/platforms/windows/qwindowspointerhandler.cpp +++ b/src/plugins/platforms/windows/qwindowspointerhandler.cpp @@ -53,7 +53,7 @@ #include <QtGui/qguiapplication.h> #include <QtGui/qscreen.h> -#include <QtGui/qtouchdevice.h> +#include <QtGui/qpointingdevice.h> #include <QtGui/qwindow.h> #include <QtGui/private/qguiapplication_p.h> #include <QtCore/qvarlengtharray.h> @@ -75,6 +75,13 @@ enum { QT_PT_TOUCHPAD = 5, // MinGW is missing PT_TOUCHPAD }; +qint64 QWindowsPointerHandler::m_nextInputDeviceId = 1; + +QWindowsPointerHandler::~QWindowsPointerHandler() +{ + delete m_touchDevice; +} + bool QWindowsPointerHandler::translatePointerEvent(QWindow *window, HWND hwnd, QtWindows::WindowsEventType et, MSG msg, LRESULT *result) { *result = 0; @@ -310,31 +317,30 @@ static bool isValidWheelReceiver(QWindow *candidate) return false; } -static QTouchDevice *createTouchDevice() -{ - const int digitizers = GetSystemMetrics(SM_DIGITIZER); - if (!(digitizers & (NID_INTEGRATED_TOUCH | NID_EXTERNAL_TOUCH))) - return nullptr; - const int tabletPc = GetSystemMetrics(SM_TABLETPC); - const int maxTouchPoints = GetSystemMetrics(SM_MAXIMUMTOUCHES); - qCDebug(lcQpaEvents) << "Digitizers:" << Qt::hex << Qt::showbase << (digitizers & ~NID_READY) - << "Ready:" << (digitizers & NID_READY) << Qt::dec << Qt::noshowbase - << "Tablet PC:" << tabletPc << "Max touch points:" << maxTouchPoints; - auto *result = new QTouchDevice; - result->setType(digitizers & NID_INTEGRATED_TOUCH - ? QTouchDevice::TouchScreen : QTouchDevice::TouchPad); - QTouchDevice::Capabilities capabilities = QTouchDevice::Position | QTouchDevice::Area | QTouchDevice::NormalizedPosition; - if (result->type() == QTouchDevice::TouchPad) - capabilities |= QTouchDevice::MouseEmulation; - result->setCapabilities(capabilities); - result->setMaximumTouchPoints(maxTouchPoints); - return result; -} - -QTouchDevice *QWindowsPointerHandler::ensureTouchDevice() +QPointingDevice *QWindowsPointerHandler::ensureTouchDevice() { - if (!m_touchDevice) - m_touchDevice = createTouchDevice(); + if (!m_touchDevice) { + const int digitizers = GetSystemMetrics(SM_DIGITIZER); + if (!(digitizers & (NID_INTEGRATED_TOUCH | NID_EXTERNAL_TOUCH))) + return nullptr; + const int tabletPc = GetSystemMetrics(SM_TABLETPC); + const int maxTouchPoints = GetSystemMetrics(SM_MAXIMUMTOUCHES); + const bool touchScreen = digitizers & NID_INTEGRATED_TOUCH; + QPointingDevice::Capabilities capabilities = QPointingDevice::Capability::Position; + if (!touchScreen) { + capabilities.setFlag(QInputDevice::Capability::MouseEmulation); + capabilities.setFlag(QInputDevice::Capability::Scroll); + } + qCDebug(lcQpaEvents) << "Digitizers:" << Qt::hex << Qt::showbase << (digitizers & ~NID_READY) + << "Ready:" << (digitizers & NID_READY) << Qt::dec << Qt::noshowbase + << "Tablet PC:" << tabletPc << "Max touch points:" << maxTouchPoints << "Capabilities:" << capabilities; + // TODO: use system-provided name and device ID rather than empty-string and m_nextInputDeviceId + m_touchDevice = new QPointingDevice(QString(), m_nextInputDeviceId++, + (touchScreen ? QInputDevice::DeviceType::TouchScreen : QInputDevice::DeviceType::TouchPad), + QPointingDevice::PointerType::Finger, capabilities, maxTouchPoints, + // TODO: precise button count (detect whether the touchpad can emulate 3 or more buttons) + (touchScreen ? 1 : 3)); + } return m_touchDevice; } @@ -577,8 +583,8 @@ bool QWindowsPointerHandler::translatePenEvent(QWindow *window, HWND hwnd, QtWin << " message=" << Qt::hex << msg.message << " flags=" << Qt::hex << penInfo->pointerInfo.pointerFlags; - const QTabletEvent::TabletDevice device = QTabletEvent::Stylus; - QTabletEvent::PointerType type; + const QInputDevice::DeviceType device = QInputDevice::DeviceType::Stylus; + QPointingDevice::PointerType type; // Since it may be the middle button, so if the checks fail then it should // be set to Middle if it was used. Qt::MouseButtons mouseButtons = queryMouseButtons(); @@ -588,16 +594,16 @@ bool QWindowsPointerHandler::translatePenEvent(QWindow *window, HWND hwnd, QtWin mouseButtons = Qt::LeftButton; if (penInfo->penFlags & (PEN_FLAG_ERASER | PEN_FLAG_INVERTED)) { - type = QTabletEvent::Eraser; + type = QPointingDevice::PointerType::Eraser; } else { - type = QTabletEvent::Pen; + type = QPointingDevice::PointerType::Pen; if (pointerInContact && penInfo->penFlags & PEN_FLAG_BARREL) mouseButtons = Qt::RightButton; // Either left or right, not both } switch (msg.message) { case WM_POINTERENTER: { - QWindowSystemInterface::handleTabletEnterProximityEvent(device, type, sourceDevice); + QWindowSystemInterface::handleTabletEnterProximityEvent(int(device), int(type), sourceDevice); m_windowUnderPointer = window; // The local coordinates may fall outside the window. // Wait until the next update to send the enter event. @@ -610,7 +616,7 @@ bool QWindowsPointerHandler::translatePenEvent(QWindow *window, HWND hwnd, QtWin m_windowUnderPointer = nullptr; m_currentWindow = nullptr; } - QWindowSystemInterface::handleTabletLeaveProximityEvent(device, type, sourceDevice); + QWindowSystemInterface::handleTabletLeaveProximityEvent(int(device), int(type), sourceDevice); break; case WM_POINTERDOWN: case WM_POINTERUP: @@ -635,7 +641,7 @@ bool QWindowsPointerHandler::translatePenEvent(QWindow *window, HWND hwnd, QtWin } const Qt::KeyboardModifiers keyModifiers = QWindowsKeyMapper::queryKeyboardModifiers(); - QWindowSystemInterface::handleTabletEvent(target, localPos, hiResGlobalPos, device, type, mouseButtons, + QWindowSystemInterface::handleTabletEvent(target, localPos, hiResGlobalPos, int(device), int(type), mouseButtons, pressure, xTilt, yTilt, tangentialPressure, rotation, z, sourceDevice, keyModifiers); return false; // Allow mouse messages to be generated. |