Created
April 10, 2017 23:26
-
-
Save jdm/ba9eda842754ab95461ed1b0fcdaa0d3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/ports/glutin/window.rs b/ports/glutin/window.rs | |
index 102c014..4c5b01d 100644 | |
--- a/ports/glutin/window.rs | |
+++ b/ports/glutin/window.rs | |
@@ -192,6 +192,10 @@ pub struct Window { | |
/// the equivalent ReceivedCharacter data as was received for the press event. | |
pressed_key_map: RefCell<Vec<(ScanCode, char)>>, | |
+ /// The last KeyboardInput event that was received. Used to reorder the KeyboardInput | |
+ /// and ReceivedCharacter events on Windows. | |
+ buffered_key_input: RefCell<Option<Event>>, | |
+ | |
gl: Rc<gl::Gl>, | |
} | |
@@ -303,6 +307,7 @@ impl Window { | |
pending_key_event_char: Cell::new(None), | |
pressed_key_map: RefCell::new(vec![]), | |
+ buffered_key_input: RefCell::new(None), | |
gl: gl.clone(), | |
}; | |
@@ -344,14 +349,42 @@ impl Window { | |
GlRequest::Specific(Api::OpenGlEs, (3, 0)) | |
} | |
+ fn handle_buffered_key_event(&self) { | |
+ let buffered = self.buffered_key_input.borrow_mut().take(); | |
+ if let Some(event) = buffered { | |
+ self.handle_window_event(event); | |
+ } | |
+ } | |
+ | |
fn handle_window_event(&self, event: glutin::Event) -> bool { | |
+ if cfg!(target_os = "windows") { | |
+ match event { | |
+ // We will deal with the buffered key event as part of processing this event. | |
+ Event::ReceivedCharacter(..) => {} | |
+ // To maintain correct event ordering, we need to ensure the buffered event (if any) | |
+ // if processed before the current event. | |
+ _ => self.handle_buffered_key_event(), | |
+ } | |
+ | |
+ if let Event::KeyboardInput(..) = event { | |
+ // Store this event for later processing. | |
+ *self.buffered_key_input.borrow_mut() = Some(event); | |
+ return false; | |
+ } | |
+ } | |
+ | |
match event { | |
Event::ReceivedCharacter(ch) => { | |
if !ch.is_control() { | |
self.pending_key_event_char.set(Some(ch)); | |
} | |
+ | |
+ if cfg!(target_os = "windows") { | |
+ self.handle_buffered_key_event(); | |
+ } | |
} | |
Event::KeyboardInput(element_state, scan_code, Some(virtual_key_code)) => { | |
+ | |
match virtual_key_code { | |
VirtualKeyCode::LControl => self.toggle_modifier(LEFT_CONTROL), | |
VirtualKeyCode::RControl => self.toggle_modifier(RIGHT_CONTROL), |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment