mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-20 21:34:14 +02:00
Fix the 3D mouse search asking every device on the PC for its name
While no 3D mouse is plugged in, which for most users is always, the hidapi backend looks for one every 3 seconds for as long as QElectroTech runs. It asked hidapi for every HID device, hid_enumerate(0, 0), and on Windows hidapi reads the serial number, manufacturer and product strings of each device that matches what it is asked for from the device itself. So every mouse, keyboard, headset and webcam on the PC was asked for its names every 3 seconds, on the GUI thread. Issue #1553 reports the pointer moving by itself on Windows since the first package with this backend; nothing else in that package talks to devices. SDL 2.0.9 polled the same way and saw freezes and a keyboard that kept re-initialising (libsdl-org/SDL#3071). The scan now asks for 3Dconnexion's vendor id, and for each 3D mouse made under Logitech's id by its product id, since most other mice and keyboards carry Logitech's id too. That is twelve hidapi calls instead of one, but a device that does not match is no longer asked for its names. On Linux and macOS hidapi takes the names from the system, and one call is cheaper than twelve (on Linux, median of 200: 5 ms against 36 ms), so the scan there is unchanged. Where the scan is filtered, a Logitech-id device that is not one of the eleven 3D mice on the list is no longer found, even if it reports itself as a multi-axis controller. 3Dconnexion's own mice and keyboards, such as the CadMouse, are still asked: their vendor id is asked for as a whole, so that new 3D mice are found without a list. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -74,6 +74,8 @@ class TstSpaceMouseHid : public QObject
|
||||
private slots:
|
||||
void recognisesOnly3DMice_data();
|
||||
void recognisesOnly3DMice();
|
||||
void scanAsksOnlyFor3DMice_data();
|
||||
void scanAsksOnlyFor3DMice();
|
||||
void parsesTheClassicDescriptor();
|
||||
void parsesADescriptorWithoutReportIds();
|
||||
void survivesBrokenDescriptors_data();
|
||||
@@ -115,6 +117,41 @@ void TstSpaceMouseHid::recognisesOnly3DMice()
|
||||
QCOMPARE(isSpaceMouse(vendor, product, page, usage), match);
|
||||
}
|
||||
|
||||
// Where hidapi reads the name strings of every device a scan asks for
|
||||
// from the device itself, as on Windows, the other devices on the PC
|
||||
// must never be asked for at all (issue #1553).
|
||||
void TstSpaceMouseHid::scanAsksOnlyFor3DMice_data()
|
||||
{
|
||||
QTest::addColumn<int>("vendor");
|
||||
QTest::addColumn<int>("product");
|
||||
QTest::addColumn<bool>("asked");
|
||||
QTest::newRow("3Dconnexion SpaceMouse Compact") << 0x256f << 0xc635 << true;
|
||||
QTest::newRow("3Dconnexion receiver") << 0x256f << 0xc652 << true;
|
||||
QTest::newRow("Logitech SpaceNavigator") << 0x046d << 0xc626 << true;
|
||||
QTest::newRow("Logitech SpacePilot Pro") << 0x046d << 0xc629 << true;
|
||||
QTest::newRow("Logitech receiver") << 0x046d << 0xc52b << false;
|
||||
QTest::newRow("Logitech mouse") << 0x046d << 0xc077 << false;
|
||||
QTest::newRow("Microsoft keyboard") << 0x045e << 0x07f8 << false;
|
||||
QTest::newRow("HP mouse") << 0x03f0 << 0x094a << false;
|
||||
}
|
||||
|
||||
void TstSpaceMouseHid::scanAsksOnlyFor3DMice()
|
||||
{
|
||||
QFETCH(int, vendor);
|
||||
QFETCH(int, product);
|
||||
QFETCH(bool, asked);
|
||||
|
||||
// hid_enumerate()'s own rule: an id of 0 matches every id.
|
||||
bool matched = false;
|
||||
for (const DeviceId &id : scanIds()) {
|
||||
if ((id.vendor == 0 || id.vendor == vendor)
|
||||
&& (id.product == 0 || id.product == product)) {
|
||||
matched = true;
|
||||
}
|
||||
}
|
||||
QCOMPARE(matched, asked);
|
||||
}
|
||||
|
||||
void TstSpaceMouseHid::parsesTheClassicDescriptor()
|
||||
{
|
||||
const Layout layout = parseDescriptor(classicDescriptor(true));
|
||||
|
||||
Reference in New Issue
Block a user