sprop

simple xprop replacement
git clone git://git.suckless.org/sprop
Log | Files | Refs | README | LICENSE

commit 2aae9d8ed744b37d002871f2f001170b7cfa21bb
Author: arg@localhost.localdomain <unknown>
Date:   Wed,  7 Apr 2010 10:02:16 +0000

initial commit
Diffstat:
sprop.c | 63+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 63 insertions(+), 0 deletions(-)

diff --git a/sprop.c b/sprop.c @@ -0,0 +1,63 @@ +#include <stdio.h> +#include <string.h> +#include <X11/Xlib.h> +#include <X11/Xatom.h> + +static char *getatom(Atom atom); +static void setatom(Atom atom, char *value); + +static Display *dpy; +static Window win; + +int +main(int argc, char *argv[]) +{ + Atom atom; + char *value = NULL; + + dpy = XOpenDisplay(NULL); + + switch(argc) { + case 4: + value = argv[3]; + case 3: + if((atom = XInternAtom(dpy, argv[2], True)) == None) { + fprintf(stderr, "sprop: no such atom\n"); + return 1; + } + win = atoi(argv[1]); + break; + default: + fprintf(stderr, "usage: sprop <xid> <atom> [<value>]\n"); + return 1; + } + if(value) + setatom(atom, value); + else { + value = getatom(atom); + printf("%s\n", value); + XFree(value); + } + XCloseDisplay(dpy); + return 0; +} + +char * +getatom(Atom atom) +{ + Atom adummy; + int idummy; + unsigned long ldummy; + unsigned char *p = NULL; + + XGetWindowProperty(dpy, win, atom, 0, BUFSIZ, False, XA_STRING, + &adummy, &idummy, &ldummy, &ldummy, &p); + return p; +} + +void +setatom(Atom atom, char *value) +{ + XChangeProperty(dpy, win, atom, XA_STRING, 8, PropModeReplace, + (unsigned char *)value, strlen(value) + 1); +}