From bc3bd642b9bf04db65a534f51a1df5d611ccf00b Mon Sep 17 00:00:00 2001
From: Peter Nelson <peter1138@openttd.org>
Date: Tue, 5 Mar 2024 18:30:25 +0000
Subject: [PATCH] Fix: Relocate main toolbar and statusbar before other
 windows. (#12218)

When repositioning all windows, the main toolbar and statusbar need to already be in position to ensure that window captions are visible.
---
 src/window.cpp | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/src/window.cpp b/src/window.cpp
index 314bc9a72c..50455202c1 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -3436,6 +3436,18 @@ void RelocateAllWindows(int neww, int newh)
 {
 	CloseWindowByClass(WC_DROPDOWN_MENU);
 
+	/* Reposition toolbar then status bar before other all windows. */
+	if (Window *wt = FindWindowById(WC_MAIN_TOOLBAR, 0); wt != nullptr) {
+		ResizeWindow(wt, std::min<uint>(neww, _toolbar_width) - wt->width, 0, false);
+		wt->left = PositionMainToolbar(wt);
+	}
+
+	if (Window *ws = FindWindowById(WC_STATUS_BAR, 0); ws != nullptr) {
+		ResizeWindow(ws, std::min<uint>(neww, _toolbar_width) - ws->width, 0, false);
+		ws->top = newh - ws->height;
+		ws->left = PositionStatusbar(ws);
+	}
+
 	for (Window *w : Window::Iterate()) {
 		int left, top;
 		/* XXX - this probably needs something more sane. For example specifying
@@ -3447,24 +3459,14 @@ void RelocateAllWindows(int neww, int newh)
 				continue;
 
 			case WC_MAIN_TOOLBAR:
-				ResizeWindow(w, std::min<uint>(neww, _toolbar_width) - w->width, 0, false);
-
-				top = w->top;
-				left = PositionMainToolbar(w); // changes toolbar orientation
-				break;
+			case WC_STATUS_BAR:
+				continue;
 
 			case WC_NEWS_WINDOW:
 				top = newh - w->height;
 				left = PositionNewsMessage(w);
 				break;
 
-			case WC_STATUS_BAR:
-				ResizeWindow(w, std::min<uint>(neww, _toolbar_width) - w->width, 0, false);
-
-				top = newh - w->height;
-				left = PositionStatusbar(w);
-				break;
-
 			case WC_SEND_NETWORK_MSG:
 				ResizeWindow(w, std::min<uint>(neww, _toolbar_width) - w->width, 0, false);