diff options
Diffstat (limited to 'src/notify.c')
-rw-r--r-- | src/notify.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/notify.c b/src/notify.c new file mode 100644 index 0000000..a276854 --- /dev/null +++ b/src/notify.c @@ -0,0 +1,23 @@ +void notify_init(void) +{ + class_replaceMethod(objc_getClass("NSBundle"), + sel_registerName("bundleIdentifier"), + method_getImplementation((void *)^{return CFSTR("com.koekeishiya.skhd");}), + NULL); +} + +void notify(char *title, char *message) +{ + CFStringRef title_ref = CFStringCreateWithCString(NULL, title, kCFStringEncodingUTF8); + CFStringRef message_ref = CFStringCreateWithCString(NULL, message, kCFStringEncodingUTF8); + + void *center = objc_msgSend((void *) objc_getClass("NSUserNotificationCenter"), sel_registerName("defaultUserNotificationCenter")); + void *notification = objc_msgSend((void *) objc_getClass("NSUserNotification"), sel_registerName("alloc"), sel_registerName("init")); + + objc_msgSend(notification, sel_registerName("setTitle:"), title_ref); + objc_msgSend(notification, sel_registerName("setInformativeText:"), message_ref); + objc_msgSend(center, sel_registerName("deliverNotification:"), notification); + + CFRelease(message_ref); + CFRelease(title_ref); +} |