From eb51ef01a4bd8bd7bea61a0a5fd524f66cf276cd Mon Sep 17 00:00:00 2001 From: Tommaso Negri Date: Tue, 11 Aug 2026 18:19:02 +0200 Subject: add additional daemons --- daemons/batteryd.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 daemons/batteryd.c (limited to 'daemons/batteryd.c') diff --git a/daemons/batteryd.c b/daemons/batteryd.c new file mode 100644 index 0000000..48e21b3 --- /dev/null +++ b/daemons/batteryd.c @@ -0,0 +1,45 @@ +// batteryd — battery daemon for bar +// +// Uses IOKit to listen for power source changes (battery level, charging +// state, AC plug/unplug) and posts a Darwin notification. +// +// Compile: +// cc -o bar-batteryd daemons/batteryd.c \ +// -framework IOKit -framework CoreFoundation + +#include +#include +#include +#include +#include +#include +#include + +static volatile int keep_running = 1; + +static void handle_signal(int sig) { + (void)sig; + keep_running = 0; +} + +static void power_source_changed(void *context) { + (void)context; + notify_post("bar.touch."); +} + +int main(void) { + signal(SIGINT, handle_signal); + signal(SIGTERM, handle_signal); + + CFRunLoopSourceRef source = IOPSNotificationCreateRunLoopSource(power_source_changed, NULL); + if (source) { + CFRunLoopAddSource(CFRunLoopGetCurrent(), source, kCFRunLoopDefaultMode); + CFRelease(source); + } + + while (keep_running) { + pause(); + } + + return 0; +} -- cgit v1.2.3