aboutsummaryrefslogtreecommitdiffstats
path: root/src/win32
diff options
context:
space:
mode:
authorTomaka17 <pierre.krieger1708@gmail.com>2014-07-27 19:58:27 +0200
committerTomaka17 <pierre.krieger1708@gmail.com>2014-07-27 19:58:27 +0200
commit1e615b59a6e9685ec283b290eb337faab888f262 (patch)
treea397bd18f32500f5602d52595c341f79b8297fd1 /src/win32
parent7a8e7a792272fd0d6775db1f8efe196406a50438 (diff)
downloadglutin-1e615b59a6e9685ec283b290eb337faab888f262.tar.gz
glutin-1e615b59a6e9685ec283b290eb337faab888f262.zip
Better events handling for win32
Diffstat (limited to 'src/win32')
-rw-r--r--src/win32/ffi.rs3
-rw-r--r--src/win32/mod.rs39
2 files changed, 11 insertions, 31 deletions
diff --git a/src/win32/ffi.rs b/src/win32/ffi.rs
index 0b47de8..96f09d4 100644
--- a/src/win32/ffi.rs
+++ b/src/win32/ffi.rs
@@ -564,6 +564,9 @@ extern "system" {
// http://msdn.microsoft.com/en-us/library/dd145167(v=vs.85).aspx
pub fn UpdateWindow(hWnd: HWND) -> BOOL;
+ // http://msdn.microsoft.com/en-us/library/windows/desktop/ms644956(v=vs.85).aspx
+ pub fn WaitMessage() -> BOOL;
+
// http://msdn.microsoft.com/en-us/library/windows/desktop/dd374379(v=vs.85).aspx
pub fn wglCreateContext(hdc: HDC) -> HGLRC;
diff --git a/src/win32/mod.rs b/src/win32/mod.rs
index 959e141..be6014e 100644
--- a/src/win32/mod.rs
+++ b/src/win32/mod.rs
@@ -204,7 +204,7 @@ impl Window {
loop {
let mut msg = unsafe { mem::uninitialized() };
- if unsafe { ffi::PeekMessageW(&mut msg, ptr::mut_null(), 0, 0, 1) } == 0 {
+ if unsafe { ffi::PeekMessageW(&mut msg, ptr::mut_null(), 0, 0, 0x1) } == 0 {
break
}
@@ -219,38 +219,21 @@ impl Window {
Err(_) => break
}
}
+
+ if events.iter().find(|e| match e { &&::Closed => true, _ => false }).is_some() {
+ use std::sync::atomics::Relaxed;
+ self.should_close.store(true, Relaxed);
+ }
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::WaitMessage() };
- 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
- }
- }
-
+ let events = self.poll_events();
if events.len() >= 1 {
return events
}
@@ -316,12 +299,6 @@ extern "stdcall" fn callback(window: ffi::HWND, msg: ffi::UINT,
0
},
- ffi::WM_PAINT => {
- /*use NeedRefresh;
- send_event(window, NeedRefresh);*/
- 0
- },
-
ffi::WM_CHAR => {
use std::mem;
use events::ReceivedCharacter;