Skip to content

Improve Logitech device lifecycle and restore hardware state - #1376

Merged
lujjjh merged 84 commits into
mainfrom
fix/logitech-device-lifecycle
Aug 31, 2026
Merged

lujjjh merged 84 commits into
mainfrom
fix/logitech-device-lifecycle

Conversation

@lujjjh

@lujjjh lujjjh commented Aug 30, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Preserve configured pointer speed, hardware DPI, and Hi-Res Wheel mode across system sleep instead of round-tripping them through their baselines.
  • Restore every managed Logitech setting when LinearMouse exits or the user session becomes inactive.
  • Reconcile direct devices immediately after wake and require fresh, exact receiver discovery before reopening receiver-routed HID++ writes.
  • Bound and cancel HID++ teardown work so application termination cannot block indefinitely.
  • Move shared HID++ transport and feature logic into the standalone HIDPP module.

Background

Logitech settings are stored on the device and may remain active after LinearMouse stops. Previously, transports could be invalidated before every managed setting was restored, leaving hardware DPI, wheel mode, diverted controls, or receiver notification flags behind after exit.

System sleep has different semantics from exit or account switching: the app still owns the same configuration, and restoring the hardware baseline only to reapply it after wake creates a visible period at the wrong pointer speed. Receiver reconnects also need special care because a pre-sleep slot can identify a different logical device after wake.

Changes

  • Split lifecycle handling into running, suspended, and terminally stopped states. Sleep keeps PointerKit observation and software pointer settings alive; session deactivation and exit perform full restoration.
  • Suspend ordinary Logitech reads and writes atomically during sleep without consuming DPI or wheel baselines. Direct USB and Bluetooth devices resume immediately; receiver devices remain suspended until a concrete rediscovery request returns a unique route.
  • Keep Hi-Res normalization state only while its target and post-wake verification remain valid.
  • Best-effort restore diverted controls to native reporting while the event pipeline is paused, then resume each monitor through its exact restart barrier. A receiver monitor is not resumed before its route is verified.
  • Capture each pre-managed hardware value before the first write and consume its baseline only after readback confirms restoration.
  • Restore HIDUseLinearScalingMouseAcceleration exactly on terminal teardown and avoid writing a missing value.
  • Register session observers before launch completes so an app started in an inactive user session cannot manage global hardware.
  • Release synthesized raw-report buttons at lifecycle boundaries so sleep or account switching cannot leave a button stuck.
  • Normalize stable Logitech serials, reject missing-identity sentinels, and fail closed when a receiver target cannot be identified safely.

Safety and compatibility

  • Sleep does not write pointer speed, DPI, or Hi-Res Wheel baselines.
  • Account switching and app exit still restore software pointer state, DPI, Hi-Res Wheel mode, diverted controls, and receiver notification flags.
  • Receiver-routed terminal writes require a stable logical-device identity; ambiguous targets are skipped rather than risking a write to another paired device.
  • Non-Logitech devices do not enter HID++ cleanup, and raw-report synthetic state is explicitly released before suspension.

Testing

  • CI-equivalent make configure clean lint test: HIDPP 20 passed, PointerKit 9 passed, LinearMouse 841 passed
  • LinearMouse Thread Sanitizer: 841 passed
  • HIDPP and PointerKit Thread Sanitizer runs: passed
  • xcodebuild analyze: passed
  • SwiftFormat: passed; SwiftLint: 0 serious violations
  • git diff --check: passed

lujjjh added 30 commits August 29, 2026 19:09
@lujjjh
lujjjh marked this pull request as draft August 30, 2026 14:58
@lujjjh
lujjjh marked this pull request as ready for review August 31, 2026 16:15
@lujjjh
lujjjh merged commit 5525bfd into main Aug 31, 2026
1 check passed
@lujjjh
lujjjh deleted the fix/logitech-device-lifecycle branch August 31, 2026 16:16
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.

1 participant