Wayland: rework the event loop & expose readiness signal (#298)

* wayland: don't create a second event_queue

As each EventsLoop has its own context, this is no longer necessary.

* wayland: buffer events rather than direct dispatch

Changes the behavior of the event loop to first internally
buffer the events generated by the wayland handlers, and then
dispatch them to the client's closure.

- It simplifies the event loop logic
- It makes it possible for the user to call window methods such as
  `set_title()` or `set_inner_size()` without causing a deadlock

* wayland: add is_ready() & fix protocol errors

Adds a `is_ready()` method to the windows to advertize
when it is legal to start drawing, and fix a few wayland
protocol mishandling in the process.
This commit is contained in:
Victor Berger 2017-09-27 16:31:46 +02:00 committed by tomaka
parent df7e349c70
commit 515595153d
6 changed files with 130 additions and 141 deletions

View file

@ -112,6 +112,17 @@ pub trait WindowExt {
///
/// The pointer will become invalid when the glutin `Window` is destroyed.
fn get_wayland_display(&self) -> Option<*mut libc::c_void>;
/// Check if the window is ready for drawing
///
/// On wayland, drawing on a surface before the server has configured
/// it using a special event is illegal. As a result, you should wait
/// until this method returns `true`.
///
/// Once it starts returning `true`, it can never return `false` again.
///
/// If the window is X11-based, this will just always return `true`.
fn is_ready(&self) -> bool;
}
impl WindowExt for Window {
@ -175,6 +186,14 @@ impl WindowExt for Window {
_ => None
}
}
#[inline]
fn is_ready(&self) -> bool {
match self.window {
LinuxWindow::Wayland(ref w) => w.is_ready(),
LinuxWindow::X(_) => true
}
}
}
/// Additional methods on `WindowBuilder` that are specific to Unix.