From 1fbce35a78563f915f3699724623295020f66167 Mon Sep 17 00:00:00 2001 From: koekeishiya Date: Sat, 2 May 2020 23:42:37 +0200 Subject: send notification from C --- src/notify.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/notify.c 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); +} -- cgit v1.2.3