sprop

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

commit 252bd2ad8faa0015098143a07646e8bb199f4c32
parent 9f17757f032db8860ea2e33abb09d92783089aa4
Author: Connor Lane Smith <cls@lubutu.com>
Date:   Mon,  9 Aug 2010 11:55:02 +0100

utf8 + display check
Diffstat:
sprop.c | 41++++++++++++++++++++++-------------------
1 file changed, 22 insertions(+), 19 deletions(-)

diff --git a/sprop.c b/sprop.c @@ -4,30 +4,34 @@ #include <X11/Xlib.h> #include <X11/Xatom.h> -static char *getatom(Atom atom); -static void setatom(Atom atom, char *value); +static char *getprop(Atom atom); +static void setprop(Atom atom, char *value); +static Atom utf8; static Display *dpy; static Window win; int main(int argc, char *argv[]) { - Atom atom; char *value = NULL; + Atom atom; - dpy = XOpenDisplay(NULL); - + if(!(dpy = XOpenDisplay(NULL))) { + fputs("sprop: cannot open display\n", stderr); + return 1; + } switch(argc) { case 4: value = argv[3]; case 3: atom = XInternAtom(dpy, argv[2], True); - win = atoi(argv[1]); + utf8 = XInternAtom(dpy, "UTF8_STRING", True); + win = atol(argv[1]); break; case 2: if(!strcmp(argv[1], "-v")) { - printf("sprop-"VERSION", © 2010 Connor Lane Smith\n"); + fputs("sprop-"VERSION", © 2010 Connor Lane Smith\n", stdout); return 0; } default: @@ -35,10 +39,10 @@ main(int argc, char *argv[]) return 1; } if(value) - setatom(atom, value); + setprop(atom, value); else { - if(!(value = getatom(atom))) { - fprintf(stderr, "sprop: cannot get atom\n"); + if(!(value = getprop(atom))) { + fputs("sprop: cannot get atom\n", stderr); return 1; } printf("%s\n", value); @@ -49,21 +53,20 @@ main(int argc, char *argv[]) } char * -getatom(Atom atom) +getprop(Atom atom) { - Atom adummy; - int idummy; - unsigned long ldummy; + int di; + unsigned long dl; unsigned char *p = NULL; + Atom da; - XGetWindowProperty(dpy, win, atom, 0, BUFSIZ, False, XA_STRING, - &adummy, &idummy, &ldummy, &ldummy, &p); + XGetWindowProperty(dpy, win, atom, 0, BUFSIZ, False, utf8, &da, &di, &dl, &dl, &p); return (char *)p; } void -setatom(Atom atom, char *value) +setprop(Atom atom, char *value) { - XChangeProperty(dpy, win, atom, XA_STRING, 8, PropModeReplace, - (unsigned char *)value, strlen(value) + 1); + XChangeProperty(dpy, win, atom, utf8, 8, PropModeReplace, + (unsigned char *)value, strlen(value)); }