diff --git a/src/api_transition.rs b/src/api_transition.rs index 231ee64a..48968376 100644 --- a/src/api_transition.rs +++ b/src/api_transition.rs @@ -21,13 +21,25 @@ macro_rules! gen_api_transition { pub fn poll_events(&self, mut callback: F) where F: FnMut(::Event) { - unimplemented!() + let mut windows = self.windows.lock().unwrap(); + for window in windows.iter() { + for event in window.poll_events() { + callback(::Event::WindowEvent { + window_id: &**window as *const Window as usize, + event: event, + }) + } + } } pub fn run_forever(&self, mut callback: F) where F: FnMut(::Event) { - unimplemented!() + // Yeah that's a very bad implementation. + loop { + self.poll_events(|e| callback(e)); + ::std::thread::sleep_ms(5); + } } } diff --git a/src/events.rs b/src/events.rs index 520a6c8a..4e664120 100644 --- a/src/events.rs +++ b/src/events.rs @@ -3,7 +3,7 @@ use std::path::PathBuf; #[derive(Clone, Debug)] pub enum Event { WindowEvent { - // window_id: , + window_id: usize, event: WindowEvent, } } diff --git a/src/window.rs b/src/window.rs index 96a5cd80..49ba7a31 100644 --- a/src/window.rs +++ b/src/window.rs @@ -318,6 +318,11 @@ impl Window { pub fn set_cursor_state(&self, state: CursorState) -> Result<(), String> { self.window.set_cursor_state(state) } + + #[inline] + pub fn id(&self) -> usize { + self.window.id() + } } /// Represents a thread safe subset of operations that can be called