seturgent.c - seturgent - set urgency hints for X applications
(HTM) git clone git://git.codemadness.org/seturgent
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
seturgent.c (1366B)
---
1 /* See LICENSE file for copyright and license details. */
2
3 #include <stdio.h>
4 #include <string.h>
5 #include <stdlib.h>
6 #include <X11/Xlib.h>
7 #include <X11/Xutil.h>
8
9 static void
10 die(const char *s)
11 {
12 fputs(s, stderr);
13 exit(EXIT_FAILURE);
14 }
15
16 static int
17 seturgency(Display *dpy, Window winid, Bool set)
18 {
19 int ret = EXIT_SUCCESS;
20 XWMHints *hints = XGetWMHints(dpy, winid);
21 if (!hints) {
22 fputs("seturgent: unable to get window manager hints.\n", stderr);
23 return EXIT_FAILURE;
24 }
25 if (set)
26 hints->flags |= XUrgencyHint;
27 else
28 hints->flags &= ~XUrgencyHint;
29 if (!XSetWMHints(dpy, winid, hints)) {
30 fputs("seturgent: unable to set urgency hint.\n", stderr);
31 ret = EXIT_FAILURE;
32 }
33 XFree(hints);
34
35 return ret;
36 }
37
38 int
39 main(int argc, char **argv)
40 {
41 Display *dpy;
42 int ret = EXIT_SUCCESS;
43
44 if (argc < 2 || !strcmp(argv[1], "-h")) /* help / usage */
45 die("Usage: seturgent <winid> [0|1]\n");
46 if (argc == 2 && !strcmp(argv[1], "-v")) /* version */
47 die("seturgent-"VERSION" © 2010-2017 seturgent engineer, see " \
48 "LICENSE file for details.\n");
49 if (!(dpy = XOpenDisplay(NULL)))
50 die("seturgent: unable to open display.\n");
51 /* set the urgency hint (or not), if not specified its True. */
52 ret = seturgency(dpy, (Window)strtol(argv[1], NULL, 0),
53 !((argc > 2) && !atol(argv[2])));
54 XSync(dpy, False);
55 XCloseDisplay(dpy);
56
57 return ret;
58 }