mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2025-01-12 05:31:31 +11:00
Merge pull request #173 from jwilm/consistent-event-order-key-char
Make keyboard input event order consistent
This commit is contained in:
commit
8f9f2352cf
|
@ -228,6 +228,23 @@ impl EventsLoop {
|
||||||
|
|
||||||
let mut ev_mods = ModifiersState::default();
|
let mut ev_mods = ModifiersState::default();
|
||||||
|
|
||||||
|
let mut keysym = unsafe {
|
||||||
|
(self.display.xlib.XKeycodeToKeysym)(self.display.display, xkev.keycode as ffi::KeyCode, 0)
|
||||||
|
};
|
||||||
|
|
||||||
|
let vkey = events::keysym_to_element(keysym as libc::c_uint);
|
||||||
|
|
||||||
|
callback(Event::WindowEvent { window_id: wid, event: WindowEvent::KeyboardInput {
|
||||||
|
// Typical virtual core keyboard ID. xinput2 needs to be used to get a reliable value.
|
||||||
|
device_id: mkdid(3),
|
||||||
|
input: KeyboardInput {
|
||||||
|
state: state,
|
||||||
|
scancode: xkev.keycode,
|
||||||
|
virtual_keycode: vkey,
|
||||||
|
modifiers: ev_mods,
|
||||||
|
},
|
||||||
|
}});
|
||||||
|
|
||||||
if state == Pressed {
|
if state == Pressed {
|
||||||
let written = unsafe {
|
let written = unsafe {
|
||||||
use std::str;
|
use std::str;
|
||||||
|
@ -267,23 +284,6 @@ impl EventsLoop {
|
||||||
callback(Event::WindowEvent { window_id: wid, event: WindowEvent::ReceivedCharacter(chr) })
|
callback(Event::WindowEvent { window_id: wid, event: WindowEvent::ReceivedCharacter(chr) })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut keysym = unsafe {
|
|
||||||
(self.display.xlib.XKeycodeToKeysym)(self.display.display, xkev.keycode as ffi::KeyCode, 0)
|
|
||||||
};
|
|
||||||
|
|
||||||
let vkey = events::keysym_to_element(keysym as libc::c_uint);
|
|
||||||
|
|
||||||
callback(Event::WindowEvent { window_id: wid, event: WindowEvent::KeyboardInput {
|
|
||||||
// Typical virtual core keyboard ID. xinput2 needs to be used to get a reliable value.
|
|
||||||
device_id: mkdid(3),
|
|
||||||
input: KeyboardInput {
|
|
||||||
state: state,
|
|
||||||
scancode: xkev.keycode,
|
|
||||||
virtual_keycode: vkey,
|
|
||||||
modifiers: ev_mods,
|
|
||||||
},
|
|
||||||
}});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ffi::GenericEvent => {
|
ffi::GenericEvent => {
|
||||||
|
|
|
@ -309,10 +309,6 @@ impl EventsLoop {
|
||||||
let mut events = std::collections::VecDeque::new();
|
let mut events = std::collections::VecDeque::new();
|
||||||
let received_c_str = foundation::NSString::UTF8String(ns_event.characters());
|
let received_c_str = foundation::NSString::UTF8String(ns_event.characters());
|
||||||
let received_str = std::ffi::CStr::from_ptr(received_c_str);
|
let received_str = std::ffi::CStr::from_ptr(received_c_str);
|
||||||
for received_char in std::str::from_utf8(received_str.to_bytes()).unwrap().chars() {
|
|
||||||
let window_event = WindowEvent::ReceivedCharacter(received_char);
|
|
||||||
events.push_back(into_event(window_event));
|
|
||||||
}
|
|
||||||
|
|
||||||
let vkey = to_virtual_key_code(NSEvent::keyCode(ns_event));
|
let vkey = to_virtual_key_code(NSEvent::keyCode(ns_event));
|
||||||
let state = ElementState::Pressed;
|
let state = ElementState::Pressed;
|
||||||
|
@ -326,10 +322,12 @@ impl EventsLoop {
|
||||||
modifiers: event_mods(ns_event),
|
modifiers: event_mods(ns_event),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
for received_char in std::str::from_utf8(received_str.to_bytes()).unwrap().chars() {
|
||||||
|
let window_event = WindowEvent::ReceivedCharacter(received_char);
|
||||||
events.push_back(into_event(window_event));
|
events.push_back(into_event(window_event));
|
||||||
let event = events.pop_front();
|
}
|
||||||
self.pending_events.lock().unwrap().extend(events.into_iter());
|
self.pending_events.lock().unwrap().extend(events.into_iter());
|
||||||
event
|
Some(into_event(window_event))
|
||||||
},
|
},
|
||||||
|
|
||||||
appkit::NSKeyUp => {
|
appkit::NSKeyUp => {
|
||||||
|
|
Loading…
Reference in a new issue