aboutsummaryrefslogtreecommitdiffstats
path: root/src/win32/mod.rs
diff options
context:
space:
mode:
authorTomaka17 <pierre.krieger1708@gmail.com>2014-07-31 20:55:30 +0200
committerTomaka17 <pierre.krieger1708@gmail.com>2014-07-31 20:55:30 +0200
commitfd203468296b0eea7f299a82a6eec2a238a5c952 (patch)
tree875c85872daad1cacb4d19f1ad6f0950a5bbf18d /src/win32/mod.rs
parent91b0eeae8d4e5eff9d581dd202a59afc7b23a1a1 (diff)
downloadglutin-fd203468296b0eea7f299a82a6eec2a238a5c952.tar.gz
glutin-fd203468296b0eea7f299a82a6eec2a238a5c952.zip
Put GetMessage in the same thread as the window creation.
Fixes #6
Diffstat (limited to 'src/win32/mod.rs')
-rw-r--r--src/win32/mod.rs32
1 files changed, 10 insertions, 22 deletions
diff --git a/src/win32/mod.rs b/src/win32/mod.rs
index 94c1590..9d8723d 100644
--- a/src/win32/mod.rs
+++ b/src/win32/mod.rs
@@ -1,10 +1,8 @@
-use std::kinds::marker::NoSend;
use std::sync::atomics::AtomicBool;
use std::ptr;
use {Event, Hints};
pub use self::monitor::{MonitorID, get_available_monitors, get_primary_monitor};
-pub use self::init::WINDOWS_LIST;
mod event;
mod ffi;
@@ -18,7 +16,6 @@ pub struct Window {
gl_library: ffi::HMODULE,
events_receiver: Receiver<Event>,
is_closed: AtomicBool,
- nosend: NoSend,
}
impl Window {
@@ -106,19 +103,6 @@ impl Window {
// TODO: return iterator
pub fn poll_events(&self) -> Vec<Event> {
- use std::mem;
-
- loop {
- let mut msg = unsafe { mem::uninitialized() };
-
- if unsafe { ffi::PeekMessageW(&mut msg, ptr::mut_null(), 0, 0, 0x1) } == 0 {
- break
- }
-
- unsafe { ffi::TranslateMessage(&msg) };
- unsafe { ffi::DispatchMessageW(&msg) };
- }
-
let mut events = Vec::new();
loop {
match self.events_receiver.try_recv() {
@@ -137,12 +121,16 @@ impl Window {
// TODO: return iterator
pub fn wait_events(&self) -> Vec<Event> {
- loop {
- unsafe { ffi::WaitMessage() };
-
- let events = self.poll_events();
- if events.len() >= 1 {
- return events
+ match self.events_receiver.recv_opt() {
+ Ok(ev) => {
+ let mut result = self.poll_events();
+ result.insert(0, ev);
+ result
+ },
+ Err(_) => {
+ use std::sync::atomics::Relaxed;
+ self.is_closed.store(true, Relaxed);
+ vec![]
}
}
}