2015-02-07 20:23:09 +03:00
|
|
|
#include <QString>
|
2020-11-30 21:24:41 +03:00
|
|
|
#include <QWindow>
|
2015-02-07 20:23:09 +03:00
|
|
|
#import <Cocoa/Cocoa.h>
|
|
|
|
|
2016-01-05 15:32:46 +03:00
|
|
|
@interface NotificationCenterDelegate : NSObject
|
|
|
|
@end
|
|
|
|
@implementation NotificationCenterDelegate
|
|
|
|
// Always show, even if app is active at the moment.
|
|
|
|
- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center
|
|
|
|
shouldPresentNotification:(NSUserNotification *)notification
|
|
|
|
{
|
|
|
|
Q_UNUSED(center);
|
|
|
|
Q_UNUSED(notification);
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
2015-02-07 20:23:09 +03:00
|
|
|
namespace OCC {
|
|
|
|
|
2022-02-03 18:37:17 +03:00
|
|
|
double statusBarThickness()
|
|
|
|
{
|
|
|
|
return [NSStatusBar systemStatusBar].thickness;
|
|
|
|
}
|
|
|
|
|
2015-02-07 20:23:09 +03:00
|
|
|
bool canOsXSendUserNotification()
|
|
|
|
{
|
|
|
|
return NSClassFromString(@"NSUserNotificationCenter") != nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
void sendOsXUserNotification(const QString &title, const QString &message)
|
|
|
|
{
|
|
|
|
Class cuserNotificationCenter = NSClassFromString(@"NSUserNotificationCenter");
|
|
|
|
id userNotificationCenter = [cuserNotificationCenter defaultUserNotificationCenter];
|
|
|
|
|
2016-01-05 15:32:46 +03:00
|
|
|
static dispatch_once_t once;
|
|
|
|
dispatch_once(&once, ^{
|
|
|
|
id delegate = [[NotificationCenterDelegate alloc] init];
|
|
|
|
[userNotificationCenter setDelegate:delegate];
|
|
|
|
});
|
|
|
|
|
2015-02-07 20:23:09 +03:00
|
|
|
Class cuserNotification = NSClassFromString(@"NSUserNotification");
|
|
|
|
id notification = [[cuserNotification alloc] init];
|
|
|
|
[notification setTitle:[NSString stringWithUTF8String:title.toUtf8().data()]];
|
|
|
|
[notification setInformativeText:[NSString stringWithUTF8String:message.toUtf8().data()]];
|
|
|
|
|
|
|
|
[userNotificationCenter deliverNotification:notification];
|
|
|
|
[notification release];
|
|
|
|
}
|
|
|
|
|
2020-11-30 21:24:41 +03:00
|
|
|
void setTrayWindowLevelAndVisibleOnAllSpaces(QWindow *window)
|
|
|
|
{
|
|
|
|
NSView *nativeView = (NSView *)window->winId();
|
|
|
|
NSWindow *nativeWindow = (NSWindow *)[nativeView window];
|
|
|
|
[nativeWindow setCollectionBehavior:NSWindowCollectionBehaviorCanJoinAllSpaces | NSWindowCollectionBehaviorIgnoresCycle |
|
|
|
|
NSWindowCollectionBehaviorTransient];
|
|
|
|
[nativeWindow setLevel:NSMainMenuWindowLevel];
|
|
|
|
}
|
|
|
|
|
2022-02-04 05:39:38 +03:00
|
|
|
bool osXInDarkMode()
|
|
|
|
{
|
|
|
|
NSString *osxMode = [[NSUserDefaults standardUserDefaults] stringForKey:@"AppleInterfaceStyle"];
|
|
|
|
return [osxMode containsString:@"Dark"];
|
|
|
|
}
|
|
|
|
|
2015-02-07 20:23:09 +03:00
|
|
|
}
|