[fix] restore main window size after display resolution changes

This commit is contained in:
kunkundi
2026-11-11 11:26:27 +08:00
parent 34b59de15d
commit abcc0eef0a
2 changed files with 13 additions and 5 deletions
@@ -6455,14 +6455,14 @@ void GuiApplication::SyncWindowGeometry(bool gallery_window) {
const bool fullscreen = window.is_fullscreen();
const bool maximized = window.is_maximized();
#endif
if (!transitioning && placement.RecoverUndersized(wall_mode, window.position(), current_size,
if (!transitioning && placement.RecoverSizeMismatch(wall_mode, window.position(), current_size,
window.scale_factor(), window.is_visible(),
window.is_minimized(), fullscreen, maximized,
compact_height, compact_width)) {
ui_->restore_ticks[gallery_window] = 0;
const auto target = placement.RestoreSize(wall_mode, window.scale_factor(),
compact_height, compact_width);
LOG_WARN("DeskHub undersized window: wall={} client={}x{} scale={}; restoring={}x{}",
LOG_WARN("DeskHub window size mismatch: wall={} client={}x{} scale={}; restoring={}x{}",
wall_mode, current_size.width, current_size.height,
window.scale_factor(), target.width, target.height);
}
@@ -45,7 +45,7 @@ struct WindowState {
}
}
bool RecoverUndersized(bool wall, slint::PhysicalPosition position,
bool RecoverSizeMismatch(bool wall, slint::PhysicalPosition position,
slint::PhysicalSize size, float scale, bool visible,
bool minimized, bool fullscreen, bool maximized,
float compact_height = 486,
@@ -53,8 +53,16 @@ struct WindowState {
// Hidden/minimized/uninitialized windows can report temporary tiny bounds.
// Leave those alone, and let an in-flight restoration retain its target.
if (Restoring() || !visible || minimized || fullscreen || maximized ||
size.width == 0 || size.height == 0 ||
!IsUndersized(size, scale, compact_height, compact_width))
size.width == 0 || size.height == 0)
return false;
// Display mode/DPI changes can enlarge the fixed connection window as
// well as shrink it. Restore both directions at the current scale; the
// resizable gallery only needs recovery below its minimum dimensions.
const bool mismatch =
wall ? IsUndersized(size, scale, compact_height, compact_width)
: !SameSize(size, RestoreSize(false, scale, compact_height,
compact_width));
if (!mismatch)
return false;
if (wall) {
wall_position = position;