From 0fcdd1f6e7965811a92fa384c07ee3a8fdd3fe02 Mon Sep 17 00:00:00 2001 From: Jason Mobarak Date: Wed, 11 May 2022 14:15:23 -0700 Subject: [PATCH] remove window flicker [CPP-744] [CPP-752] (#560) * remove window flicker + Hides the winit window, otherwise on windows you see this window briefly pop-up then disappear before the splash screen shows up + Falls back to 20,20 as the position if a monitor can't be fetched instead of erroring out * try other things to make sure the initial window doesn't show up * attempt to make positioning of splash on wayland work * remove println * disable wayland to center the splash screen * remove resize, reduce code * reorder * Increase init size to 1x1. Co-authored-by: John Michael Burke --- Cargo.lock | 6 ------ entrypoint/Cargo.toml | 2 ++ entrypoint/src/splash.rs | 41 +++++++++++++++++++++++++++++----------- 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3aa4e10d9..0d5e299df 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1419,21 +1419,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9e21c5f89bb820c7878c300c5b944e65de0f1b2a75e0be92ce670b95943740e" dependencies = [ "cc", - "dlib", "futures", "instant", "js-sys", - "lazy_static", "libc", "orbclient", "raw-window-handle 0.4.3", "serde", "serde_derive", - "tempfile", "wasm-bindgen-futures", - "wayland-client", - "wayland-cursor", - "wayland-protocols", "winapi", "x11-dl", ] diff --git a/entrypoint/Cargo.toml b/entrypoint/Cargo.toml index 49f7881cf..cc66a1093 100644 --- a/entrypoint/Cargo.toml +++ b/entrypoint/Cargo.toml @@ -35,6 +35,8 @@ version = "0.24.2" [dependencies.minifb] optional = true +default-features = false +features = ["x11"] version = "0.23" [dependencies.pyo3] diff --git a/entrypoint/src/splash.rs b/entrypoint/src/splash.rs index eab914909..033d2e6b4 100644 --- a/entrypoint/src/splash.rs +++ b/entrypoint/src/splash.rs @@ -8,7 +8,6 @@ use std::{ use lazy_static::lazy_static; use minifb::{Window, WindowOptions}; -use winit::{event_loop::EventLoop, window::Window as WinitWindow}; use entrypoint::attach_console; @@ -37,7 +36,9 @@ fn create_temp_file() -> Result { } fn launch_splash() -> Result<()> { + // Attach to console in windows so logs go somewhere attach_console(); + let logo = include_bytes!("../../resources/images/splash.jpg"); let image = image::io::Reader::with_format( std::io::BufReader::new(Cursor::new(logo)), @@ -49,18 +50,36 @@ fn launch_splash() -> Result<()> { .chunks(3) .map(|v| rgb8_3_to_rgb32(v[0], v[1], v[2])) .collect(); - let current_monitor = WinitWindow::new(&EventLoop::new())? - .current_monitor() - .ok_or_else(|| Into::::into(String::from("could not get current monitor")))?; - let size = current_monitor.size(); - let (width, height) = if cfg!(target_os = "macos") { - let size = size.to_logical::(current_monitor.scale_factor()); - (size.width, size.height) + + let monitor = { + let init_pos = winit::dpi::Position::Logical(winit::dpi::LogicalPosition::new(0.0, 0.0)); + let init_size = winit::dpi::Size::Logical(winit::dpi::LogicalSize::new(1.0, 1.0)); + let event_loop = winit::event_loop::EventLoop::new(); + winit::window::WindowBuilder::new() + .with_visible(false) + .with_decorations(false) + .with_inner_size(init_size) + .with_position(init_pos) + .build(&event_loop)? + .current_monitor() + .or(event_loop.primary_monitor()) + .or(event_loop.available_monitors().take(1).next()) + }; + + let (pos_x, pos_y) = if let Some(monitor) = monitor { + let size = monitor.size(); + let (width, height) = if cfg!(target_os = "macos") { + let size = size.to_logical::(monitor.scale_factor()); + (size.width, size.height) + } else { + (size.width as f64, size.height as f64) + }; + let pos_x = ((width - image.width() as f64) / 2.0) as isize; + let pos_y = ((height - image.height() as f64) / 2.0) as isize; + (pos_x, pos_y) } else { - (size.width as f64, size.height as f64) + (20, 20) }; - let pos_x = ((width - image.width() as f64) / 2.0) as isize; - let pos_y = ((height - image.height() as f64) / 2.0) as isize; let mut window = Window::new( "",