fix: EventQueue::dispatch blocks until some events are available (#265)

use non blocking alternative as documented in EventQueue
This commit is contained in:
vemoo 2021-12-06 12:11:50 +01:00 committed by GitHub
parent 08dcf752af
commit e0992261c9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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