diff --git a/CHANGELOG.md b/CHANGELOG.md index 71eab13d..c18e3865 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Unreleased +- On macOS, fix `` so applications receive the event. +- On macOS, fix `` so applications receive the event. + # Version 0.17.1 (2018-08-05) - On X11, prevent a compilation failure in release mode for versions of Rust greater than or equal to 1.30. diff --git a/src/platform/macos/events_loop.rs b/src/platform/macos/events_loop.rs index 3c893cdd..edc2923c 100644 --- a/src/platform/macos/events_loop.rs +++ b/src/platform/macos/events_loop.rs @@ -315,6 +315,27 @@ impl EventsLoop { }); match event_type { + // https://github.com/glfw/glfw/blob/50eccd298a2bbc272b4977bd162d3e4b55f15394/src/cocoa_window.m#L881 + appkit::NSKeyUp => { + if let Some(key_window) = maybe_key_window() { + if event_mods(ns_event).logo { + let _: () = msg_send![*key_window.window, sendEvent:ns_event]; + } + } + None + }, + // similar to above, but for ``, the keyDown is suppressed instead of the + // KeyUp, and the above trick does not appear to work. + appkit::NSKeyDown => { + let modifiers = event_mods(ns_event); + let keycode = NSEvent::keyCode(ns_event); + if modifiers.logo && keycode == 47 { + modifier_event(ns_event, NSEventModifierFlags::NSCommandKeyMask, false) + .map(into_event) + } else { + None + } + }, appkit::NSFlagsChanged => { let mut events = std::collections::VecDeque::new(); diff --git a/src/platform/macos/view.rs b/src/platform/macos/view.rs index 5a4b54d6..f042e88e 100644 --- a/src/platform/macos/view.rs +++ b/src/platform/macos/view.rs @@ -11,7 +11,7 @@ use cocoa::base::{id, nil}; use cocoa::appkit::{NSEvent, NSView, NSWindow}; use cocoa::foundation::{NSPoint, NSRect, NSSize, NSString, NSUInteger}; use objc::declare::ClassDecl; -use objc::runtime::{Class, Object, Protocol, Sel, BOOL}; +use objc::runtime::{Class, Object, Protocol, Sel, BOOL, YES}; use {ElementState, Event, KeyboardInput, MouseButton, WindowEvent, WindowId}; use platform::platform::events_loop::{DEVICE_ID, event_mods, Shared, to_virtual_key_code}; @@ -122,6 +122,7 @@ lazy_static! { decl.add_method(sel!(mouseDragged:), mouse_dragged as extern fn(&Object, Sel, id)); decl.add_method(sel!(rightMouseDragged:), right_mouse_dragged as extern fn(&Object, Sel, id)); decl.add_method(sel!(otherMouseDragged:), other_mouse_dragged as extern fn(&Object, Sel, id)); + decl.add_method(sel!(_wantsKeyDownForEvent:), wants_key_down_for_event as extern fn(&Object, Sel, id) -> BOOL); decl.add_ivar::<*mut c_void>("winitState"); decl.add_ivar::("markedText"); let protocol = Protocol::get("NSTextInputClient").unwrap(); @@ -566,3 +567,8 @@ extern fn right_mouse_dragged(this: &Object, _sel: Sel, event: id) { extern fn other_mouse_dragged(this: &Object, _sel: Sel, event: id) { mouse_motion(this, event); } + +// https://github.com/chromium/chromium/blob/a86a8a6bcfa438fa3ac2eba6f02b3ad1f8e0756f/ui/views/cocoa/bridged_content_view.mm#L816 +extern fn wants_key_down_for_event(_this: &Object, _se: Sel, _event: id) -> BOOL { + YES +}