Skip to content

Commit

Permalink
Clean up and document setFullSizeContentView changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jdpurcell committed May 6, 2024
1 parent 9ff52d6 commit 9a38b12
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/qvcocoafunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class QVCocoaFunctions

static void setUserDefaults();

static void setFullSizeContentView(QWindow *window, const bool shouldEnable);
static void setFullSizeContentView(QWindow *window, const bool enable);

static void setVibrancy(bool alwaysDark, QWindow *window);

Expand Down
23 changes: 13 additions & 10 deletions src/qvcocoafunctions.mm
Original file line number Diff line number Diff line change
Expand Up @@ -64,33 +64,36 @@ static void fixNativeMenuEccentricities(QMenu *menu, NSMenu *nativeMenu)
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"NSFullScreenMenuItemEverywhere"];
}

// This function should only be called once because it sets observers
void QVCocoaFunctions::setFullSizeContentView(QWindow *window, const bool shouldEnable)
// This function should only be enabled once because it sets observers
void QVCocoaFunctions::setFullSizeContentView(QWindow *window, const bool enable)
{
auto *view = reinterpret_cast<NSView*>(window->winId());

const bool isAlreadyEnabled = view.window.styleMask & NSWindowStyleMaskFullSizeContentView;
if (shouldEnable == isAlreadyEnabled || (shouldEnable && !view.wantsLayer))
// Make sure the requested state isn't already in effect
if (enable == (view.window.styleMask & NSWindowStyleMaskFullSizeContentView))
return;

// Changing the style mask causes the window to resize, so snapshot the original size
NSRect originalFrame = view.window.frame;
if (shouldEnable)

if (enable)
{
// Proceed only if this Qt and macOS version combination is already using layer-backed view
if (!view.wantsLayer)
return;
view.window.styleMask |= NSWindowStyleMaskFullSizeContentView;
}
else
{
int titlebarOverlap = view.window.contentView.frame.size.height - view.window.contentLayoutRect.size.height;
NSRect adjustedFrame = originalFrame;
adjustedFrame.size.height -= titlebarOverlap;
[view.window setFrame:adjustedFrame display:NO];
view.window.styleMask &= ~NSWindowStyleMaskFullSizeContentView;
}

// Restore original size after style mask change
[view.window setFrame:originalFrame display:YES];

#if QT_VERSION < QT_VERSION_CHECK(6, 2, 0)
// workaround for QTBUG-69975
if (shouldEnable)
if (enable)
{
[[NSNotificationCenter defaultCenter] addObserverForName:NSWindowDidExitFullScreenNotification object:view.window queue:nil usingBlock:^(NSNotification *notification){
auto *window = reinterpret_cast<NSWindow*>(notification.object);
Expand Down

0 comments on commit 9a38b12

Please sign in to comment.