From fd3315bc614c907eef098d6940b9358b193c4327 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Wed, 8 Sep 2021 14:05:28 +0200 Subject: [PATCH] macOS: Move pointingDeviceFor helper to top of file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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ø --- src/plugins/platforms/cocoa/qnsview_mouse.mm | 60 ++++++++++---------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/src/plugins/platforms/cocoa/qnsview_mouse.mm b/src/plugins/platforms/cocoa/qnsview_mouse.mm index 7ef5d3d0533..abafb8446f0 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(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(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