From c033bd27f23953537520d17493c7b77ea146e7d5 Mon Sep 17 00:00:00 2001 From: thewh1teagle <61390950+thewh1teagle@users.noreply.github.com> Date: Wed, 31 Jan 2024 02:15:53 +0200 Subject: [PATCH] fix(macos): global keys shortcuts (#1156) * fix: send key equivalent to menu * Create wkwebview.md * Update wkwebview.md --- .changes/wkwebview.md | 5 +++++ src/wkwebview/mod.rs | 14 ++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 .changes/wkwebview.md diff --git a/.changes/wkwebview.md b/.changes/wkwebview.md new file mode 100644 index 000000000..0cc876944 --- /dev/null +++ b/.changes/wkwebview.md @@ -0,0 +1,5 @@ +--- +"wry": patch +--- + +On `macOS`, fix menu keyboard shortcuts. This issue bug was introduced in `v2` when added `webview` as `child`. diff --git a/src/wkwebview/mod.rs b/src/wkwebview/mod.rs index 0607e2b72..cd929b4fa 100644 --- a/src/wkwebview/mod.rs +++ b/src/wkwebview/mod.rs @@ -342,6 +342,10 @@ impl InnerWebView { sel!(acceptsFirstMouse:), accept_first_mouse as extern "C" fn(&Object, Sel, id) -> BOOL, ); + decl.add_method( + sel!(performKeyEquivalent:), + key_equivalent as extern "C" fn(&mut Object, Sel, id) -> BOOL, + ); extern "C" fn accept_first_mouse(this: &Object, _sel: Sel, _event: id) -> BOOL { unsafe { @@ -353,7 +357,17 @@ impl InnerWebView { } } } + + extern "C" fn key_equivalent(_this: &mut Object, _sel: Sel, event: id) -> BOOL { + unsafe { + let app = cocoa::appkit::NSApp(); + let menu: id = msg_send![app, mainMenu]; + let () = msg_send![menu, performKeyEquivalent: event]; + } + YES + } } + decl.register() } _ => class!(WryWebView),