Skip to content

Commit

Permalink
Remove all keydown implementations (#798)
Browse files Browse the repository at this point in the history
* Remove all keydown implementations

* Update example's js file
  • Loading branch information
wusyong committed Dec 9, 2022
1 parent 6e622ff commit fee4bf2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 39 deletions.
5 changes: 5 additions & 0 deletions .changes/keydown.md
@@ -0,0 +1,5 @@
---
"wry": patch
---

On macOS, remove all custom keydown implementations. This will bring back keydown regression but should allow all accelerator working.
20 changes: 16 additions & 4 deletions examples/menu.rs
Expand Up @@ -23,11 +23,21 @@ fn main() -> wry::Result<()> {

let mut menu = MenuBar::new();
let mut file_menu = MenuBar::new();
file_menu.add_native_item(tao::menu::MenuItem::Cut);
file_menu.add_native_item(tao::menu::MenuItem::Copy);
file_menu.add_native_item(tao::menu::MenuItem::Paste);
file_menu.add_item(
MenuItemAttributes::new("Quit").with_accelerators(&Accelerator::new(
Some(ModifiersState::SUPER),
// Some(ModifiersState::SHIFT),
// None,
Some(ModifiersState::CONTROL | ModifiersState::SHIFT),
KeyCode::KeyQ,
)),
);
file_menu.add_item(
MenuItemAttributes::new("Quit").with_accelerators(&Accelerator::new(None, KeyCode::KeyQ)),
);
file_menu.add_item(
MenuItemAttributes::new("Quit").with_accelerators(&Accelerator::new(
Some(ModifiersState::SHIFT),
KeyCode::KeyQ,
)),
);
Expand Down Expand Up @@ -63,6 +73,8 @@ fn main() -> wry::Result<()> {
(content, "text/javascript")
} else if path.ends_with(".png") {
(content, "image/png")
} else if path.ends_with(".wasm") {
(content, "application/wasm")
} else {
unimplemented!();
};
Expand All @@ -87,7 +99,7 @@ fn main() -> wry::Result<()> {
} => *control_flow = ControlFlow::Exit,
Event::MenuEvent { menu_id, .. } => {
println!("Menu clicked! {:?}", menu_id);
*control_flow = ControlFlow::Exit;
// *control_flow = ControlFlow::Exit;
}
_ => (),
}
Expand Down
36 changes: 1 addition & 35 deletions src/webview/wkwebview/mod.rs
Expand Up @@ -276,22 +276,6 @@ impl InnerWebView {
sel!(acceptsFirstMouse:),
accept_first_mouse as extern "C" fn(&Object, Sel, id) -> BOOL,
);
decl.add_method(
sel!(keyDown:),
key_down as extern "C" fn(&mut Object, Sel, id),
);

extern "C" fn key_down(this: &mut Object, _sel: 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];
}

let () = msg_send![this, performKeyEquivalent: event];
}
}

extern "C" fn accept_first_mouse(this: &Object, _sel: Sel, _event: id) -> BOOL {
unsafe {
Expand Down Expand Up @@ -703,25 +687,7 @@ r#"Object.defineProperty(window, 'ipc', {
// Inject the web view into the window as main content
#[cfg(target_os = "macos")]
{
let parent_view_cls = match ClassDecl::new("WryWebViewParent", class!(NSView)) {
Some(mut decl) => {
decl.add_method(
sel!(keyDown:),
key_down as extern "C" fn(&mut Object, Sel, id),
);

extern "C" fn key_down(this: &mut Object, _sel: Sel, event: id) {
unsafe {
let superclass: *const Class = msg_send![this, superclass];
let () = msg_send![super(this, &*superclass), keyDown: event];
}
}

decl.register()
}
None => class!(NSView),
};

let parent_view_cls = class!(NSView);
let parent_view: id = msg_send![parent_view_cls, alloc];
let _: () = msg_send![parent_view, init];
parent_view.setAutoresizingMask_(NSViewHeightSizable | NSViewWidthSizable);
Expand Down

0 comments on commit fee4bf2

Please sign in to comment.