Cocoa: deal with unexpected tablet events without proximity

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ø <tor.arne.vestbo@qt.io>
This commit is contained in:
Shawn Rutledge 2022-07-01 15:17:18 +02:00
parent 60c69b4da5
commit 3372e1db14

View File

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