Browse Source

Fix: make sure always_on_top is respected on glow again

pull/2698/head
Emil Ernerfeldt 2 years ago
parent
commit
0fc25c2680
  1. 15
      crates/eframe/src/native/epi_integration.rs
  2. 14
      crates/eframe/src/native/run.rs

15
crates/eframe/src/native/epi_integration.rs

@ -64,6 +64,7 @@ pub fn read_window_info(
monitor_size,
}
}
pub fn window_builder<E>(
event_loop: &EventLoopWindowTarget<E>,
title: &str,
@ -159,23 +160,17 @@ pub fn window_builder<E>(
}
window_builder
}
pub fn build_window<E>(
event_loop: &EventLoopWindowTarget<E>,
title: &str,
native_options: &epi::NativeOptions,
window_settings: Option<WindowSettings>,
) -> Result<winit::window::Window, winit::error::OsError> {
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<E>(event_loop: &EventLoopWindowTarget<E>) -> egui::Vec2 {

14
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<winit::window::Window, winit::error::OsError> {
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)]

Loading…
Cancel
Save