Skip to content

Add Logitech control button support for gesture trigger and auto scroll - #1134

Merged
lujjjh merged 4 commits into
mainfrom
gesture-trigger-and-logitech-support
Mar 26, 2026
Merged

lujjjh merged 4 commits into
mainfrom
gesture-trigger-and-logitech-support

Conversation

@lujjjh

@lujjjh lujjjh commented Mar 26, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Gesture trigger refactor: Replace hardcoded middle-button Picker with a recording interface (ButtonMappingButtonRecorder) supporting any mouse button + modifier key combination. Migrates button: Int to trigger: Mapping with backwards-compatible Codable (legacy button field auto-migrates).
  • Logitech HID++ support: Logitech reprogrammable control buttons now work as gesture and auto-scroll triggers via direct HID++ event routing. Adds gesture control IDs to the diversion whitelist.
  • Native control ID exclusion: Left/right/middle mouse button CIDs (0x0050–0x0052) are excluded from HID++ diversion alongside back/forward, preventing breakage of OS-handled buttons.
  • Multi-display fix: Logitech control event handler now resolves PID from the window under the mouse cursor (matching GlobalEventTap behavior) instead of the frontmost application, fixing gesture/auto-scroll triggers when focus and cursor are on different displays.
  • Thread safety: Logitech handleLogitechControlEvent in both AutoScrollTransformer and GestureButtonTransformer now dispatches all state mutations to the main thread, fixing a data race with the CGEvent tap callback.
  • Modifier check fix: GestureButtonTransformer Logitech handler only checks modifier flags on button press (not release), preventing stuck tracking state when modifier is released before the button.
  • Schema backwards compat: Deprecated button field retained in JSON schema so old configs validate. enabled field preserved with ?? false default.
  • Code quality: LogitechEventContext promoted to standalone type. Logitech dispatch order aligned with transformer construction order. desiredDivertedControlIDs uses mouseLocationPid.
  • Disable preserves config: Disabling gesture sets enabled = false instead of wiping the configuration.

Test plan

  • 142 unit tests pass (including 9 new Gesture Codable migration tests)
  • Verify gesture trigger works with middle button, side buttons, and modifier combos
  • Verify Logitech reprogrammable control button as gesture trigger (single and multi-display)
  • Verify Logitech control button as auto-scroll trigger
  • Verify native mouse buttons (left/right/middle/back/forward) are not broken by HID++ diversion
  • Verify legacy configs with "button": 2 migrate correctly
  • Verify disabling and re-enabling gesture preserves trigger/threshold/actions

lujjjh added 2 commits March 26, 2026 22:17
…auto-scroll

- Replace gesture button Picker with recording interface supporting any
  mouse button + modifier key combination (Mapping-based trigger)
- Add backward-compatible migration from legacy "button" field to "trigger"
- Route Logitech HID++ control events directly to GestureButtonTransformer
  and AutoScrollTransformer, bypassing synthetic events that caused cache
  key mismatches
- Add gesture trigger to Logitech diversion whitelist so HID++ controls
  are properly diverted when configured as gesture triggers
- Include .mouseMoved in GlobalEventTap event mask when gesture is enabled
- Handle .mouseMoved in GestureButtonTransformer and AutoScrollTransformer
  for Logitech controls (which don't produce OS-level drag events)
- Fix background-thread crash in AutoScrollTransformer by dispatching
  activate/deactivate to main thread
- Change enabled defaults from false to true for auto-scroll and gesture
  to match existing Smoothed.enabled convention
- Preserve gesture settings when disabling (set enabled=false instead of
  wiping config)
- Add left/right/middle mouse CIDs (0x0050-0x0052) to native control ID
  set to prevent diverting OS-handled buttons
Use mouse-location window PID instead of frontmost app PID when
resolving the event transformer for Logitech HID++ control events.
This matches how GlobalEventTap resolves transformers for CGEvents,
preventing cache key mismatches when the focused app is on a different
display than the mouse pointer.
@lujjjh lujjjh changed the title Refactor gesture trigger and add Logitech HID++ support Add Logitech control button support for gesture trigger and auto scroll Mar 26, 2026
@lujjjh lujjjh added the enhancement New feature or request label Mar 26, 2026
lujjjh added 2 commits March 26, 2026 23:14
- Dispatch Logitech handleLogitechControlEvent to main thread in both
  AutoScrollTransformer and GestureButtonTransformer to fix data race
- Move modifier flags check to press-only path in GestureButtonTransformer
  so release events aren't blocked when modifier is released first
- Revert enabled defaults to ?? false for both autoScroll and gesture
- Add deprecated "button" field back to JSON schema for backwards compat
- Promote LogitechEventContext to standalone type (was nested in
  ButtonActionsTransformer but used by three transformer types)
- Align desiredDivertedControlIDs PID resolution with event handler
  (use mouseLocationPid instead of frontmostPid)
- Use NSEvent.mouseLocation instead of CGEvent(source: nil) in
  AutoScrollTransformer Logitech handler
- Align Logitech dispatch order with transformer construction order
- Add 9 unit tests for Gesture Codable migration (legacy button→trigger,
  enabled handling, encoding, round-trip)
NSEvent.mouseLocation is already in Cocoa coordinates (Y=0 at bottom),
same as CGEvent.unflippedLocation which activate(at:) expects. The
manual Y flip was incorrectly converting to Quartz coordinates.
@lujjjh
lujjjh merged commit 7db2346 into main Mar 26, 2026
1 check passed
@lujjjh
lujjjh deleted the gesture-trigger-and-logitech-support branch March 26, 2026 15:22
@lujjjh lujjjh linked an issue Mar 30, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use another button to press and hold while dragging

1 participant