Skip to content

Commit

Permalink
fix(macos): global keys shortcuts (#1156)
Browse files Browse the repository at this point in the history
* fix: send key equivalent to menu

* Create wkwebview.md

* Update wkwebview.md
  • Loading branch information
thewh1teagle authored Jan 31, 2024
1 parent 818dc8d commit c033bd2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changes/wkwebview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wry": patch
---

On `macOS`, fix menu keyboard shortcuts. This issue bug was introduced in `v2` when added `webview` as `child`.
14 changes: 14 additions & 0 deletions src/wkwebview/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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),
Expand Down

0 comments on commit c033bd2

Please sign in to comment.