diff options
author | koekeishiya <aasvi93@hotmail.com> | 2020-05-02 23:42:37 +0200 |
---|---|---|
committer | koekeishiya <aasvi93@hotmail.com> | 2020-05-02 23:43:39 +0200 |
commit | 1fbce35a78563f915f3699724623295020f66167 (patch) | |
tree | 54a875804bfa4992a03a7bafdc8189e33d9597a6 /src/notify.c | |
parent | 5f4761acaae0443f293b3f95c4bd3bda171ec3fb (diff) | |
download | skhd-1fbce35a78563f915f3699724623295020f66167.tar.gz skhd-1fbce35a78563f915f3699724623295020f66167.zip |
send notification from C
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); +} |