diff options
| author | Robert Knight <robert.knight@mendeley.com> | 2015-07-13 07:26:07 +0100 | 
|---|---|---|
| committer | Robert Knight <robert.knight@mendeley.com> | 2015-07-13 07:26:07 +0100 | 
| commit | d960753360fdc70e94ce2633db1e03d5ddc7b657 (patch) | |
| tree | 16a6825c8db2d8deed12efb654417d596db0b092 /src/api | |
| parent | b1223bc0413b8129fa64336ba73ad85ac9eb2d2c (diff) | |
| download | glutin-d960753360fdc70e94ce2633db1e03d5ddc7b657.tar.gz glutin-d960753360fdc70e94ce2633db1e03d5ddc7b657.zip | |
Address code review feedback
 * Fix an issue where PollEventsIterator::next() would fail to return
   keyboard input and mouse events immediately but instead only
   return them on the next call to next()
 * Inline process_generic_event() and queue_event()
Diffstat (limited to 'src/api')
| -rw-r--r-- | src/api/x11/window.rs | 55 | 
1 files changed, 24 insertions, 31 deletions
| diff --git a/src/api/x11/window.rs b/src/api/x11/window.rs index 9a01e17..b13a94a 100644 --- a/src/api/x11/window.rs +++ b/src/api/x11/window.rs @@ -143,42 +143,17 @@ pub struct PollEventsIterator<'a> {      window: &'a Window  } -impl<'a> PollEventsIterator<'a> { -    fn queue_event(&mut self, event: Event) { -        self.window.pending_events.lock().unwrap().push_back(event); -    } - -    fn process_generic_event(&mut self, event: &ffi::XEvent) { -        if let Some(cookie) = GenericEventCookie::from_event(self.window.x.display.borrow(), *event) { -            match cookie.cookie.evtype { -                ffi::XI_DeviceChanged...ffi::XI_LASTEVENT => { -                    match self.window.input_handler.lock() { -                        Ok(mut handler) => { -                            match handler.translate_event(&cookie.cookie) { -                                Some(event) => self.queue_event(event), -                                None => {} -                            } -                        }, -                        Err(_) => {} -                    } -                }, -                _ => {} -            } -        } -    } -} -  impl<'a> Iterator for PollEventsIterator<'a> {      type Item = Event;      fn next(&mut self) -> Option<Event> { -        if let Some(ev) = self.window.pending_events.lock().unwrap().pop_front() { -            return Some(ev); -        } -          let xlib = &self.window.x.display.xlib;          loop { +            if let Some(ev) = self.window.pending_events.lock().unwrap().pop_front() { +                return Some(ev); +            } +              let mut xev = unsafe { mem::uninitialized() };              let res = unsafe { (xlib.XCheckMaskEvent)(self.window.x.display.display, -1, &mut xev) }; @@ -231,10 +206,28 @@ impl<'a> Iterator for PollEventsIterator<'a> {                      let mut event: &mut ffi::XKeyEvent = unsafe { mem::transmute(&mut xev) };                      let events = self.window.input_handler.lock().unwrap().translate_key_event(&mut event);                      for event in events { -                        self.queue_event(event); +                        self.window.pending_events.lock().unwrap().push_back(event);                      }                  }, -                ffi::GenericEvent => { self.process_generic_event(&mut xev); } + +                ffi::GenericEvent => { +                    if let Some(cookie) = GenericEventCookie::from_event(self.window.x.display.borrow(), xev) { +                        match cookie.cookie.evtype { +                            ffi::XI_DeviceChanged...ffi::XI_LASTEVENT => { +                                match self.window.input_handler.lock() { +                                    Ok(mut handler) => { +                                        match handler.translate_event(&cookie.cookie) { +                                            Some(event) => self.window.pending_events.lock().unwrap().push_back(event), +                                            None => {} +                                        } +                                    }, +                                    Err(_) => {} +                                } +                            }, +                            _ => {} +                        } +                    } +                }                  _ => {}              }; | 
