Skip to content

fix: keep title bar and system button state consistent across changes - #270

Closed
SineStriker wants to merge 4 commits into
mainfrom
docs/registration-contract
Closed

SineStriker wants to merge 4 commits into
mainfrom
docs/registration-contract

Conversation

@SineStriker

Copy link
Copy Markdown
Contributor

Motivation

setTitleBar() documents that the system buttons and hit-test visible items are unset when the title bar changes. The implementation performed this only when the previous title bar still existed, so a first assignment kept the earlier state. The title bar is a QPointer, so destroying it also left its system buttons set on the agent. setTitleBar() also asserted a non-null item, which made nullptr unusable as "no title bar".

This PR is a follow-up to the review of #262.

Behavior

  • setTitleBar(nullptr) removes the title bar.
  • Changing the title bar unsets all system buttons and hit-test visible items, including on the first assignment.
  • Destroying the title bar has the same effect as removing it. The agent clears the title bar, emits systemButtonChanged(role, nullptr) for each cleared system button, and emits titleBarChanged(nullptr) (Widgets) or titleBarWidgetChanged(nullptr) (Quick).
  • Replacing the title bar emits systemButtonChanged(role, nullptr) for each cleared system button. Destroying a title bar that has already been replaced emits nothing.
  • The shared logic is in WindowAgentBasePrivate. Each agent emits its typed signals and performs its macOS updates in the notification functions.
  • setHitTestVisible() does not emit a signal. This is unchanged.
  • The qdoc of setTitleBar(), setSystemButton(), and setHitTestVisible() is added for QuickWindowAgent, and the qdoc of the Widgets functions states the unset behavior and the ordering constraints.

Notes for reviewers

  • WindowAgentBasePrivate is an installed private header. It gains pure virtual functions notifyTitleBarReplaced() and notifyTitleBarDestroyed(), so the class is abstract. The only subclasses in this repository are WidgetWindowAgentPrivate and QuickWindowAgentPrivate.

Verification

  • Built the core, Widgets, and Quick libraries with Apple Clang and Qt 6.12.1 (Debug, Cocoa platform).
  • Probes on macOS cover first assignment, replacement, destruction of the current title bar, and destruction of the agent before the title bar. All cases pass for both agents.
  • A mutation that removes the cleared-button signal makes the probe fail, and the restored code passes.

Not verified: Windows and Linux. The implementations for these platforms are not compiled on the test machine.

@wangwenx190

Copy link
Copy Markdown
Collaborator

Merged into main by cherry-pick in 276cd07..d7b9c40, therefore GitHub does not detect the merge:

Differences from this PR:

  • 215d844 adds AbstractWindowContext::removeTitleBar(), and the destroyed handler calls it instead of setTitleBar(nullptr). QObject clears the title bar QPointer before it emits destroyed(), except for QWidget, whose destructor emits destroyed() earlier. For a Quick title bar, setTitleBar(nullptr) therefore compared equal and returned early, and the system buttons and hit-test visible items stayed registered while the signals reported them as unset.
  • main had preserved registrations made before the first title bar. That behavior is replaced by the behavior of this PR, and the affected tests in tests/unit and tests/windows/windowproc are updated. Two tests declared variables captured by signal handlers after the title bar items; destroying the title bar now emits a signal, therefore AddressSanitizer reported a stack-use-after-scope, and the declaration order is corrected.
  • The documentation of main keeps the hit-test rules next to the text of this PR, and the changelog and tutorials record the compatibility change for registrations made before the first setTitleBar() call.

Verified on macOS with Apple Clang and Qt 6.12.1: each commit builds and passes the test suite, and the unit and component tests pass under AddressSanitizer. Windows and Linux are not verified.

@wangwenx190 wangwenx190 closed this Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants