Skip to content

allow multiple identical devices to be configured #940

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

patrick99e99
Copy link
Contributor

@patrick99e99 patrick99e99 commented Jun 2, 2025

After my last pull request was merged in for the pointerRedirectsToScroll feature, I realized that if you have two identical devices (such as two trackballs that are the same model from the same manufacturer), the configuration object currently is shared for BOTH devices, so impossible to make one handle mouse events, and the other redirect to scroll.

The changes in this PR fix this behavior, so now if there are multiple identical devices then a number is appended to the name in the settings UI so they will show up like "CST Laser Trackball #1" and "CST Laser Trackball #2". But if there is only one device of a type, then it will not show that number.

In order to ensure a unique configuration object was created for each duplicate device, I needed to include something in the productName property to differentiate the devices, so I used the device's id property for that.

Thanks.

@lujjjh
Copy link
Collaborator

lujjjh commented Jun 2, 2025

Thanks a lot for the contribution!

I'm not sure prepending the id in productName can reliably solve the issue you described. The id is not a stable value—it depends on the order in which devices are connected or discovered—so it’s not suitable for serialization into persistent storage like the configuration file.

When I originally designed this, I considered using serialNumber to distinguish identical devices. While not all devices have it (for example, my Logitech USB receiver), in my experience, devices connected via Bluetooth usually do provide a serial number.

Also, this change introduces a breaking change: since the productName would change, existing configuration schemes would stop working unless users manually update their configuration.

@patrick99e99 patrick99e99 force-pushed the fix-for-multiple-identical-devices branch from 9dfe1c7 to a625d1c Compare June 2, 2025 06:02
@patrick99e99
Copy link
Contributor Author

I'm not sure prepending the id in productName can reliably solve the issue you described. The id is not a stable value—it depends on the order in which devices are connected or discovered—so it’s not suitable for serialization into persistent storage like the configuration file.

Yeah, I was just doing some testing and noticed that and made a change (force pushed) to basically just add the #1 or #2 at the end IF there are duplicates...

Also, this change introduces a breaking change: since the productName would change, existing configuration schemes would stop working unless users manually update their configuration.

Well, what I just changed would now only break configurations IF people had multiple identical devices-- which might be unlikely?

@lujjjh
Copy link
Collaborator

lujjjh commented Jun 2, 2025

Thanks for your quick response.

I'm still not convinced duplicateIdentifier is stable. It relies on device connection order, which can lead to issues like reconnected devices being assigned new, duplicate identifiers (e.g., reconnected #1 becoming #2). This means configurations could be randomly applied after restarts, which isn't ideal.

I agree that it makes sense to distinguish between devices with the same product name in the UI. However, our first step should probably be figuring out how to get a stable serial number / identifier for them. If you can shed some light on why the device isn't acquiring a serial number, we might be able to offer more targeted solutions.

@patrick99e99 patrick99e99 force-pushed the fix-for-multiple-identical-devices branch from 4d0f3db to 7b6194d Compare June 2, 2025 19:58
@patrick99e99
Copy link
Contributor Author

patrick99e99 commented Jun 2, 2025

I'm still not convinced duplicateIdentifier is stable. It relies on device connection order, which can lead to issues like reconnected devices being assigned new, duplicate identifiers (e.g., reconnected #1 becoming #2). This means configurations could be randomly applied after restarts, which isn't ideal.

Yeah, that's something I did not consider...

I agree that it makes sense to distinguish between devices with the same product name in the UI. However, our first step should probably be figuring out how to get a stable serial number / identifier for them. If you can shed some light on why the device isn't acquiring a serial number, we might be able to offer more targeted solutions.

Unfortunately, it looks like the CST Laser Trackball devices don't have serial numbers:
Screenshot 2025-06-02 at 10 47 12 AM

How about the commit I just pushed up now? I added 'locationID' to devices and made the DeviceMatcher fallback to locationID if serialNumber is nil.. What do you think of that approach?

@patrick99e99
Copy link
Contributor Author

patrick99e99 commented Jun 2, 2025

and also just changed the UI's duplicate handling of CST Trackball #1 to CST Trackball [serial or location] since that numbering was unreliable.

@lujjjh
Copy link
Collaborator

lujjjh commented Jun 3, 2025

Adding locationId matching sounds promising! I'll test this change when I have time, and thank you again for your contribution.

However, the logic around implementing locationId matching will be quite complex. This is mainly because:

  • If we unconditionally add locationId matching: Every time users plug a device into a different USB port, the system would recognize it as a "new" device. This would force them to reconfigure all their devices, significantly impacting the user experience.
  • If we determine whether to add locationId matching based on duplicate devices: While this approach sounds more reasonable, it could complicate future adjustments to existing configuration schemes or require us to re-evaluate how current configurations are applied.

Ideally, we'll need a more comprehensive scheme management user interface to effectively handle these scenarios.

I also noticed #906. This locationId approach might not fully address all the use cases there, especially when devices are connected via the same port (meaning their locationId is identical). In such scenarios, it would still be impossible to distinguish between them. A more robust, though labor-intensive, solution would be to adapt to each manufacturer's private protocol—like hidpp—to obtain individual device serial numbers.

Copy link
Contributor

github-actions bot commented Aug 3, 2025

This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 10 days.

@github-actions github-actions bot added the Stale label Aug 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants