mirror of
https://github.com/italicsjenga/rust_minifb.git
synced 2024-12-23 11:21:30 +11:00
fix: EventQueue::dispatch blocks until some events are available (#265)
use non blocking alternative as documented in EventQueue
This commit is contained in:
parent
08dcf752af
commit
e0992261c9
|
@ -30,7 +30,7 @@ use xkb::keymap::Keymap;
|
|||
use std::cell::RefCell;
|
||||
use std::ffi::c_void;
|
||||
use std::fs::File;
|
||||
use std::io::{Read, Seek, SeekFrom, Write};
|
||||
use std::io::{self, Read, Seek, SeekFrom, Write};
|
||||
use std::mem;
|
||||
use std::os::unix::io::{AsRawFd, FromRawFd, RawFd};
|
||||
use std::rc::Rc;
|
||||
|
@ -709,12 +709,34 @@ impl Window {
|
|||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn update(&mut self) {
|
||||
fn try_dispatch_events(&mut self) {
|
||||
// as seen in https://docs.rs/wayland-client/0.28/wayland_client/struct.EventQueue.html
|
||||
if let Err(e) = self.display.event_queue.display().flush() {
|
||||
if e.kind() != io::ErrorKind::WouldBlock {
|
||||
eprintln!("Error while trying to flush the wayland socket: {:?}", e);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(guard) = self.display.event_queue.prepare_read() {
|
||||
if let Err(e) = guard.read_events() {
|
||||
if e.kind() != io::ErrorKind::WouldBlock {
|
||||
eprintln!(
|
||||
"Error while trying to read from the wayland socket: {:?}",
|
||||
e
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.display
|
||||
.event_queue
|
||||
.dispatch(&mut (), |_, _, _| {})
|
||||
.dispatch_pending(&mut (), |_, _, _| {})
|
||||
.map_err(|e| Error::WindowCreate(format!("Event dispatch failed: {:?}", e)))
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
pub fn update(&mut self) {
|
||||
self.try_dispatch_events();
|
||||
|
||||
if let Some(resize) = (*self.toplevel_info.0.borrow_mut()).take() {
|
||||
// Don't try to resize to 0x0
|
||||
|
|
Loading…
Reference in a new issue