-
Notifications
You must be signed in to change notification settings - Fork 0
/
ipc.c
62 lines (51 loc) · 1.57 KB
/
ipc.c
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
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "ipc.h"
#include "config.h"
#include "util.h"
#include <X11/Xatom.h>
#include <X11/Xlib.h>
#define ATLASWM_COMMAND "_ATLASWM_COMMAND"
Atom command_atom = None;
Atom get_command_atom(Display *dpy) {
return XInternAtom(dpy, ATLASWM_COMMAND, False);
}
void setup_ipc(Display *dpy) {
command_atom = get_command_atom(dpy);
Window root = DefaultRootWindow(dpy);
CommandType initial = 0;
XChangeProperty(dpy, root, command_atom, XA_CARDINAL, 32, PropModeReplace,
(unsigned char *)&initial, 1);
}
int send_command(Display *dpy, CommandType cmd) {
Window root = DefaultRootWindow(dpy);
Atom command_atom = get_command_atom(dpy);
// Check if AtlasWM is running by looking for the command atom
Atom type;
int format;
unsigned long nitems, bytes_after;
unsigned char *data = NULL;
// Try to read the property just to see if it exists
if (XGetWindowProperty(dpy, root, command_atom, 0, 1, False, XA_CARDINAL,
&type, &format, &nitems, &bytes_after,
&data) == Success) {
if (data)
XFree(data);
// Send the command
CommandType cmd_data = cmd;
XChangeProperty(dpy, root, command_atom, XA_CARDINAL, 32, PropModeReplace,
(unsigned char *)&cmd_data, 1);
XFlush(dpy);
return 1;
}
LOG_ERROR("No running instance of AtlasWM found");
return 0;
}
void handle_command(CommandType cmd) {
switch (cmd) {
case CMD_RELOAD:
LOG_INFO("Received reload command");
reload_config();
break;
default:
LOG_ERROR("Unknown command received: %d", cmd);
}
}