Signed-off-by: Brian Kendall <brian@briankendall.net>
// 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
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
/**
#include <QString>
+#include <QWindow>
#import <Cocoa/Cocoa.h>
@interface NotificationCenterDelegate : NSObject
[notification release];
}
+void setTrayWindowLevelAndVisibleOnAllSpaces(QWindow *window)
+{
+ NSView *nativeView = (NSView *)window->winId();
+ NSWindow *nativeWindow = (NSWindow *)[nativeView window];
+ [nativeWindow setCollectionBehavior:NSWindowCollectionBehaviorCanJoinAllSpaces | NSWindowCollectionBehaviorIgnoresCycle |
+ NSWindowCollectionBehaviorTransient];
+ [nativeWindow setLevel:NSMainMenuWindowLevel];
+}
+
}