blob: 9a575642ca5a17b3fab165484160fa7428ff2614 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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;
}
|