macOS: Preserve styleMask bits that we don't control when updating mask

We use QCocoaWindow::windowStyleMask to compute a new styleMask for the
NSWindow, based on the QWindow flags. However, some styleMask bits we
do not control in this function, so we need to preserve them in case
they were already set on the NSWindow, as otherwise we end up clearing
those bits. We did this already for NSWindowStyleMaskFullScreen, but now
we do it for all style mask bits we don't control.

This fixes an issue after QCocoaWindow::applyContentBorderThickness()
started calling setWindowFlags to control NSWindowStyleMaskTexturedBackground,
after the introduction of the Qt::NoTitleBarBackgroundHint window flag in
a1e6fed44964a3eb14045bf819d232d6cbad9f59 and then
bddc0198297828ba29e5cf4b39e07412a506a551.

The symptom was losing the NSWindowStyleMaskDocModalWindow style mask
for sheets or other modal windows with a QTabWidget in them, as that
widget ends up calling applyContentBorderThickness().

Fixes: QTBUG-134447
Change-Id: Ie3e9ca3ff14f84ce70438d3633bd283fb78b9e8c
Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
(cherry picked from commit b90b473ee01bc3dfce88cce3d0f6ebb8ee0f7f57)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit 027624b4d59b65f9f8b4ccf23611d988c4633614)
This commit is contained in:
Tor Arne Vestbø 2025-03-06 16:09:05 +01:00 committed by Qt Cherry-pick Bot
parent de02c59757
commit 516cce13e2

View File

@ -649,9 +649,13 @@ NSUInteger QCocoaWindow::windowStyleMask(Qt::WindowFlags flags)
if (flags & Qt::ExpandedClientAreaHint)
styleMask |= NSWindowStyleMaskFullSizeContentView;
// Don't wipe existing states
if (m_view.window.styleMask & NSWindowStyleMaskFullScreen)
styleMask |= NSWindowStyleMaskFullScreen;
// Don't wipe existing states for style flags we don't control here
styleMask |= (m_view.window.styleMask & (
NSWindowStyleMaskFullScreen
| NSWindowStyleMaskUnifiedTitleAndToolbar
| NSWindowStyleMaskDocModalWindow
| NSWindowStyleMaskNonactivatingPanel
| NSWindowStyleMaskHUDWindow));
return styleMask;
}