Fix macOS volume and media key posting#184
Conversation
Greptile SummaryReview completed and submitted via submit_review tool. Confidence Score: 5/5Safe to merge. No blocking issues found. No files require special attention. Reviews (2): Last reviewed commit: "fix(core): drain media-key NSEvent autor..." | 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.
|
@AprilNEA can we get this merged please? |
…dia-keys # Conflicts: # crates/openlogi-core/Cargo.toml
post_media_key runs on the hook/gesture dispatch threads, which have no run loop to drain autorelease pools, and NSEvent creation plus the CGEvent getter both autorelease temporaries — every media/volume press leaked them for the lifetime of the thread. Wrap the exchange in an explicit objc2::rc::autoreleasepool, the same pattern (and reasoning) as the hook's frontmost_bundle_id. This also puts the previously unused direct objc2 dependency to use.
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.