From e17d38167e174a2cf664e430fe968ec6492e1f08 Mon Sep 17 00:00:00 2001 From: Victor Berger Date: Fri, 6 Oct 2017 17:47:51 +0200 Subject: Update glutin & fix a few wayland issues (#815) This PR fixes a few wayland issues of alacritty (and updates glutin on the process because it is needed). Mainly two changes are done: 1. Add a drawing_ready() method on Window: see https://docs.rs/winit/0.8.2/winit/os/unix/trait.WindowExt.html#tymethod.is_ready for explanations. Hopefully glutin will be able to handle it itself in the future, but it currently does not. 2. resize window and OpenGL contextes. The way wayland forces winit to draw its own decorations and how surface size is defined by its content means that in practice: - winit's window.set_inner_size() defines the dimensions of the borders - glutins gl_window.resize() defines the dimensions of the content (and is a noop in other platforms) It is for now glutin's user responsibility to keep them in sync otherwise borders are drawn stupidly. This PR changes the resize methods of alacritty::Window to always update both. This fixed the borders issues for me, tested on weston. --- src/event.rs | 3 +++ src/main.rs | 2 +- src/window.rs | 20 ++++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/event.rs b/src/event.rs index 95685001..6ec8415a 100644 --- a/src/event.rs +++ b/src/event.rs @@ -327,6 +327,9 @@ impl Processor { }, Event::Awakened => { processor.ctx.terminal.dirty = true; + }, + Event::Suspended(_) => { + // Only relevant on mobile devices } } } diff --git a/src/main.rs b/src/main.rs index ec327009..ee774094 100644 --- a/src/main.rs +++ b/src/main.rs @@ -181,7 +181,7 @@ fn run(mut config: Config, options: cli::Options) -> Result<(), Box> { }); // Maybe draw the terminal - if terminal.needs_draw() { + if terminal.needs_draw() && display.window().drawing_ready() { // Try to update the position of the input method editor display.update_ime_position(&terminal); // Handle pending resize events diff --git a/src/window.rs b/src/window.rs index f24def3a..a99b1437 100644 --- a/src/window.rs +++ b/src/window.rs @@ -256,6 +256,9 @@ impl Window { #[inline] pub fn resize(&self, width: u32, height: u32) { + // resize the window + self.window.set_inner_size(width, height); + // resize the gl context (needed on some platforms) self.window.resize(width, height); } @@ -331,6 +334,20 @@ impl Window { pub fn get_window_id(&self) -> Option { None } + + #[cfg(any(target_os = "linux", target_os = "freebsd", target_os="dragonfly", target_os="openbsd"))] + #[inline] + pub fn drawing_ready(&self) -> bool { + // needed for wayland support while glutin does not manage it itself + use glutin::os::unix::WindowExt; + self.window.is_ready() + } + + #[cfg(not(any(target_os = "linux", target_os = "freebsd", target_os="dragonfly", target_os="openbsd")))] + #[inline] + pub fn drawing_ready(&self) -> bool { + true + } } pub trait OsExtensions { @@ -394,6 +411,9 @@ pub trait SetInnerSize { impl SetInnerSize> for Window { fn set_inner_size(&mut self, size: &T) { let size = size.to_points(self.hidpi_factor()); + // resize the window self.window.set_inner_size(*size.width as _, *size.height as _); + // resize the gl context (needed on some platforms) + self.window.resize(*size.width as _, *size.height as _); } } -- cgit