wayland: properly fetch new events with Window::poll_events()

This commit is contained in:
Victor Berger 2016-10-16 23:29:29 +02:00
parent 0663269482
commit 76f5613496
2 changed files with 13 additions and 4 deletions

View file

@ -39,7 +39,7 @@ kernel32-sys = "0.2"
dwmapi-sys = "0.1" dwmapi-sys = "0.1"
[target.'cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd"))'.dependencies] [target.'cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd"))'.dependencies]
wayland-client = { version = "0.7.3", features = ["dlopen"] } wayland-client = { version = "0.7.4", features = ["dlopen"] }
wayland-kbd = "0.6.2" wayland-kbd = "0.6.2"
wayland-window = "0.4.2" wayland-window = "0.4.2"
x11-dl = "2.8" x11-dl = "2.8"

View file

@ -134,11 +134,20 @@ impl Window {
}; };
if evt.is_some() { return evt } if evt.is_some() { return evt }
// There is no event in the queue, we need to fetch more
// flush the display
self.ctxt.flush();
// read some events if some are waiting & queue is empty
if let Some(guard) = self.evq.lock().unwrap().prepare_read() {
guard.read_events();
}
// try a pending dispatch // try a pending dispatch
// TODO: insert a non-blocking read from socket, overwise no new events will ever come
{ {
self.ctxt.dispatch_pending(); self.ctxt.dispatch_pending();
let mut guard = self.evq.lock().unwrap().dispatch_pending(); self.evq.lock().unwrap().dispatch_pending();
// some events were dispatched, need to process a potential resising // some events were dispatched, need to process a potential resising
self.process_resize(); self.process_resize();
} }
@ -153,7 +162,7 @@ impl Window {
{ {
self.ctxt.flush(); self.ctxt.flush();
self.ctxt.dispatch(); self.ctxt.dispatch();
let mut guard = self.evq.lock().unwrap().dispatch_pending(); self.evq.lock().unwrap().dispatch_pending();
// some events were dispatched, need to process a potential resising // some events were dispatched, need to process a potential resising
self.process_resize(); self.process_resize();
} }