From 8afef45d4e92ea66f35c35102302c97d1632043c Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Sun, 25 Feb 2024 08:35:57 +0000 Subject: [PATCH] Fix d3c673e: Don't defer OnResize() after ReInit() (#12174) Some windows resize themselves during painting and issue ReInit(). In this case deferred OnResize() causes a visible glitch as the event is handled on the next redraw. --- src/window.cpp | 14 +++++++++----- src/window_func.h | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/window.cpp b/src/window.cpp index 2151be5f49..314bc9a72c 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -984,7 +984,7 @@ void Window::ReInit(int rx, int ry, bool reposition) this->FindWindowPlacementAndResize(this->window_desc->GetDefaultWidth(), this->window_desc->GetDefaultHeight()); } - ResizeWindow(this, dx, dy); + ResizeWindow(this, dx, dy, true, false); /* ResizeWindow() does this->SetDirty() already, no need to do it again here. */ } @@ -1447,8 +1447,8 @@ void Window::FindWindowPlacementAndResize(int def_width, int def_height) ResizeWindow(this, enlarge_x, enlarge_y); /* ResizeWindow() calls this->OnResize(). */ } else { - /* Schedule OnResize; that way the scrollbars and matrices get initialized. */ - this->ScheduleResize(); + /* Always call OnResize; that way the scrollbars and matrices get initialized. */ + this->OnResize(); } int nx = this->left; @@ -2024,7 +2024,7 @@ static void EnsureVisibleCaption(Window *w, int nx, int ny) * @param delta_y Delta y-size of changed window * @param clamp_to_screen Whether to make sure the whole window stays visible */ -void ResizeWindow(Window *w, int delta_x, int delta_y, bool clamp_to_screen) +void ResizeWindow(Window *w, int delta_x, int delta_y, bool clamp_to_screen, bool schedule_resize) { if (delta_x != 0 || delta_y != 0) { if (clamp_to_screen) { @@ -2051,7 +2051,11 @@ void ResizeWindow(Window *w, int delta_x, int delta_y, bool clamp_to_screen) EnsureVisibleCaption(w, w->left, w->top); /* Schedule OnResize to make sure everything is initialised correctly if it needs to be. */ - w->ScheduleResize(); + if (schedule_resize) { + w->ScheduleResize(); + } else { + w->OnResize(); + } w->SetDirty(); } diff --git a/src/window_func.h b/src/window_func.h index da798aa4e9..8bc5aba228 100644 --- a/src/window_func.h +++ b/src/window_func.h @@ -26,7 +26,7 @@ Window *FindWindowById(WindowClass cls, T number) return FindWindowById(cls, number.base()); } -void ResizeWindow(Window *w, int x, int y, bool clamp_to_screen = true); +void ResizeWindow(Window *w, int x, int y, bool clamp_to_screen = true, bool schedule_resize = true); int PositionMainToolbar(Window *w); int PositionStatusbar(Window *w); int PositionNewsMessage(Window *w);