From 3372e1db14679840844d64e9e3de8aa567828939 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Fri, 1 Jul 2022 15:17:18 +0200 Subject: [PATCH] Cocoa: deal with unexpected tablet events without proximity MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the user has a Wacom stylus in proximity of the tablet already (perhaps left it lying on the tablet) and starts a Qt application, we don't get to see a proximity enter event, so a lot of device information is missing; nevertheless, creating a stop-gap device (with ID 0, type Unknown) makes it possible to get basic QTabletEvents with pressure, until the next time the stylus leaves and comes back into proximity. Pick-to: 6.4 Fixes: QTBUG-65559 Change-Id: Ibacbdb78461c0b62d4040c80d210a1b06074e952 Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/cocoa/qnsview_tablet.mm | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/plugins/platforms/cocoa/qnsview_tablet.mm b/src/plugins/platforms/cocoa/qnsview_tablet.mm index 72e1b2d78f..4c6e351b3f 100644 --- a/src/plugins/platforms/cocoa/qnsview_tablet.mm +++ b/src/plugins/platforms/cocoa/qnsview_tablet.mm @@ -34,14 +34,18 @@ Q_GLOBAL_STATIC(QCocoaTabletDeviceMap, devicesInProximity) // We use devicesInProximity because deviceID is typically 0, // so QInputDevicePrivate::fromId() won't work. - const auto *device = devicesInProximity->value(theEvent.deviceID); - if (!device) { - // Error: Unknown tablet device. Qt also gets into this state - // when running on a VM. This appears to be harmless; don't - // print a warning. - return false; + const auto deviceId = theEvent.deviceID; + const auto *device = devicesInProximity->value(deviceId); + if (!device && deviceId == 0) { + // Application started up with stylus in proximity already, so we missed the proximity event? + // Create a generic tablet device for now. + device = tabletToolInstance(theEvent); + devicesInProximity->insert(deviceId, device); } + if (Q_UNLIKELY(!device)) + return false; + bool down = (eventType != NSEventTypeMouseMoved); qreal pressure;