diff --git a/crates/eframe/src/native/epi_integration.rs b/crates/eframe/src/native/epi_integration.rs index 26c912ead23..9010dbd0efe 100644 --- a/crates/eframe/src/native/epi_integration.rs +++ b/crates/eframe/src/native/epi_integration.rs @@ -64,6 +64,7 @@ pub fn read_window_info( monitor_size, } } + pub fn window_builder( event_loop: &EventLoopWindowTarget, title: &str, @@ -159,23 +160,17 @@ pub fn window_builder( } window_builder } -pub fn build_window( - event_loop: &EventLoopWindowTarget, - title: &str, - native_options: &epi::NativeOptions, - window_settings: Option, -) -> Result { - let window_builder = window_builder(event_loop, title, native_options, window_settings); - let window = window_builder.build(event_loop)?; +pub fn apply_native_options_to_window( + window: &winit::window::Window, + native_options: &crate::NativeOptions, +) { use winit::window::WindowLevel; window.set_window_level(if native_options.always_on_top { WindowLevel::AlwaysOnTop } else { WindowLevel::Normal }); - - Ok(window) } fn largest_monitor_point_size(event_loop: &EventLoopWindowTarget) -> egui::Vec2 { diff --git a/crates/eframe/src/native/run.rs b/crates/eframe/src/native/run.rs index 933a193ef76..87b66fd671d 100644 --- a/crates/eframe/src/native/run.rs +++ b/crates/eframe/src/native/run.rs @@ -457,6 +457,7 @@ mod glow_integration { } }; let not_current_gl_context = Some(gl_context); + // the fun part with opengl gl is that we never know whether there is an error. the context creation might have failed, but // it could keep working until we try to make surface current or swap buffers or something else. future glutin improvements might // help us start from scratch again if we fail context creation and go back to preferEgl or try with different config etc.. @@ -471,6 +472,7 @@ mod glow_integration { not_current_gl_context, }) } + /// This will be run after `new`. on android, it might be called multiple times over the course of the app's lifetime. /// roughly, /// 1. check if window already exists. otherwise, create one now. @@ -546,6 +548,7 @@ mod glow_integration { } Ok(()) } + fn window(&self) -> &winit::window::Window { self.window.as_ref().expect("winit window doesn't exist") } @@ -631,6 +634,11 @@ mod glow_integration { GlutinWindowContext::new(winit_window_builder, native_options, event_loop)? }; glutin_window_context.on_resume(event_loop)?; + + if let Some(window) = &glutin_window_context.window { + epi_integration::apply_native_options_to_window(window, native_options); + } + let gl = unsafe { glow::Context::from_loader_function(|s| { let s = std::ffi::CString::new(s) @@ -1047,7 +1055,11 @@ mod wgpu_integration { native_options: &NativeOptions, ) -> std::result::Result { let window_settings = epi_integration::load_window_settings(storage); - epi_integration::build_window(event_loop, title, native_options, window_settings) + let window_builder = + epi_integration::window_builder(event_loop, title, native_options, window_settings); + let window = window_builder.build(event_loop)?; + epi_integration::apply_native_options_to_window(&window, native_options); + Ok(window) } #[allow(unsafe_code)]