From 086919afde769c14aedd4a7ad52589eda03fd295 Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Tue, 6 Feb 2024 21:46:30 +0200 Subject: [PATCH] On Windows, apply `ScaleFactorChanged` new size if different than OS This fixes an issue when setting the position of the window on a new monitor and immediately maximizing it ```rs window.set_outer_position::>((2000, 200).into()); window.set_maximized(true); ``` Due to the nature of the event loop, the requested position and maximization state will apply correctly but due to the fact that the new position is a different monitor, a `ScaleFactorChanged` is emitted afterwards to the evenloop and a new size is set while the window is still maximized which results in a window that has `WS_MAXIMZE` window style but doesn't cover the whole monitor. --- CHANGELOG.md | 1 + .../windows/event_loop/runner.rs | 28 +++++++++++-------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8a9bb5bd1..0dc82e9bcc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ Unreleased` header. - On X11, fix deadlock when adjusting DPI and resizing at the same time. - On Wayland, fix `Focused(false)` being send when other seats still have window focused. - On Wayland, fix `Window::set_{min,max}_inner_size` not always applied. +- On Windows, fix inconsistent resizing behavior with multi-monitor setups when repositioning outside the event loop. # 0.29.10 diff --git a/src/platform_impl/windows/event_loop/runner.rs b/src/platform_impl/windows/event_loop/runner.rs index 7486528de5..4881ce7452 100644 --- a/src/platform_impl/windows/event_loop/runner.rs +++ b/src/platform_impl/windows/event_loop/runner.rs @@ -403,23 +403,29 @@ impl BufferedEvent { match self { Self::Event(event) => dispatch(event), Self::ScaleFactorChanged(window_id, scale_factor, new_inner_size) => { - let new_inner_size = Arc::new(Mutex::new(new_inner_size)); + let user_new_innner_size = Arc::new(Mutex::new(new_inner_size)); dispatch(Event::WindowEvent { window_id, event: WindowEvent::ScaleFactorChanged { scale_factor, - inner_size_writer: InnerSizeWriter::new(Arc::downgrade(&new_inner_size)), + inner_size_writer: InnerSizeWriter::new(Arc::downgrade( + &user_new_innner_size, + )), }, }); - let inner_size = *new_inner_size.lock().unwrap(); - drop(new_inner_size); - - let window_flags = unsafe { - let userdata = - get_window_long(window_id.0.into(), GWL_USERDATA) as *mut WindowData; - (*userdata).window_state_lock().window_flags - }; - window_flags.set_size((window_id.0).0, inner_size); + let inner_size = *user_new_innner_size.lock().unwrap(); + + drop(user_new_innner_size); + + if inner_size != new_inner_size { + let window_flags = unsafe { + let userdata = + get_window_long(window_id.0.into(), GWL_USERDATA) as *mut WindowData; + (*userdata).window_state_lock().window_flags + }; + + window_flags.set_size((window_id.0).0, inner_size); + } } } }