Skip to content

frontend: an application quit closes the main window first (Fixes #5406) - #5410

Merged
vpacher merged 3 commits into
masterfrom
fix/5406-quit-floating-dock
Nov 21, 2026
Merged

vpacher merged 3 commits into
masterfrom
fix/5406-quit-floating-dock

Conversation

@vpacher

@vpacher vpacher commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

Fixes #5406.

Problem

Cmd+Q, logoff, shutdown and QCoreApplication::quit() reach OBS as QEvent::Quit. Qt then closes the visible top-level windows in no fixed order (QApplicationPrivate::tryCloseAllWidgetWindows(), a hash set of widgets) and cancels the quit when one of them refuses its close. The main docks (Scenes, Sources, Audio Mixer, Scene Transitions, Controls) are not closable, and QDockWidget::closeEvent() refuses their close while the main window is visible. When a floating main dock came before the main window, the quit was cancelled, OBSBasic::closeWindow() never ran, and OBS stayed open for the rest of the session: File → Exit and SIGTERM ended in the same refused close. An lldb trace on macOS showed the chain from -[NSApplication terminate:] to the refused scenesDock close.

Change

  • QuitClosesMainWindowFirst (frontend/utility/close-top-level.hpp, header-only, Qt Widgets only): an event filter on the application. On QEvent::Quit it closes the visible main window first, through CloseTopLevel(), as if the user had closed it (OBSBasic::closeEvent() saves, stops the outputs and may ask). If the main window refuses (a cancelled exit prompt, outputs not ready yet), the quit is cancelled, as Qt cancels it. Then Qt closes the main docks in any order. A hidden main window (minimized to the tray) is left to Qt. The main window is held in a QPointer (OBSBasic deletes itself on close).
  • OBSApp::OBSInit() installs it after OBSBasic::OBSInit().
  • docs/features.md: one line under Fixed upstream bugs, Scenes and UI.

Not in this PR: closing one floating main dock (Cmd+W) is #5408; floating docks that hide while OBS is inactive on macOS are #5409.

Tests

Three cases in test_close_top_level (no new target or registration): a main window with 32 floating docks that are movable and floatable but not closable, like OBS's main docks.

  • quit_closes_the_main_window_with_floating_main_docks: a quit closes the main window once and all docks.
  • quit_is_cancelled_when_the_main_window_refuses: a refused main window close cancels the quit; the docks stay.
  • quit_with_a_hidden_main_window_closes_nothing_twice: with the main window hidden, the quit does not close it again.

RED 51f214ae4 (stub filter that does nothing): Linux (Qt 6.11.1, offscreen) 5/5 runs fail the first two cases: quit accepted 0, main window close events 0 (expected 1), main window visible 1, docks still visible 32 of 32, docks closed while the main window was visible 1. Windows (Qt 6.10.1, minimal) 10/10 runs fail. With 32 docks, a dock comes before the main window in Qt's order in nearly every run; a RED run can pass by chance only if the main window comes first.

GREEN 2f2e38979: Linux 25/25 runs pass, Windows 10/10, the Qt Frontend Linux lane passes (ci/linux_qt_frontend.py, 30 Qt tests). Test cost: about 0.05 s, peak RSS about 28 MB, no own threads.

Tier 2 and Tier 3: not applicable (frontend, no C original).

Real app

macOS 27.2.1 build on Apple silicon with Scenes and Stats floating, Cmd+Q: before the fix, 3 of 3 starts stayed open (the "Closing Dockable Window" notice, then nothing; File → Exit and SIGTERM did nothing). With the fix, 4 of 4 starts quit (==== Shutting down, 0 memory leaks), and the next start shows Scenes floating.

🤖 Generated with Claude Code

vpacher and others added 3 commits November 21, 2026 12:49
…ocks, RED (Refs #5406)

Three cases in test_close_top_level drive QuitClosesMainWindowFirst (a stub
that does nothing) with a main window and 32 floating docks that are not
closable, like OBS's main docks: a quit must close the main window and the
docks, a refused main window close must cancel the quit, and a quit with a
hidden main window must not close it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…5406)

Cmd+Q, logoff, shutdown and QCoreApplication::quit() reach OBS as
QEvent::Quit. Qt then closes the visible top-level windows in no fixed order
and cancels the quit when one refuses. The main docks are not closable, so
QDockWidget refuses their close while the main window is visible: a floating
main dock that came first cancelled the quit, and OBS stayed open for the
rest of the session.

QuitClosesMainWindowFirst, installed on the application, closes the main
window first. If OBSBasic refuses (a cancelled exit prompt, outputs not ready
yet), the quit is cancelled as before. Then Qt closes the main docks in any
order.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@vpacher
vpacher force-pushed the fix/5406-quit-floating-dock branch from 26912b5 to f56a1bb Compare November 21, 2026 12:13
@vpacher vpacher changed the title docs: features ledger line for the quit with a floating main dock (Refs #5406) frontend: an application quit closes the main window first (Fixes #5406) Nov 21, 2026
@vpacher
vpacher marked this pull request as ready for review November 21, 2026 12:15
@vpacher
vpacher requested a review from zackees as a code owner November 21, 2026 12:15
@vpacher
vpacher enabled auto-merge November 21, 2026 12:15
@vpacher
vpacher added this pull request to the merge queue Nov 21, 2026
Merged via the queue into master with commit c0bf235 Nov 21, 2026
47 checks passed
@vpacher
vpacher deleted the fix/5406-quit-floating-dock branch November 21, 2026 12:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

macOS: Cmd+Q does not quit when a floating main dock is closed first

1 participant