diff options
author | kostix <kostix@cc602e41-bd33-0410-9637-a208f32f1443> | 2009-01-21 01:31:38 +0000 |
---|---|---|
committer | kostix <kostix@cc602e41-bd33-0410-9637-a208f32f1443> | 2009-01-21 01:31:38 +0000 |
commit | cf928a9b4091b18ecf76aeaa4d2c4baed6364acd (patch) | |
tree | 655fa23feca904b9afe6d7edb343f0b3aabf916f /urgent.c | |
download | urgent-cf928a9b4091b18ecf76aeaa4d2c4baed6364acd.tar.gz urgent-cf928a9b4091b18ecf76aeaa4d2c4baed6364acd.tar.xz urgent-cf928a9b4091b18ecf76aeaa4d2c4baed6364acd.zip |
Added preliminary implementation of the "urgent" plugin
which controls the X Window "urgency" hint on Tkabber
chat windows.
See http://www.jabber.ru/bugzilla/show_bug.cgi?id=389
git-svn-id: http://svn.xmpp.ru/repos/tkabber-3rd-party/trunk/plugins/urgent@166 cc602e41-bd33-0410-9637-a208f32f1443
Diffstat (limited to 'urgent.c')
-rw-r--r-- | urgent.c | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/urgent.c b/urgent.c new file mode 100644 index 0000000..42f01ad --- /dev/null +++ b/urgent.c @@ -0,0 +1,103 @@ +/* + * $Id$ + * + * Compile with + * gcc -L/usr/X11R6/lib -lX11 urgent.c -o urgent + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> +#include <X11/Xlib.h> +#include <X11/Xutil.h> + +typedef long (*FLAGMANIP) (long); + +static long set_urgency(long flags) +{ + return flags | XUrgencyHint; +} + +static long clear_urgency(long flags) +{ + return flags & ~XUrgencyHint; +} + +static long toggle_urgency(long flags) +{ + if ((flags & XUrgencyHint) == 0) { + return set_urgency(flags); + } else { + return clear_urgency(flags); + } +} + +static int apply(Display *dpy, Window id, FLAGMANIP f) +{ + XWMHints *hints = XGetWMHints(dpy, id); + + if (hints == NULL) + return 0; + + hints->flags = f(hints->flags); + + return (XSetWMHints(dpy, id, hints) != 0); +} + +int main(int argc, char *argv[]) +{ + const char helpstr[] = "Usage: urgent {-set|-clear|-toggle} XWINID\n"; + Display *dpy; + Window id; + FLAGMANIP action; + + if (argc == 2 && strcmp(argv[1], "-help") == 0) { + printf("Sets, clears or toggles the \"urgency\" flag " + "for a specified X window using its WM_HINTS property\n"); + printf(helpstr); + return EXIT_SUCCESS; + } + + if (argc != 3) { + fprintf(stderr, "Wrong number of agruments\n"); + fprintf(stderr, helpstr); + return EXIT_FAILURE; + } + + if (strcmp(argv[1], "-set") == 0) { + action = set_urgency; + } else if (strcmp(argv[1], "-clear") == 0) { + action = clear_urgency; + } else if (strcmp(argv[1], "-toggle") == 0) { + action = toggle_urgency; + } else { + fprintf(stderr, "Invalid action \"%s\", " + "must be one of -set, -clear or -toggle\n", argv[1]); + return EXIT_FAILURE; + } + + errno = 0; + id = strtol(argv[2], NULL, 16); + if (errno != 0) { + fprintf(stderr, "Invalid X window id \"%s\", " + "must be a hexadecimal integer\n", argv[2]); + return EXIT_FAILURE; + } + + dpy = XOpenDisplay(NULL); + + if (dpy == NULL) { + fprintf(stderr, "Unable to open display."); + return EXIT_FAILURE; + } + + apply(dpy, id, action); + + XFlush(dpy); + + XCloseDisplay(dpy); + + return EXIT_SUCCESS; +} + |