Skip to content

feat(macos): implement mouse button input and side button output support#2005

Merged
jtroo merged 1 commit intojtroo:mainfrom
FlameFlag:flameflag/push-nlrlossvmxzm
Apr 8, 2026
Merged

feat(macos): implement mouse button input and side button output support#2005
jtroo merged 1 commit intojtroo:mainfrom
FlameFlag:flameflag/push-nlrlossvmxzm

Conversation

@FlameFlag
Copy link
Copy Markdown
Contributor

Partially addresses #1470 (mapping mouse buttons on macOS)

Describe your changes. Use imperative present tense

Add mouse button input interception and side button (forward/backward) output
support on macOS

Mouse button output (side buttons)

Fix mbck and mfwd actions which currently panic on macOS because the code
does not know which CGEventType to use for side buttons

Use CGEventType::OtherMouseDown/Up (same event type as middle click) and
override the MOUSE_EVENT_BUTTON_NUMBER field to the correct button index (3
for Back, 4 for Forward). The Rust core-graphics crate's CGMouseButton enum
only has 3 variants but the underlying Apple API supports up to 32 buttons via
this field

Ref: init(mouseEventSource:mouseType:mouseCursorPosition:mouseButton:), setIntegerValueField

Mouse button input (event tap)

Before this change, mouse buttons in defsrc had no effect on macOS because the
Karabiner DriverKit only captures keyboard HID events

Add a CGEventTap on a background thread that intercepts mouse button
events at the HID level. Suppress mapped buttons and forward them to kanata's
processing channel for remapping; pass unmapped buttons through. Follow the same
architecture as the Windows mouse hook (src/kanata/windows/llhook.rs). Only
install the tap if the config has mouse buttons in defsrc

Require Accessibility or Input Monitoring permission in System Settings >
Privacy & Security

Checklist

  • Add documentation to docs/config.adoc
    • Yes (updated mouse button section to include macOS, added permission note)
  • Add example and basic docs to cfg_samples/kanata.kbd
    • N/A (mouse button examples already exist in kanata.kbd lines 1044-1072; no new actions added)
  • Update error messages
    • Yes (error log when event tap creation fails with permission guidance)
  • Added tests, or did manual testing
    • Yes, Manual testing on macOS with a USB mouse (side buttons, middle click, left, right)

Enable mouse buttons (mlft, mrgt, mmid, mbck, mfwd) in defsrc on macOS
by adding a CGEventTap that intercepts and remaps mouse button events.
The tap only installs if the config maps mouse buttons

Fix mbck and mfwd output actions which previously panicked on macOS

Requires Accessibility or Input Monitoring permission on macOS

Update docs/config.adoc, platform-known-issues.adoc, and
release-template.md to reflect macOS mouse support
@FlameFlag FlameFlag force-pushed the flameflag/push-nlrlossvmxzm branch from 18077b8 to 2953ff4 Compare April 7, 2026 17:09
Copy link
Copy Markdown
Owner

@jtroo jtroo left a comment

Choose a reason for hiding this comment

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

Thanks!

@jtroo jtroo merged commit 398969f into jtroo:main Apr 8, 2026
5 checks passed
@FlameFlag FlameFlag deleted the flameflag/push-nlrlossvmxzm branch April 8, 2026 05:02
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.

2 participants