New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
On macOS, pass key event to menu on key press #760
Conversation
|
||
// Key event chain is consumed by window and cannot pass to menu. | ||
// So we pass the event to menu if we have one | ||
extern "C" fn key_down(_: &mut Object, _: Sel, event: id) { | ||
unsafe { | ||
let app = cocoa::appkit::NSApp(); | ||
let menu: id = msg_send![app, mainMenu]; | ||
if !menu.is_null() { | ||
let () = msg_send![menu, performKeyEquivalent: event]; | ||
} | ||
} | ||
} | ||
// We need to declare this method to get Command+ key equivalent. | ||
extern "C" fn do_command_by_selector(_: &Object, _: Sel, _: Sel) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this fix be upstream to winit
? seems like a valid use-case for any winit app.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
winit can call performKeyEquivalent
in WinitWindow
's sendEvent
but I'm not sure if winit team willing to take this workaround. Key event chain in macOS is a mess tbh.
As for workaround for users of winit, I think we can add a NSView as subview and add similar code like above. Or just replace winitWindow
with default NSView if they don't care any window events sent from winit like we did before (we can't do this in wry anymore since event like resize has moved to winitView).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
winit ships with a default menu so this workaround is valid for their use-case too but we won't know for sure until we open a PR.
What kind of change does this PR introduce?
Does this PR introduce a breaking change?
Checklist
fix: remove a typo, closes #___, #___
)Other information
fix tauri-apps/tauri#2626