2 * On-screen Display Client -- Sending Messages
4 * (c) 2010 Martin Mares <mj@ucw.cz>
11 #include <X11/Xatom.h>
19 #define MAX_MSG_SIZE 1024
23 char buf[MAX_MSG_SIZE];
29 dpy = XOpenDisplay(NULL);
31 die("Cannot open display");
33 pty = XInternAtom(dpy, "OSD_QUEUE", False);
35 die("Cannot intern OSD_QUEUE atom");
41 struct osd_msg *msg = xmalloc(sizeof(*msg));
47 osd_add_line(struct osd_msg *msg, char *key, char *val)
51 msg->cnt += snprintf(msg->buf + msg->cnt, MAX_MSG_SIZE - msg->cnt - 1, "%s:%s\n", key, val);
52 if (msg->cnt > MAX_MSG_SIZE - 1)
53 die("OSD message too long (at most %d bytes)", MAX_MSG_SIZE);
57 osd_send(struct osd_msg *msg)
62 msg->buf[msg->cnt++] = '\n';
63 if (!XChangeProperty(dpy, DefaultRootWindow(dpy), pty, XA_STRING, 8, PropModeAppend, (unsigned char *) msg->buf, msg->cnt))
64 die("XChangeProperty failed");