Merge pull request #4917 from nextcloud/bugfix/macos-notch-calc

Fix menu bar height calculation on macOS
This commit is contained in:
Matthieu Gallien 2022-09-10 11:52:37 +02:00 committed by GitHub
commit a400738b05
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 5 deletions

View file

@ -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) {

View file

@ -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
/**

View file

@ -52,9 +52,18 @@ enum MacNotificationAuthorizationOptions {
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