Fix macOS volume and media key posting#184
Conversation
Greptile SummaryThis PR replaces the placeholder
Confidence Score: 3/5The approach is correct and the constants are accurate, but the loop's early-return on failure can leave a key-down event posted without a paired key-up, which is worth fixing before merge. The crates/openlogi-core/src/binding.rs — specifically the error branches inside the Important Files Changed
Sequence DiagramsequenceDiagram
participant A as Action::execute_macos
participant M as macos::post_media_key
participant NS as NSEvent (AppKit)
participant CG as CGEvent (CoreGraphics)
participant OS as macOS HID System
A->>M: "post_media_key(NX_KEYTYPE_*)"
loop key-down then key-up
M->>NS: "otherEventWithType(SystemDefined, subtype=8, data1)"
NS-->>M: "Option<NSEvent>"
M->>NS: ns_event.CGEvent()
NS-->>M: "Option<CGEvent>"
M->>CG: CGEvent::post(HIDEventTap, cg_event)
CG->>OS: deliver NX_SUBTYPE_AUX_CONTROL_BUTTONS event
end
Reviews (1): Last reviewed commit: "Fix macOS volume and media key posting" | Re-trigger Greptile |
| ) else { | ||
| tracing::warn!(nx_key, phase, "NSEvent::otherEventWithType failed"); | ||
| return; | ||
| }; | ||
| let Some(cg_event) = ns_event.CGEvent() else { | ||
| tracing::warn!(nx_key, phase, "NSEvent::CGEvent failed"); | ||
| return; | ||
| }; | ||
| CGEvent::post(CGEventTapLocation::HIDEventTap, Some(&cg_event)); | ||
| } |
There was a problem hiding this comment.
Early
return can leave key-down posted without matching key-up
If the first iteration (key-down) posts successfully and the second iteration (key-up) then hits either NSEvent::otherEventWithType returning None or ns_event.CGEvent() returning None, the return exits the function entirely — leaving a key-down event in the system with no paired key-up. The post_click function in the same module handles this more gracefully with if let Ok. Using break instead of return in the failure branches would avoid posting orphaned key-down events for volume/media while still aborting any remaining work.
Summary
Validation
Fixes mouse-button bindings for Volume Up/Down/Mute on macOS, where kVK_Volume* keyboard events are ignored by the system volume handler.