diff options
author | Anselm R Garbe <garbeam@gmail.com> | 2008-06-17 10:29:33 +0100 |
---|---|---|
committer | Anselm R Garbe <garbeam@gmail.com> | 2008-06-17 10:29:33 +0100 |
commit | b0a608b5385f53252de9508f250592880ef479e9 (patch) | |
tree | 2a4ebeb3ab756fb30ad0701fc67f1ca54b15b069 /wmname.c | |
parent | 5fcac5aad79988fd242f475ef278278167a7cd33 (diff) | |
download | wmname-b0a608b5385f53252de9508f250592880ef479e9.tar.gz wmname-b0a608b5385f53252de9508f250592880ef479e9.zip |
updated
Diffstat (limited to 'wmname.c')
-rw-r--r-- | wmname.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/wmname.c b/wmname.c new file mode 100644 index 0000000..924e247 --- /dev/null +++ b/wmname.c @@ -0,0 +1,53 @@ +/* See LICENSE file for details. */ +#include <stdarg.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <X11/Xlib.h> +#include <X11/Xatom.h> +#include <X11/Xutil.h> + +void +eprint(const char *errstr, ...) { + va_list ap; + + va_start(ap, errstr); + vfprintf(stderr, errstr, ap); + va_end(ap); + exit(EXIT_FAILURE); +} + +int +main(int argc, char **argv) { + int status, format; + unsigned char *data = NULL; + unsigned long n, extra; + Display *dpy; + Window root; + Atom netwmcheck, netwmname, utf8_string, real; + + if(argc > 2) + eprint("usage: setwmname [name] [-v]\n"); + else if(argc == 2 && !strncmp(argv[1], "-v", 3)) + eprint("setwmname-"VERSION", © 2008 Anselm R Garbe\n", stdout); + + if(!(dpy = XOpenDisplay(0))) + eprint("setwmname: cannot open display\n"); + root = DefaultRootWindow(dpy); + netwmcheck = XInternAtom(dpy, "_NET_SUPPORTING_WM_CHECK", False); + netwmname = XInternAtom(dpy, "_NET_WM_NAME", False); + utf8_string = XInternAtom(dpy, "UTF8_STRING", False); + if(argc == 1) { + status = XGetWindowProperty(dpy, root, netwmname, 0L, 32L, False, utf8_string, &real, &format, &n, &extra, (unsigned char **) &data); + if(status == Success && data != NULL) + fprintf(stdout, "%s\n", data); + XFree(data); + } + else { + XChangeProperty(dpy, root, netwmcheck, XA_WINDOW, 32, PropModeReplace, (unsigned char *)&root, 1); + XChangeProperty(dpy, root, netwmname, utf8_string, 8, PropModeReplace, (unsigned char *)argv[1], strlen(argv[1])); + } + XSync(dpy, False); + XCloseDisplay(dpy); + return 0; +} |