diff options
| author | Tommaso Negri <me@tommasongr.com> | 2026-08-11 18:19:02 +0200 |
|---|---|---|
| committer | Tommaso Negri <me@tommasongr.com> | 2026-08-11 18:19:02 +0200 |
| commit | eb51ef01a4bd8bd7bea61a0a5fd524f66cf276cd (patch) | |
| tree | d750764614bf1e5125c4a09ba6c72084b6a5772e /daemons/focusd.c | |
| parent | a1d62dd085ac70fc90a05095220156897bdd8f82 (diff) | |
| download | bar-eb51ef01a4bd8bd7bea61a0a5fd524f66cf276cd.tar.gz bar-eb51ef01a4bd8bd7bea61a0a5fd524f66cf276cd.zip | |
add additional daemons
Diffstat (limited to 'daemons/focusd.c')
| -rw-r--r-- | daemons/focusd.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/daemons/focusd.c b/daemons/focusd.c new file mode 100644 index 0000000..9a57564 --- /dev/null +++ b/daemons/focusd.c @@ -0,0 +1,49 @@ +// bar-focusd — Focus / Do Not Disturb daemon for bar +// +// Listens for Focus mode and DND changes via DistributedNotificationCenter +// and posts a Darwin notification. +// +// Compile: +// cc -o bar-focusd daemons/focusd.c -framework CoreFoundation + +#include <CoreFoundation/CoreFoundation.h> +#include <notify.h> +#include <signal.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +static volatile int keep_running = 1; + +static void handle_signal(int sig) { + (void)sig; + keep_running = 0; +} + +static void focus_changed( + CFNotificationCenterRef center, void *observer, + CFStringRef name, const void *object, CFDictionaryRef userInfo +) { + (void)center; (void)observer; (void)name; (void)object; (void)userInfo; + notify_post("bar.touch.<block-name>"); +} + +int main(void) { + signal(SIGINT, handle_signal); + signal(SIGTERM, handle_signal); + + CFNotificationCenterRef center = CFNotificationCenterGetDistributedCenter(); + + // DND / Focus mode changes + CFNotificationCenterAddObserver( + center, NULL, focus_changed, + CFSTR("com.apple.notificationcenter.dndprefs_changed"), + NULL, CFNotificationSuspensionBehaviorDeliverImmediately); + + while (keep_running) { + pause(); + } + + CFNotificationCenterRemoveEveryObserver(center, NULL); + return 0; +} |
