Skip to content

Commit

Permalink
Merge pull request #4917 from nextcloud/bugfix/macos-notch-calc
Browse files Browse the repository at this point in the history
Fix menu bar height calculation on macOS
  • Loading branch information
mgallien authored Sep 10, 2022
2 parents d91415e + b1caa45 commit a400738
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/gui/systray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,9 +513,8 @@ QRect Systray::taskbarGeometry() const
}
return tbRect;
#elif defined(Q_OS_MACOS)
// Finder bar is always 22px height on macOS (when treating as effective pixels)
const auto screenWidth = currentScreenRect().width();
const auto statusBarHeight = static_cast<int>(OCC::statusBarThickness());
const auto statusBarHeight = static_cast<int>(OCC::menuBarThickness());
return {0, 0, screenWidth, statusBarHeight};
#else
if (taskbarOrientation() == TaskBarPosition::Bottom || taskbarOrientation() == TaskBarPosition::Top) {
Expand Down
2 changes: 1 addition & 1 deletion src/gui/systray.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ bool canOsXSendUserNotification();
void sendOsXUserNotification(const QString &title, const QString &message);
void sendOsXUpdateNotification(const QString &title, const QString &message, const QUrl &webUrl);
void setTrayWindowLevelAndVisibleOnAllSpaces(QWindow *window);
double statusBarThickness();
double menuBarThickness();
#endif

/**
Expand Down
13 changes: 11 additions & 2 deletions src/gui/systray.mm
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,18 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center
Provisional
};

double statusBarThickness()
double menuBarThickness()
{
return [NSStatusBar systemStatusBar].thickness;
const NSMenu *mainMenu = [[NSApplication sharedApplication] mainMenu];

if (mainMenu == nil) {
// Return this educated guess if something goes wrong.
// As of macOS 12.4 this will always return 22, even on notched Macbooks.
qCWarning(lcMacSystray) << "Got nil for main menu. Going with reasonable menu bar height guess.";
return [[NSStatusBar systemStatusBar] thickness];
}

return mainMenu.menuBarHeight;
}

// TODO: Get this to actually check for permissions
Expand Down

0 comments on commit a400738

Please sign in to comment.