From 1819be1173a3c57152a4af361e09d9e22ea33a1d Mon Sep 17 00:00:00 2001 From: OJ Kwon Date: Sat, 12 May 2018 19:10:57 -0700 Subject: [PATCH] fix(mac_platform): forward keyevent to system (#511) * fix(mac_platform): forward keyevent to system * doc(changelog): update changelog --- CHANGELOG.md | 1 + src/platform/macos/events_loop.rs | 5 +---- src/platform/macos/window.rs | 11 +++++++---- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f9b63fe8..c998563b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ - `Icon::to_cardinals` is no longer public, since it was never supposed to be. - Wayland: improve diagnostics if initialization fails +- Fix some system event key doesn't work when focused, do not block keyevent forward to system on macOS # Version 0.14.0 (2018-05-09) diff --git a/src/platform/macos/events_loop.rs b/src/platform/macos/events_loop.rs index 66217930..01ffb564 100644 --- a/src/platform/macos/events_loop.rs +++ b/src/platform/macos/events_loop.rs @@ -294,10 +294,7 @@ impl EventsLoop { // FIXME: Document this. Why do we do this? Seems like it passes on events to window/app. // If we don't do this, window does not become main for some reason. - match event_type { - appkit::NSKeyDown => (), - _ => appkit::NSApp().sendEvent_(ns_event), - } + appkit::NSApp().sendEvent_(ns_event); let windows = self.shared.windows.lock().unwrap(); let maybe_window = windows.iter() diff --git a/src/platform/macos/window.rs b/src/platform/macos/window.rs index 4163cf19..1a1c168e 100644 --- a/src/platform/macos/window.rs +++ b/src/platform/macos/window.rs @@ -415,13 +415,13 @@ impl WindowDelegate { // callbacks for drag and drop events decl.add_method(sel!(draggingEntered:), dragging_entered as extern fn(&Object, Sel, id) -> BOOL); - decl.add_method(sel!(prepareForDragOperation:), + decl.add_method(sel!(prepareForDragOperation:), prepare_for_drag_operation as extern fn(&Object, Sel, id)); - decl.add_method(sel!(performDragOperation:), + decl.add_method(sel!(performDragOperation:), perform_drag_operation as extern fn(&Object, Sel, id) -> BOOL); - decl.add_method(sel!(concludeDragOperation:), + decl.add_method(sel!(concludeDragOperation:), conclude_drag_operation as extern fn(&Object, Sel, id)); - decl.add_method(sel!(draggingExited:), + decl.add_method(sel!(draggingExited:), dragging_exited as extern fn(&Object, Sel, id)); // callbacks for fullscreen events @@ -686,10 +686,13 @@ impl Window2 { static INIT: std::sync::Once = std::sync::ONCE_INIT; INIT.call_once(|| unsafe { + extern fn on_key_down(_this: &Object, _sel: Sel, _id: id) {} + let window_superclass = Class::get("NSWindow").unwrap(); let mut decl = ClassDecl::new("WinitWindow", window_superclass).unwrap(); decl.add_method(sel!(canBecomeMainWindow), yes as extern fn(&Object, Sel) -> BOOL); decl.add_method(sel!(canBecomeKeyWindow), yes as extern fn(&Object, Sel) -> BOOL); + decl.add_method(sel!(keyDown:), on_key_down as extern fn(&Object, Sel, id)); WINDOW2_CLASS = decl.register(); });