Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eframe: Don't show window until after initialization #2279

Merged
merged 9 commits into from
Nov 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions crates/eframe/src/native/epi_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ pub fn handle_app_output(
fullscreen,
drag_window,
window_pos,
visible,
visible: _, // handled in post_present
always_on_top,
} = app_output;

Expand Down Expand Up @@ -183,10 +183,6 @@ pub fn handle_app_output(
let _ = window.drag_window();
}

if let Some(visible) = visible {
window.set_visible(visible);
}

if let Some(always_on_top) = always_on_top {
window.set_always_on_top(always_on_top);
}
Expand Down Expand Up @@ -240,7 +236,10 @@ impl EpiIntegration {
native_pixels_per_point: Some(native_pixels_per_point),
window_info: read_window_info(window, egui_ctx.pixels_per_point()),
},
output: Default::default(),
output: epi::backend::AppOutput {
visible: Some(true),
..Default::default()
},
storage,
#[cfg(feature = "glow")]
gl,
Expand Down Expand Up @@ -325,6 +324,7 @@ impl EpiIntegration {
if app_output.close {
self.close = app.on_close_event();
}
self.frame.output.visible = app_output.visible; // this is handled by post_present
handle_app_output(window, self.egui_ctx.pixels_per_point(), app_output);
}

Expand All @@ -341,6 +341,12 @@ impl EpiIntegration {
app.post_rendering(window_size_px, &self.frame);
}

pub fn post_present(&mut self, window: &winit::window::Window) {
if let Some(visible) = self.frame.output.visible.take() {
window.set_visible(visible);
}
}

pub fn handle_platform_output(
&mut self,
window: &winit::window::Window,
Expand Down
9 changes: 7 additions & 2 deletions crates/eframe/src/native/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,9 @@ mod glow_integration {
};
let window_settings = epi_integration::load_window_settings(storage);

let window_builder =
epi_integration::window_builder(native_options, &window_settings).with_title(title);
let window_builder = epi_integration::window_builder(native_options, &window_settings)
.with_title(title)
.with_visible(false); // Keep hidden until we've painted something. See https://github.com/emilk/egui/pull/2279

let gl_window = unsafe {
glutin::ContextBuilder::new()
Expand Down Expand Up @@ -493,6 +494,8 @@ mod glow_integration {
gl_window.swap_buffers().unwrap();
}

integration.post_present(window);

let control_flow = if integration.should_close() {
EventResult::Exit
} else if repaint_after.is_zero() {
Expand Down Expand Up @@ -692,6 +695,7 @@ mod wgpu_integration {
let window_settings = epi_integration::load_window_settings(storage);
epi_integration::window_builder(native_options, &window_settings)
.with_title(title)
.with_visible(false) // Keep hidden until we've painted something. See https://github.com/emilk/egui/pull/2279
.build(event_loop)
.unwrap()
}
Expand Down Expand Up @@ -850,6 +854,7 @@ mod wgpu_integration {
);

integration.post_rendering(app.as_mut(), window);
integration.post_present(window);

let control_flow = if integration.should_close() {
EventResult::Exit
Expand Down