diff options
author | Tomaka17 <pierre.krieger1708@gmail.com> | 2014-07-27 18:35:42 +0200 |
---|---|---|
committer | Tomaka17 <pierre.krieger1708@gmail.com> | 2014-07-27 18:35:42 +0200 |
commit | c67ab381bf024461793798be255c5351c47fb8b0 (patch) | |
tree | 1b1c5d6dc007068cd7010af4997001e299815de0 /src | |
parent | 24baf4d10405129d1631efe82ae2f7a0cf18132b (diff) | |
download | glutin-c67ab381bf024461793798be255c5351c47fb8b0.tar.gz glutin-c67ab381bf024461793798be255c5351c47fb8b0.zip |
Fix events handling on win32
Diffstat (limited to 'src')
-rw-r--r-- | src/win32/ffi.rs | 4 | ||||
-rw-r--r-- | src/win32/mod.rs | 52 |
2 files changed, 43 insertions, 13 deletions
diff --git a/src/win32/ffi.rs b/src/win32/ffi.rs index 63afef4..5051c46 100644 --- a/src/win32/ffi.rs +++ b/src/win32/ffi.rs @@ -381,6 +381,10 @@ extern "system" { // http://msdn.microsoft.com/en-us/library/windows/desktop/aa366730(v=vs.85).aspx pub fn LocalFree(hMem: HLOCAL) -> HLOCAL; + // http://msdn.microsoft.com/en-us/library/windows/desktop/ms644943(v=vs.85).aspx + pub fn PeekMessageW(lpMsg: *mut MSG, hWnd: HWND, wMsgFilterMin: UINT, wMsgFilterMax: UINT, + wRemoveMsg: UINT) -> BOOL; + // http://msdn.microsoft.com/en-us/library/windows/desktop/ms644945(v=vs.85).aspx pub fn PostQuitMessage(nExitCode: libc::c_int); diff --git a/src/win32/mod.rs b/src/win32/mod.rs index a1bda6f..a13aa74 100644 --- a/src/win32/mod.rs +++ b/src/win32/mod.rs @@ -198,22 +198,13 @@ impl Window { // TODO: return iterator pub fn poll_events(&self) -> Vec<Event> { - unimplemented!() - } - - // TODO: return iterator - pub fn wait_events(&self) -> Vec<Event> { use std::mem; - { + loop { let mut msg = unsafe { mem::uninitialized() }; - if unsafe { ffi::GetMessageW(&mut msg, ptr::mut_null(), 0, 0) } == 0 { - use std::sync::atomics::Relaxed; - use Closed; - - self.should_close.store(true, Relaxed); - return vec![Closed] + if unsafe { ffi::PeekMessageW(&mut msg, ptr::mut_null(), 0, 0, 1) } == 0 { + break } unsafe { ffi::TranslateMessage(&msg) }; @@ -227,9 +218,44 @@ impl Window { Err(_) => break } } + events } + // TODO: return iterator + pub fn wait_events(&self) -> Vec<Event> { + use std::mem; + + loop { + { + let mut msg = unsafe { mem::uninitialized() }; + + if unsafe { ffi::GetMessageW(&mut msg, ptr::mut_null(), 0, 0) } == 0 { + use std::sync::atomics::Relaxed; + use Closed; + + self.should_close.store(true, Relaxed); + return vec![Closed] + } + + unsafe { ffi::TranslateMessage(&msg) }; + unsafe { ffi::DispatchMessageW(&msg) }; + } + + let mut events = Vec::new(); + loop { + match self.events_receiver.try_recv() { + Ok(ev) => events.push(ev), + Err(_) => break + } + } + + if events.len() >= 1 { + return events + } + } + } + pub fn make_current(&self) { unsafe { ffi::wglMakeCurrent(self.hdc, self.context) } } @@ -276,8 +302,8 @@ extern "stdcall" fn callback(window: ffi::HWND, msg: ffi::UINT, match msg { ffi::WM_DESTROY => { use Closed; - send_event(window, Closed); unsafe { ffi::PostQuitMessage(0); } + send_event(window, Closed); 0 }, |