From 19b6a2f701379ba2ed5177a091c513d3d7e64a2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Frosteg=C3=A5rd?= Date: Sat, 5 Dec 2020 01:48:26 +0100 Subject: [PATCH] macOS: handle changed flags This enables catching pressed modifier keys with no other keys pressed --- src/macos/view.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/macos/view.rs b/src/macos/view.rs index 293fc04..74a132c 100644 --- a/src/macos/view.rs +++ b/src/macos/view.rs @@ -149,6 +149,10 @@ unsafe fn create_view_class() -> &'static Class { sel!(keyUp:), key_up:: as extern "C" fn(&Object, Sel, id), ); + class.add_method( + sel!(flagsChanged:), + flags_changed:: as extern "C" fn(&Object, Sel, id), + ); class.add_ivar::<*mut c_void>(WINDOW_STATE_IVAR_NAME); class.add_ivar::<*mut c_void>(FRAME_TIMER_IVAR_NAME); @@ -388,6 +392,17 @@ extern "C" fn key_up(this: &Object, _: Sel, event: id){ WindowState::from_field(this) }; + if let Some(key_event) = state.process_native_key_event(event){ + state.trigger_event(Event::Keyboard(key_event)); + } +} + + +extern "C" fn flags_changed(this: &Object, _: Sel, event: id){ + let state: &mut WindowState = unsafe { + WindowState::from_field(this) + }; + if let Some(key_event) = state.process_native_key_event(event){ state.trigger_event(Event::Keyboard(key_event)); }