diff --git a/kitty/cocoa_window.m b/kitty/cocoa_window.m index fe7e9640f94..418cec0eb73 100644 --- a/kitty/cocoa_window.m +++ b/kitty/cocoa_window.m @@ -11,6 +11,7 @@ #include #include +#include // Needed for _NSGetProgname #include #include @@ -23,6 +24,12 @@ #define NSEventModifierFlagControl NSControlKeyMask #endif +/*#if (MAC_OS_X_VERSION_MAX_ALLOWED < 101600) +#define UNNotification NSUserNotification +#define UNUserNotificationCenter NSUserNotificationCenter +#define UNUserNotificationCenterDelegate NSUserNotificationCenterDelegate +#endif*/ + typedef int CGSConnectionID; typedef int CGSWindowID; typedef int CGSWorkspaceID; @@ -141,25 +148,16 @@ + (GlobalMenuTarget *) shared_instance Py_RETURN_NONE; } -@interface NotificationDelegate : NSObject +@interface NotificationDelegate : NSObject @end @implementation NotificationDelegate - - (void)userNotificationCenter:(NSUserNotificationCenter *)center - didDeliverNotification:(NSUserNotification *)notification { - (void)(center); (void)(notification); - } - - - (BOOL) userNotificationCenter:(NSUserNotificationCenter *)center - shouldPresentNotification:(NSUserNotification *)notification { - (void)(center); (void)(notification); - return YES; - } - - - (void) userNotificationCenter:(NSUserNotificationCenter *)center - didActivateNotification:(NSUserNotification *)notification { - (void)(center); (void)(notification); + - (void)userNotificationCenter:(UNUserNotificationCenter *)center + didReceiveNotificationResponse:(UNNotificationResponse *)response + withCompletionHandler:(void (^)(void))completionHandler { + (void)(center); (void)(completionHandler); if (notification_activated_callback) { + UNNotificationContent *notification = [[[response notification] request] content]; PyObject *ret = PyObject_CallFunction(notification_activated_callback, "z", notification.userInfo[@"user_id"] ? [notification.userInfo[@"user_id"] UTF8String] : NULL); if (ret == NULL) PyErr_Print(); @@ -172,10 +170,10 @@ - (void) userNotificationCenter:(NSUserNotificationCenter *)center cocoa_send_notification(PyObject *self UNUSED, PyObject *args) { char *identifier = NULL, *title = NULL, *subtitle = NULL, *informativeText = NULL, *path_to_image = NULL; if (!PyArg_ParseTuple(args, "zssz|z", &identifier, &title, &informativeText, &path_to_image, &subtitle)) return NULL; - NSUserNotificationCenter *center = [NSUserNotificationCenter defaultUserNotificationCenter]; + UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; if (!center) {PyErr_SetString(PyExc_RuntimeError, "Failed to get the user notification center"); return NULL; } if (!center.delegate) center.delegate = [[NotificationDelegate alloc] init]; - NSUserNotification *n = [NSUserNotification new]; + UNNotificationContent *n = [UNNotificationContent new]; NSImage *img = nil; if (path_to_image) { NSString *p = @(path_to_image); @@ -188,18 +186,18 @@ - (void) userNotificationCenter:(NSUserNotificationCenter *)center } [img release]; } -#define SET(x) { \ - if (x) { \ - NSString *t = @(x); \ - n.x = t; \ - [t release]; \ - }} - SET(title); SET(subtitle); SET(informativeText); -#undef SET - if (identifier) { - n.userInfo = @{@"user_id": @(identifier)}; - } - [center deliverNotification:n]; + // Configure the notification's payload. + UNMutableNotificationContent* content = [[UNMutableNotificationContent alloc] init]; + content.title = @(title); + content.sound = [UNNotificationSound defaultSound]; + + // Deliver the notification in five seconds. + UNTimeIntervalNotificationTrigger* trigger = [UNTimeIntervalNotificationTrigger + triggerWithTimeInterval:5 repeats:NO]; + UNNotificationRequest* request = [UNNotificationRequest requestWithIdentifier:@"FiveSecond" + content:content trigger:trigger]; + + [center addNotificationRequest:request withCompletionHandler:NULL]; Py_RETURN_NONE; } diff --git a/setup.py b/setup.py index bd924ed8738..c485eb6d3a5 100755 --- a/setup.py +++ b/setup.py @@ -330,7 +330,7 @@ def kitty_env() -> Env: at_least_version('harfbuzz', 1, 5) cflags.extend(pkg_config('libpng', '--cflags-only-I')) if is_macos: - font_libs = ['-framework', 'CoreText', '-framework', 'CoreGraphics'] + font_libs = ['-framework', 'CoreText', '-framework', 'CoreGraphics', '-framework', 'UserNotifications'] # Apple deprecated OpenGL in Mojave (10.14) silence the endless # warnings about it cppflags.append('-DGL_SILENCE_DEPRECATION')