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

Fix: Window position creeps between executions on scaled monitors #4443

Merged
Merged
Changes from 1 commit
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
Next Next commit
Factor out active monitor detection
  • Loading branch information
avery-radmacher committed May 2, 2024
commit 6937f39b929d7dc9129104a8f86aa9a56b71a1c0
25 changes: 21 additions & 4 deletions crates/egui-winit/src/window_settings.rs
Original file line number Diff line number Diff line change
@@ -127,12 +127,12 @@ impl WindowSettings {
}
}

fn clamp_pos_to_monitors<E>(
fn find_active_monitor<E>(
egui_zoom_factor: f32,
event_loop: &winit::event_loop::EventLoopWindowTarget<E>,
window_size_pts: egui::Vec2,
position_px: &mut egui::Pos2,
) {
position_px: &egui::Pos2,
) -> Option<winit::monitor::MonitorHandle> {
crate::profile_function!();

let monitors = event_loop.available_monitors();
@@ -142,7 +142,7 @@ fn clamp_pos_to_monitors<E>(
.primary_monitor()
.or_else(|| event_loop.available_monitors().next())
else {
return; // no monitors 🤷
return None; // no monitors 🤷
};

for monitor in monitors {
@@ -159,6 +159,23 @@ fn clamp_pos_to_monitors<E>(
}
}

Some(active_monitor)
}

fn clamp_pos_to_monitors<E>(
egui_zoom_factor: f32,
event_loop: &winit::event_loop::EventLoopWindowTarget<E>,
window_size_pts: egui::Vec2,
position_px: &mut egui::Pos2,
) {
crate::profile_function!();

let Some(active_monitor) =
find_active_monitor(egui_zoom_factor, event_loop, window_size_pts, position_px)
else {
return; // no monitors 🤷
};

let mut window_size_px =
window_size_pts * (egui_zoom_factor * active_monitor.scale_factor() as f32);
// Add size of title bar. This is 32 px by default in Win 10/11.