diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2021-09-08 14:05:28 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2021-09-08 18:39:10 +0000 |
commit | fd3315bc614c907eef098d6940b9358b193c4327 (patch) | |
tree | 21c585ef8ddf5bf62b0665efb2f90e6ec5bf3c54 /src/plugins/platforms/cocoa | |
parent | 2e520f29a73fe4c3432a992d41c33220736a0d65 (diff) |
macOS: Move pointingDeviceFor helper to top of file
It's confusing to have it in the middle of the code implementing the
various interfaces. Make review of follow up patches easier by moving
it out of the way.
Change-Id: I10f6e8f7642ec0cb14ae31b14a023c6a9ef455d9
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/plugins/platforms/cocoa')
-rw-r--r-- | src/plugins/platforms/cocoa/qnsview_mouse.mm | 60 |
1 files changed, 30 insertions, 30 deletions
diff --git a/src/plugins/platforms/cocoa/qnsview_mouse.mm b/src/plugins/platforms/cocoa/qnsview_mouse.mm index 7ef5d3d053..abafb8446f 100644 --- a/src/plugins/platforms/cocoa/qnsview_mouse.mm +++ b/src/plugins/platforms/cocoa/qnsview_mouse.mm @@ -39,6 +39,36 @@ // This file is included from qnsview.mm, and only used to organize the code +static const QPointingDevice *pointingDeviceFor(qint64 deviceID) +{ + // macOS will in many cases not report a deviceID (0 value). + // We can't pass this on directly, as the QInputDevicePrivate + // constructor will treat this as a request to assign a new Id. + // Instead we use the default Id of the primary pointing device. + static const int kDefaultPrimaryPointingDeviceId = 1; + if (!deviceID) + deviceID = kDefaultPrimaryPointingDeviceId; + + if (const auto *device = QPointingDevicePrivate::pointingDeviceById(deviceID)) + return device; // All good, already have the device registered + + const auto *primaryDevice = QPointingDevice::primaryPointingDevice(); + if (primaryDevice->systemId() == kDefaultPrimaryPointingDeviceId) { + // Adopt existing primary device instead of creating a new one + QPointingDevicePrivate::get(const_cast<QPointingDevice *>(primaryDevice))->systemId = deviceID; + qCDebug(lcInputDevices) << "primaryPointingDevice is now" << primaryDevice; + return primaryDevice; + } else { + // Register a new device. Name and capabilities may need updating later. + const auto *device = new QPointingDevice(QLatin1String("mouse"), deviceID, + QInputDevice::DeviceType::Mouse, QPointingDevice::PointerType::Generic, + QInputDevice::Capability::Scroll | QInputDevice::Capability::Position, + 1, 3, QString(), QPointingDeviceUniqueId(), QCocoaIntegration::instance()); + QWindowSystemInterface::registerInputDevice(device); + return device; + } +} + /* The reason for using this helper is to ensure that QNSView doesn't implement the NSResponder callbacks for mouseEntered, mouseExited, and mouseMoved. @@ -219,36 +249,6 @@ } @end -static const QPointingDevice *pointingDeviceFor(qint64 deviceID) -{ - // macOS will in many cases not report a deviceID (0 value). - // We can't pass this on directly, as the QInputDevicePrivate - // constructor will treat this as a request to assign a new Id. - // Instead we use the default Id of the primary pointing device. - static const int kDefaultPrimaryPointingDeviceId = 1; - if (!deviceID) - deviceID = kDefaultPrimaryPointingDeviceId; - - if (const auto *device = QPointingDevicePrivate::pointingDeviceById(deviceID)) - return device; // All good, already have the device registered - - const auto *primaryDevice = QPointingDevice::primaryPointingDevice(); - if (primaryDevice->systemId() == kDefaultPrimaryPointingDeviceId) { - // Adopt existing primary device instead of creating a new one - QPointingDevicePrivate::get(const_cast<QPointingDevice *>(primaryDevice))->systemId = deviceID; - qCDebug(lcInputDevices) << "primaryPointingDevice is now" << primaryDevice; - return primaryDevice; - } else { - // Register a new device. Name and capabilities may need updating later. - const auto *device = new QPointingDevice(QLatin1String("mouse"), deviceID, - QInputDevice::DeviceType::Mouse, QPointingDevice::PointerType::Generic, - QInputDevice::Capability::Scroll | QInputDevice::Capability::Position, - 1, 3, QString(), QPointingDeviceUniqueId(), QCocoaIntegration::instance()); - QWindowSystemInterface::registerInputDevice(device); - return device; - } -} - @implementation QNSView (Mouse) - (void)initMouse |