From: Brian Kendall Date: Mon, 30 Nov 2020 18:24:41 +0000 (-0500) Subject: Fix macOS bug where tray window causes spaces to switch X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~22^2~32^2 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=f9991e180ca1cb7d88d773e61c1fe914f31d1791;p=nextcloud-desktop.git Fix macOS bug where tray window causes spaces to switch Signed-off-by: Brian Kendall --- diff --git a/src/gui/systray.cpp b/src/gui/systray.cpp index 7e5c0bb31..422c41b88 100644 --- a/src/gui/systray.cpp +++ b/src/gui/systray.cpp @@ -267,6 +267,14 @@ void Systray::forceWindowInit(QQuickWindow *window) const // this shouldn't flicker window->show(); window->hide(); + +#ifdef Q_OS_MAC + // On macOS we need to designate the tray window as visible on all spaces and + // at the menu bar level, otherwise showing it can cause the current spaces to + // change, or the window could be obscured by another window that shouldn't + // normally cover a menu. + OCC::setTrayWindowLevelAndVisibleOnAllSpaces(window); +#endif } QScreen *Systray::currentScreen() const diff --git a/src/gui/systray.h b/src/gui/systray.h index 13f79ed01..df15154ba 100644 --- a/src/gui/systray.h +++ b/src/gui/systray.h @@ -23,12 +23,14 @@ class QScreen; class QQmlApplicationEngine; class QQuickWindow; +class QWindow; namespace OCC { #ifdef Q_OS_OSX bool canOsXSendUserNotification(); void sendOsXUserNotification(const QString &title, const QString &message); +void setTrayWindowLevelAndVisibleOnAllSpaces(QWindow *window); #endif /** diff --git a/src/gui/systray.mm b/src/gui/systray.mm index 95e0a11a7..a4d35eb23 100644 --- a/src/gui/systray.mm +++ b/src/gui/systray.mm @@ -1,4 +1,5 @@ #include +#include #import @interface NotificationCenterDelegate : NSObject @@ -41,4 +42,13 @@ void sendOsXUserNotification(const QString &title, const QString &message) [notification release]; } +void setTrayWindowLevelAndVisibleOnAllSpaces(QWindow *window) +{ + NSView *nativeView = (NSView *)window->winId(); + NSWindow *nativeWindow = (NSWindow *)[nativeView window]; + [nativeWindow setCollectionBehavior:NSWindowCollectionBehaviorCanJoinAllSpaces | NSWindowCollectionBehaviorIgnoresCycle | + NSWindowCollectionBehaviorTransient]; + [nativeWindow setLevel:NSMainMenuWindowLevel]; +} + }