diff --git a/src/os/posix/wayland.rs b/src/os/posix/wayland.rs index 811b329..6394134 100644 --- a/src/os/posix/wayland.rs +++ b/src/os/posix/wayland.rs @@ -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