Skip to content

Commit ce6b92c

Browse files
sp00ktoberclaude
andcommitted
fix(studio): restore the dock layout before the window maximizes
Qt keeps a layout restored into a hidden, maximized window that does not fit yet and retries it on every resize. On macOS each retry builds new dock tab bars and resizes again, so a saved maximized window plus a saved layout froze the studio at start (about 750 tab bars a second). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 394f2a2 commit ce6b92c

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

‎apps/studio/src/mhfu_studio/ui/window.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,12 @@ def __init__(self, studio: Studio, settings: QSettings | None = None) -> None:
208208
if not (isinstance(geo, QByteArray) and self.restoreGeometry(geo)):
209209
self.resize(1500, 940)
210210
studio.listen(self._schedule)
211+
# the layout before the maximize: Qt retries one restored into a hidden, maximized
212+
# window on every resize, and on macOS each retry resizes again, forever
213+
maximized = self.windowState() & Qt.WindowState.WindowMaximized
214+
self.setWindowState(self.windowState() & ~maximized)
211215
self.sync()
216+
self.setWindowState(self.windowState() | maximized)
212217

213218
# ---- docks ----------------------------------------------------------------------- #
214219

‎apps/studio/tests/ui/test_window.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,24 @@ def test_old_layouts_are_dropped(make_window: Make) -> None:
176176
assert again.dockWidgetArea(dock(again, "map/Items")) == LEFT
177177

178178

179+
def test_layout_restores_unmaximized(make_window: Make, monkeypatch: pytest.MonkeyPatch) -> None:
180+
"""A layout restored into a hidden, maximized window looped forever on macOS."""
181+
w = make_window()
182+
w.showMaximized()
183+
w.close()
184+
states: list[Qt.WindowState] = []
185+
restore = QMainWindow.restoreState
186+
187+
def spy(self: QMainWindow, state: Any, version: int = 0) -> bool:
188+
states.append(self.windowState())
189+
return restore(self, state, version)
190+
191+
monkeypatch.setattr(QMainWindow, "restoreState", spy)
192+
again = make_window(show=False)
193+
assert states and not any(s & Qt.WindowState.WindowMaximized for s in states)
194+
assert again.windowState() & Qt.WindowState.WindowMaximized
195+
196+
179197
def test_restore_places_new_docks(make_window: Make) -> None:
180198
make_window().close()
181199
w = make_window(Tabbed("map"), Tabbed("monster"))

0 commit comments

Comments
 (0)