Skip to content

Commit

Permalink
Fix: make sure always_on_top is respected on glow again
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Feb 8, 2023
1 parent 449dd1c commit 0fc25c2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
15 changes: 5 additions & 10 deletions crates/eframe/src/native/epi_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ pub fn read_window_info(
monitor_size,
}
}

pub fn window_builder<E>(
event_loop: &EventLoopWindowTarget<E>,
title: &str,
Expand Down Expand Up @@ -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 {
Expand Down
14 changes: 13 additions & 1 deletion crates/eframe/src/native/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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..
Expand All @@ -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.
Expand Down Expand Up @@ -546,6 +548,7 @@ mod glow_integration {
}
Ok(())
}

fn window(&self) -> &winit::window::Window {
self.window.as_ref().expect("winit window doesn't exist")
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)]
Expand Down

0 comments on commit 0fc25c2

Please sign in to comment.