Skip to content

Commit

Permalink
On Windows, apply ScaleFactorChanged new size if different than OS
Browse files Browse the repository at this point in the history
This fixes an issue when setting the position of the window on a new
monitor and immediately maximizing it

```rs
window.set_outer_position::<PhysicalPosition<u32>>((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.
  • Loading branch information
amrbashir authored and kchibisov committed Feb 17, 2024
1 parent c248bec commit 086919a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
28 changes: 17 additions & 11 deletions src/platform_impl/windows/event_loop/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,23 +403,29 @@ impl<T> BufferedEvent<T> {
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<T>;
(*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<T>;
(*userdata).window_state_lock().window_flags
};

window_flags.set_size((window_id.0).0, inner_size);
}
}
}
}
Expand Down

0 comments on commit 086919a

Please sign in to comment.