Fix key state on MacOS (#610)

This commit is contained in:
Paul Rouget 2018-07-26 01:36:33 +08:00 committed by Francesca Frangipane
parent 3910326709
commit 01cb8e59e3
2 changed files with 9 additions and 4 deletions

View file

@ -1,5 +1,6 @@
# Unreleased # Unreleased
- On MacOS, the key state for modifiers key events is now properly set.
- On iOS, the view is now set correctly. This makes it possible to render things (instead of being stuck on a black screen), and touch events work again. - On iOS, the view is now set correctly. This makes it possible to render things (instead of being stuck on a black screen), and touch events work again.
- Added NetBSD support. - Added NetBSD support.

View file

@ -674,11 +674,15 @@ pub fn event_mods(event: cocoa::base::id) -> ModifiersState {
unsafe fn modifier_event( unsafe fn modifier_event(
ns_event: cocoa::base::id, ns_event: cocoa::base::id,
keymask: NSEventModifierFlags, keymask: NSEventModifierFlags,
key_pressed: bool, was_key_pressed: bool,
) -> Option<WindowEvent> { ) -> Option<WindowEvent> {
if !key_pressed && NSEvent::modifierFlags(ns_event).contains(keymask) if !was_key_pressed && NSEvent::modifierFlags(ns_event).contains(keymask)
|| key_pressed && !NSEvent::modifierFlags(ns_event).contains(keymask) { || was_key_pressed && !NSEvent::modifierFlags(ns_event).contains(keymask) {
let state = ElementState::Released; let state = if was_key_pressed {
ElementState::Released
} else {
ElementState::Pressed
};
let keycode = NSEvent::keyCode(ns_event); let keycode = NSEvent::keyCode(ns_event);
let scancode = keycode as u32; let scancode = keycode as u32;
let virtual_keycode = to_virtual_key_code(keycode); let virtual_keycode = to_virtual_key_code(keycode);