Skip to content

Match a receiver-connected Logitech mouse as the paired device - #1385

Closed
reowens wants to merge 2 commits into
linearmouse:mainfrom
reowens:fix/receiver-logical-identity-matcher
Closed

reowens wants to merge 2 commits into
linearmouse:mainfrom
reowens:fix/receiver-logical-identity-matcher

Conversation

@reowens

@reowens reowens commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Fixes #1075.

Problem

A Logitech mouse that is used both through a Bolt/Unifying/Lightspeed receiver and over Bluetooth gets two unrelated identities. macOS presents the receiver as the HID device, so on the receiver the matcher sees VID 0x046D / PID 0xC548 / "USB Receiver" / no serial, while over Bluetooth it sees VID 0x046D / PID 0xB042 / "MX Master 4" / serial 11D5D259 (MX Master 4). Every scheme created on one transport is invisible on the other, which reads as "settings reset when I switch" (#1075).

What LinearMouse already knew

ReceiverMonitor resolves the paired device behind a monitored receiver through HID++ pairing info: name, product ID and serial (ReceiverLogicalDeviceIdentity). LogitechHardwareTargetKey already treats that serial and the Bluetooth-side serial as the same hardware for DPI and Hi-Res Wheel baselines. The config matcher was the one place that ignored it.

Change

  • DeviceMatchCandidates (in DeviceMatcher.swift): the identity a scheme is written against (primary) plus the raw HID identity as fallback. With a resolved receiver route, primary is the paired device (vendor from the receiver, product ID, name and serial from the identity) and fallback is the receiver. Without a route, or when the identity carries neither a product ID nor a serial, primary is the physical identity and there is no fallback.
  • Device.matchCandidates derives it from logitechReceiverRouteSnapshot.
  • DeviceMatcher(of:) returns primary; DeviceMatcher.match(with: Device) accepts either candidate.
  • Scheme.MatchContext carries deviceFallback; Scheme.If.isSatisfied(in:) accepts either; [Scheme].allDeviceSpecficSchemes(of:) unions the candidates.
  • DeviceManager.receiverPointingDevicesChanged re-applies pointer speed and acceleration for a device whose match identity changed, since those were read when the device was added and before the route resolved, and republishes the device list so DeviceState, the device picker and SchemeState pick the new identity up. The route cache key in EventTransformerManager already includes the matcher, so events rebuild their route on the next event.
  • The receiver discovery log line now includes product ID and serial, so a report like automaticaclly resetting settings with mouse switch #1075 can show them.
  • Documentation/Configuration.md gains a paragraph under Device matching.

Compatibility: a scheme written against the receiver identity (0xC548 / "USB Receiver") keeps applying through the fallback. When both a receiver-keyed and a mouse-keyed scheme exist they merge in file order, as any two matching schemes do.

Tests

LinearMouseUnitTests/Model/DeviceMatcherTests.swift, 9 cases: identity resolution with and without a route, product ID or serial missing, a Bluetooth-written scheme applying through the receiver, a receiver-written scheme still applying, a scheme created through the receiver applying over Bluetooth, a different mouse on the same receiver not matching, and both identities merging.

xcodebuild test -only-testing:LinearMouseUnitTests: 850 tests, 0 failures. swiftformat --lint . and swiftlint . clean on the changed files.

Verified on hardware

MacBook Pro, macOS 26.6, MX Master 4 paired to both a Logi Bolt receiver on the Mac and Bluetooth. The debug build, launched with the mouse on Bluetooth, added the device as MX Master 4 (VID=0x046D, PID=0xB042), started the receiver monitor for the Bolt receiver, and applied the existing Bluetooth scheme (pointer speed, DPI 1100, Hi-Res Wheel).

After switching the mouse to the Bolt channel, the receiver monitor resolved slot=2 name=MX Master 4 productID=0xB042 serial=11D5D259, the same product ID and serial macOS reports over Bluetooth. The event transformer rebuilt its route with the merged scheme, the hardware DPI and Hi-Res Wheel were applied through the receiver slot, and after the route resolved the receiver device received the Bluetooth scheme's pointer speed (0.0748) and acceleration (4.0396) in place of the defaults it had at enumeration (0.069 / 3.0). The config file was not changed; both existing schemes remained as written.

🤖 Generated with Claude Code

reowens and others added 2 commits September 9, 2026 03:27
macOS presents a mouse behind a Bolt, Unifying or Lightspeed receiver
as the receiver itself, so the device matcher saw a different vendor,
product, name and serial on the receiver than over Bluetooth and every
scheme was written twice. The receiver monitor already resolves the
paired device's name, product ID and serial through HID++, and the
hardware baseline store already treats that serial as the same device
as the Bluetooth one.

DeviceMatchCandidates carries the identity a scheme is written against
(the resolved paired device when the route is known) and the raw HID
identity as a fallback, so schemes written against the receiver keep
applying. Scheme.MatchContext carries both, If.isSatisfied accepts
either, and the device-specific scheme lookup unions them. When a route
resolves and the match identity changes, DeviceManager republishes the
device list so the picker and scheme state pick the new identity up.

Fixes linearmouse#1075.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…entity

Pointer speed and acceleration are read from the matching schemes when
a device is added, before the receiver monitor has resolved the paired
device. Once the route resolves and the match identity changes, the
schemes that now match are read again for that device, so a scheme
written over Bluetooth sets the pointer speed on the receiver too.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Settings and hardware configuration paths do not yet handle all new identity candidates consistently.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 4 Medium severity

Open (4)
What changed in this PR

Unifies Logitech mouse identities across receiver and Bluetooth connections while preserving receiver-based configurations.

Changes:

  • Adds paired-device and receiver fallback matching.
  • Refreshes pointer settings when receiver identity resolves.
  • Adds tests, diagnostics, and documentation.
File Description
LinearMouseUnitTests/​Model/​DeviceMatcherTests.swift Tests receiver and Bluetooth matching behavior.
LinearMouse/​Model/​Configuration/​Scheme/​Scheme.swift Propagates and indexes fallback identities.
LinearMouse/​Model/​Configuration/​Scheme/​If/​If.swift Matches schemes against either identity.
LinearMouse/​Model/​Configuration/​DeviceMatcher.swift Defines primary and fallback candidates.
LinearMouse/​Device/​DeviceManager.swift Refreshes settings after identity changes.
LinearMouse/​Device/​Device.swift Derives match candidates from receiver routes.
Documentation/​Configuration.md Documents cross-transport matching.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +37 to +38
guard let logicalIdentity,
logicalIdentity.productID != nil || logicalIdentity.serialNumber != nil
primary = DeviceMatcher(
vendorID: physical.vendorID,
productID: logicalIdentity.productID,
productName: logicalIdentity.name,
/// The identity a scheme is written against for `device`.
init(of device: Device) {
self.init(
self = device.matchCandidates.primary
Comment on lines +218 to +223
let candidates = device.matchCandidates.all
var seen = Set<Int>()
return candidates
.flatMap { allDeviceMatcherSpecificSchemes(of: $0) }
.filter { seen.insert($0.offset).inserted }
.sorted { $0.offset < $1.offset }
lujjjh added a commit that referenced this pull request Nov 1, 2026
…oth (#1488)

A device paired to a Logitech receiver is matched by the identity it reports
through the receiver (vendor ID, product ID, serial number), with the receiver
as a second candidate. On Bolt this is the same identity as over Bluetooth, so
schemes written for the mouse over Bluetooth apply through the receiver and the
other way round, while schemes written for the receiver keep applying to every
device behind it.

The device picker lists the devices behind a receiver instead of the receiver,
and lists the receiver only while it cannot tell which device is in use.
Hardware settings and pointer settings are reapplied when the device behind a
receiver changes, and not routed to it after wake until rediscovery confirms
it. A new device-wide scheme for a device behind a receiver goes before the
receiver's app and display schemes. New conditions for Logitech devices omit
the product name when a product ID and serial number are known. Receiver logs
show only the last four characters of a serial number.

Supersedes #1385.

Co-authored-by: Robert Owens <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@lujjjh

lujjjh commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator

Thanks for working on this! I ended up taking a different approach to the scheme design in #1488, so this is handled transparently for users. It supersedes this PR, and I've credited you as a co-author. Closing.

@lujjjh lujjjh closed this Nov 4, 2026
@reowens

reowens commented Nov 4, 2026 via email

Copy link
Copy Markdown
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

automaticaclly resetting settings with mouse switch

3 participants