Skip to content

Commit 0fcdd1f

Browse files
Jason Mobarakjohn-michaelburke
andauthored
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 <[email protected]>
1 parent 739367f commit 0fcdd1f

File tree

3 files changed

+32
-17
lines changed

3 files changed

+32
-17
lines changed

Cargo.lock

Lines changed: 0 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

entrypoint/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ version = "0.24.2"
3535

3636
[dependencies.minifb]
3737
optional = true
38+
default-features = false
39+
features = ["x11"]
3840
version = "0.23"
3941

4042
[dependencies.pyo3]

entrypoint/src/splash.rs

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use std::{
88

99
use lazy_static::lazy_static;
1010
use minifb::{Window, WindowOptions};
11-
use winit::{event_loop::EventLoop, window::Window as WinitWindow};
1211

1312
use entrypoint::attach_console;
1413

@@ -37,7 +36,9 @@ fn create_temp_file() -> Result<PathBuf> {
3736
}
3837

3938
fn launch_splash() -> Result<()> {
39+
// Attach to console in windows so logs go somewhere
4040
attach_console();
41+
4142
let logo = include_bytes!("../../resources/images/splash.jpg");
4243
let image = image::io::Reader::with_format(
4344
std::io::BufReader::new(Cursor::new(logo)),
@@ -49,18 +50,36 @@ fn launch_splash() -> Result<()> {
4950
.chunks(3)
5051
.map(|v| rgb8_3_to_rgb32(v[0], v[1], v[2]))
5152
.collect();
52-
let current_monitor = WinitWindow::new(&EventLoop::new())?
53-
.current_monitor()
54-
.ok_or_else(|| Into::<Error>::into(String::from("could not get current monitor")))?;
55-
let size = current_monitor.size();
56-
let (width, height) = if cfg!(target_os = "macos") {
57-
let size = size.to_logical::<f64>(current_monitor.scale_factor());
58-
(size.width, size.height)
53+
54+
let monitor = {
55+
let init_pos = winit::dpi::Position::Logical(winit::dpi::LogicalPosition::new(0.0, 0.0));
56+
let init_size = winit::dpi::Size::Logical(winit::dpi::LogicalSize::new(1.0, 1.0));
57+
let event_loop = winit::event_loop::EventLoop::new();
58+
winit::window::WindowBuilder::new()
59+
.with_visible(false)
60+
.with_decorations(false)
61+
.with_inner_size(init_size)
62+
.with_position(init_pos)
63+
.build(&event_loop)?
64+
.current_monitor()
65+
.or(event_loop.primary_monitor())
66+
.or(event_loop.available_monitors().take(1).next())
67+
};
68+
69+
let (pos_x, pos_y) = if let Some(monitor) = monitor {
70+
let size = monitor.size();
71+
let (width, height) = if cfg!(target_os = "macos") {
72+
let size = size.to_logical::<f64>(monitor.scale_factor());
73+
(size.width, size.height)
74+
} else {
75+
(size.width as f64, size.height as f64)
76+
};
77+
let pos_x = ((width - image.width() as f64) / 2.0) as isize;
78+
let pos_y = ((height - image.height() as f64) / 2.0) as isize;
79+
(pos_x, pos_y)
5980
} else {
60-
(size.width as f64, size.height as f64)
81+
(20, 20)
6182
};
62-
let pos_x = ((width - image.width() as f64) / 2.0) as isize;
63-
let pos_y = ((height - image.height() as f64) / 2.0) as isize;
6483

6584
let mut window = Window::new(
6685
"",

0 commit comments

Comments
 (0)