Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix menu bar height calculation on macOS #4917

Merged
merged 1 commit into from
Sep 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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