diff options
author | Kirill Chibisov <wchibisovkirill@gmail.com> | 2019-06-26 00:34:55 +0300 |
---|---|---|
committer | Christian Duerr <chrisduerr@users.noreply.github.com> | 2019-06-25 21:34:55 +0000 |
commit | 0815774cbfb9d1421b8077d5d9d641faf5f818c1 (patch) | |
tree | 218a7177650ef8fa92b6c1936de73a32d3396628 /alacritty_terminal/src | |
parent | e2e25b3206ec6c99592ef9ee829426cad62e4d29 (diff) | |
download | alacritty-0815774cbfb9d1421b8077d5d9d641faf5f818c1.tar.gz alacritty-0815774cbfb9d1421b8077d5d9d641faf5f818c1.zip |
Perform clear and buffer swap before showing window
This should fill window with background color while it is offscreen instead of
showing it with uninitilized surface and then performing `clear`. So, the new
behavior should prevent glitches during startup. e.g. content of the windows
below, garbage from drivers and so on.
Diffstat (limited to 'alacritty_terminal/src')
-rw-r--r-- | alacritty_terminal/src/display.rs | 26 | ||||
-rw-r--r-- | alacritty_terminal/src/window.rs | 53 |
2 files changed, 46 insertions, 33 deletions
diff --git a/alacritty_terminal/src/display.rs b/alacritty_terminal/src/display.rs index 081625ac..4a2e57c4 100644 --- a/alacritty_terminal/src/display.rs +++ b/alacritty_terminal/src/display.rs @@ -224,6 +224,32 @@ impl Display { api.clear(background_color); }); + // We should call `clear` when window is offscreen, so when `window.show()` happens it + // would be with background color instead of uninitialized surface. + window.swap_buffers()?; + + window.show(); + + // Set window position + // + // TODO: replace `set_position` with `with_position` once available + // Upstream issue: https://github.com/tomaka/winit/issues/806 + if let Some(position) = config.window.position { + let physical = PhysicalPosition::from((position.x, position.y)); + let logical = physical.to_logical(window.hidpi_factor()); + window.set_position(logical); + } + + #[allow(clippy::single_match)] + match config.window.startup_mode() { + StartupMode::Fullscreen => window.set_fullscreen(true), + #[cfg(target_os = "macos")] + StartupMode::SimpleFullscreen => window.set_simple_fullscreen(true), + #[cfg(not(any(target_os = "macos", windows)))] + StartupMode::Maximized if window.is_x11() => window.set_maximized(true), + _ => (), + } + Ok(Display { window, renderer, diff --git a/alacritty_terminal/src/window.rs b/alacritty_terminal/src/window.rs index 186d3c12..f7eb16c1 100644 --- a/alacritty_terminal/src/window.rs +++ b/alacritty_terminal/src/window.rs @@ -17,7 +17,7 @@ use std::ffi::c_void; use std::fmt::Display; use crate::gl; -use glutin::dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize}; +use glutin::dpi::{LogicalPosition, LogicalSize, PhysicalSize}; #[cfg(target_os = "macos")] use glutin::os::macos::WindowExt; #[cfg(not(any(target_os = "macos", windows)))] @@ -158,38 +158,6 @@ impl Window { create_gl_window(window_builder.clone(), &event_loop, false, dimensions) .or_else(|_| create_gl_window(window_builder, &event_loop, true, dimensions))?; let window = windowed_context.window(); - window.show(); - - // Maximize window after mapping in X11 - #[cfg(not(any(target_os = "macos", windows)))] - { - if event_loop.is_x11() && config.window.startup_mode() == StartupMode::Maximized { - window.set_maximized(true); - } - } - - // Set window position - // - // TODO: replace `set_position` with `with_position` once available - // Upstream issue: https://github.com/tomaka/winit/issues/806 - if let Some(position) = config.window.position { - let physical = PhysicalPosition::from((position.x, position.y)); - let logical = physical.to_logical(window.get_hidpi_factor()); - window.set_position(logical); - } - - if let StartupMode::Fullscreen = config.window.startup_mode() { - let current_monitor = window.get_current_monitor(); - window.set_fullscreen(Some(current_monitor)); - } - - #[cfg(target_os = "macos")] - { - if let StartupMode::SimpleFullscreen = config.window.startup_mode() { - use glutin::os::macos::WindowExt; - window.set_simple_fullscreen(true); - } - } // Text cursor window.set_cursor(MouseCursor::Text); @@ -250,6 +218,12 @@ impl Window { self.windowed_context.resize(size); } + /// Show window + #[inline] + pub fn show(&self) { + self.window().show(); + } + /// Block waiting for events #[inline] pub fn wait_events<F>(&mut self, func: F) @@ -379,6 +353,10 @@ impl Window { self.window().set_ime_spot(pos); } + pub fn set_position(&self, pos: LogicalPosition) { + self.window().set_position(pos); + } + #[cfg(not(any(target_os = "macos", target_os = "windows")))] pub fn get_window_id(&self) -> Option<usize> { match self.window().get_xlib_window() { @@ -387,6 +365,11 @@ impl Window { } } + #[cfg(not(any(target_os = "macos", target_os = "windows")))] + pub fn is_x11(&self) -> bool { + self.event_loop.is_x11() + } + #[cfg(any(target_os = "macos", target_os = "windows"))] pub fn get_window_id(&self) -> Option<usize> { None @@ -408,6 +391,10 @@ impl Window { } } + pub fn set_maximized(&self, maximized: bool) { + self.window().set_maximized(maximized); + } + #[cfg(target_os = "macos")] pub fn set_simple_fullscreen(&self, fullscreen: bool) { use glutin::os::macos::WindowExt; |