Refactor win32 window state code#730
Conversation
b04622c to
5851c56
Compare
5851c56 to
4cba678
Compare
|
There hasn't been much movement on getting this reviewed, but this fixes quite a few issues and improves the code quality in the Windows backend so I'm gonna go ahead merge this. |
|
Was about to submit an issue but it looks like this is still open and is probably the same thing? Our particular use case is that the window is shrinking when toggling back and forth between windowed and borderless fullscreen on windows, my shot in the dark guess would be that there is an inconsistency between whether the window still/already has a border when the client rect gets saved and restored, respectively. |
|
I experienced something similar where the size/position wasn't restoring correctly, but eventually sorted it out by setting everything manually instead of using the enum WindowMode {
Fullscreen {
last_position: LogicalPosition,
last_size: LogicalSize,
},
Windowed,
}
pub fn toggle_window_mode(&mut self) {
match self.window_mode {
WindowMode::Windowed => {
let last_position = self.window.outer_position().unwrap();
let last_size = self.window.inner_size();
let monitor = self.window.current_monitor();
let dpi_factor = monitor.hidpi_factor();
let x = monitor.position().x as _;
// If the window is wider than the current monitor, stretch it across all monitors
let mut inner_physical_size = monitor.size();
if last_size.to_physical(dpi_factor).width > inner_physical_size.width {
let monitor_count = self.window.available_monitors().count();
inner_physical_size.width *= monitor_count as f64;
}
self.window.set_visible(false);
self.window.set_decorations(false);
self.window.set_outer_position(LogicalPosition::from((x, 0)));
self.window.set_inner_size(inner_physical_size.to_logical(dpi_factor));
self.window.set_visible(true);
self.window_mode = WindowMode::Fullscreen {
last_position,
last_size,
};
}
WindowMode::Fullscreen {
last_position,
last_size,
} => {
self.window.set_visible(false);
self.window.set_decorations(true);
self.window.set_inner_size(last_size);
self.window.set_outer_position(last_position);
self.window.set_visible(true);
self.window_mode = WindowMode::Windowed;
}
}
} |
|
@JasonHise I think you're right about that. There's probably some further simplification of our underlying model that we could do to fix that, but fixing that is fairly low on my personal priority list. |
|
@JasonHise Actually, looking back at this, it looks like that's a separate bug entirely! It looks like there was a small oversight in some code that arrived later and we weren't handling the window rect restore correctly. It's a fairly simple fix though, so I've made a PR here: #1172. Sorry about dismissing your issue earlier! |
|
@Osspial awesome, thanks! |
CHANGELOG.mdif knowledge of this change could be valuable to usersThis PR refactors the Windows state-setting code to make it significantly easier to read and modify going forward. It also fixes #723 and a few other miscellaneous untracked issues I found when doing the refactor.
TODO:
WS_CHILDwhenWS_POPUPis enabledset_maximized