Skip to content

Commit

Permalink
remove window flicker [CPP-744] [CPP-752] (#560)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
Jason Mobarak and john-michaelburke authored May 11, 2022
1 parent 739367f commit 0fcdd1f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
6 changes: 0 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions entrypoint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ version = "0.24.2"

[dependencies.minifb]
optional = true
default-features = false
features = ["x11"]
version = "0.23"

[dependencies.pyo3]
Expand Down
41 changes: 30 additions & 11 deletions entrypoint/src/splash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -37,7 +36,9 @@ fn create_temp_file() -> Result<PathBuf> {
}

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)),
Expand All @@ -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::<Error>::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::<f64>(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::<f64>(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(
"",
Expand Down

0 comments on commit 0fcdd1f

Please sign in to comment.