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>
This commit is contained in:
Volker Hilsheimer 2021-09-08 14:05:28 +02:00 committed by Tor Arne Vestbø
parent 2e520f29a7
commit fd3315bc61

View File

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