Skip to content

Restore mappings for buttons recovered from HID reports - #1448

Merged
lujjjh merged 1 commit into
mainfrom
fix/hid-side-button-mappings
Oct 10, 2026
Merged

lujjjh merged 1 commit into
mainfrom
fix/hid-side-button-mappings

Conversation

@lujjjh

@lujjjh lujjjh commented Oct 10, 2026

Copy link
Copy Markdown
Collaborator

Buttons reconstructed by the HID compatibility handlers were marked as synthetic and skipped by the button mapping pipeline. Give these physical inputs a distinct marker so they can trigger configured mappings, while keeping replayed events excluded to prevent repeated mapping.

Apply this distinction to the generic side-button, Kensington Slimblade, and ELECOM handlers. Device matching and HID report parsing remain unchanged.

Related to #1439.

Validation:

  • make test passed, including 1,146 application tests. Four DockKit tests were skipped.
  • Added regression coverage for both side buttons, Option modifiers, and fallback replay without remapping.
  • Changed files pass formatting and strict lint checks. Full-repository lint still reports existing violations.

The affected hardware is not available locally. This addresses a confirmed code-path issue, but resolution of #1439 remains unverified. After merging and releasing, the reporter will need to test it on their device.

Implementation assisted by Codex.

Distinguish physical buttons reconstructed by HID compatibility handlers from synthetic fallback events so mappings can recognize them without remapping replayed clicks.

Related to #1439.

Co-authored-by: Codex <[email protected]>
@lujjjh lujjjh added the bug Something isn't working label Oct 10, 2026
@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: linearmouse/linearmouse/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: cece893c-53ab-4556-a6ff-bfb660d8e958

📥 Commits

Reviewing files that changed from the base of the PR and between 1a6c3f4 and 8eeccfa.


📒 Files selected for processing (7)
  • LinearMouse/Device/InputReportHandler.swift
  • LinearMouse/Device/InputReportHandlers/ElecomTrackballHandler.swift
  • LinearMouse/Device/InputReportHandlers/GenericSideButtonHandler.swift
  • LinearMouse/Device/InputReportHandlers/KensingtonSlimbladeHandler.swift
  • LinearMouse/EventTransformer/ButtonMappingTransformer.swift
  • LinearMouse/Utilities/CGEvent+LinearMouseSynthetic.swift
  • LinearMouseUnitTests/EventTransformer/ButtonMappingTransformerTests.swift

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.



📝 Walkthrough

Walkthrough

HID input report handlers now emit button events with a distinct HID marker. The button mapping transformer allows marked HID-button events through while continuing to exclude other LinearMouse synthetic events. Tests cover button mappings, modifier flags, and fallback behavior.

Changes

HID Button Mapping

Layer / File(s) Summary
Mark and emit button events
LinearMouse/Utilities/CGEvent+LinearMouseSynthetic.swift, LinearMouse/Device/InputReportHandler.swift
The event emitter distinguishes HID-button events from other synthetic events. It validates button conversions and returns without posting when event creation fails.
Route HID buttons through mapping
LinearMouse/Device/InputReportHandlers/*, LinearMouse/EventTransformer/ButtonMappingTransformer.swift, LinearMouseUnitTests/EventTransformer/ButtonMappingTransformerTests.swift
Three input report handlers use the HID-button emitter. The transformer allows marked HID-button events through. Tests cover button 3 and 4 mappings, Option modifier flags, and synthetic fallback events.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant ElecomTrackballHandler
  participant SyntheticMouseButtonEventEmitter
  participant ButtonMappingTransformer
  ElecomTrackballHandler->>SyntheticMouseButtonEventEmitter: postHIDButton(button, down)
  SyntheticMouseButtonEventEmitter->>ButtonMappingTransformer: post marked HID-button event
  ButtonMappingTransformer->>ButtonMappingTransformer: apply matching button mapping
Loading

Merge Risk | ⚪ Minimal · up to 8eecc

Merge Risk: ⚪ Minimal · up to 8eecc

No concrete merge-blocking issue remains. The hardware-specific outcome still needs confirmation on the affected device after release.

Security Architecture Review

Security architecture risk: 🟡 Moderate · up to 8eecc

The fix restores intended button mappings, but the new origin tag also exempts events from other-application filtering. If another application with event-injection permission can preserve that tag, it could trigger configured keystrokes or commands. This cross-application path remains unverified; replay protection and button-release cleanup are preserved.

Retained concerns

  • Medium · security · inferred: The new constant HID origin tag simultaneously bypasses other-application filtering and admits events into configured button actions, without independently checking local-emission provenance. If an external process permitted to inject events can preserve this tag, it could trigger configured keystrokes or commands despite the source-filter preference. The base rejected synthetic events at the mapping gate. Cross-process forgery and preservation are unverified, and the separate source-application bypass set still applies.
Security review details

Security Blast Radius

  • inferred — The supported exposure is local action execution in the selected configuration: keyboard and mouse synthesis, window operations, and configured commands launched by LinearMouse. A forged event would not itself choose arbitrary command text; consequences depend on the mappings already configured.

Security Findings and Attack Paths

  • inferred — The conditional attack path is external event injection with the HID user-data tag, exemption from general source filtering, button-mapping admission, and execution of a matching configured action. Repository evidence establishes these consumer decisions, but not cross-process tag preservation or an independently verified exploit.

Trust Boundaries and Controls

  • observed — The event tap passes the event's positive source PID into routing, but HID-marker recognition checks only user-data equality. Thus the routing tag is not an independent authentication check. Ordinary external events remain subject to the source-filter preference, and the separate application bypass set still applies.

Resilience and Maintainability Implications

  • observed — Fresh fallback clicks receive the ordinary synthetic marker, preventing recursive HID remapping. Regression tests assert this exclusion. Transformer deactivation resets recognition lanes and delegates cleanup to an executor that cancels repeats and releases held keys.

Hardening Proposals

  • proposed — Validate cross-process marker behavior on the supported platform. Consider binding the HID exception to trusted local-emission provenance rather than a constant tag alone, while retaining ordinary replay exclusion.

Pre-merge checks | Passed 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check Passed The title clearly identifies the main change: restoring button mappings for inputs reconstructed from HID reports.
Description check Passed The description directly explains the HID event marker change, affected handlers, replay behavior, tests, and validation status.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.

✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR


🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@lujjjh
lujjjh merged commit d12e52d into main Oct 10, 2026
2 checks passed
@lujjjh
lujjjh deleted the fix/hid-side-button-mappings branch October 10, 2026 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant