X-Git-Url: https://git.distorted.org.uk/~mdw/xtoys/blobdiff_plain/01a2fe8e4dc87fdb256d95504482acf0fb06b67b..c3d5f88d49ba3dbb7c2f44d5861206f273dd2924:/xatom.c diff --git a/xatom.c b/xatom.c index 826085c..0e486bb 100644 --- a/xatom.c +++ b/xatom.c @@ -35,9 +35,7 @@ #include #include -#include #include -#include #include #include @@ -48,7 +46,7 @@ /*----- Static variables --------------------------------------------------*/ -static Display *display = 0; +static Display *dpy = 0; static Window window = None; /*----- Command implementations -------------------------------------------*/ @@ -64,10 +62,10 @@ static int c_get(int argc, char **argv) if (argc != 2) die(EXIT_FAILURE, "Usage: get PROPERTY"); - if ((p = XInternAtom(display, argv[1], True)) == None || - (a = xatom_get(display, window, p)) == None) + if ((p = XInternAtom(dpy, argv[1], True)) == None || + (a = xatom_get(dpy, window, p)) == None) return (0); - name = XGetAtomName(display, a); + name = XGetAtomName(dpy, a); puts(name); return (0); } @@ -78,9 +76,9 @@ static int c_set(int argc, char **argv) if (argc != 3) die(EXIT_FAILURE, "Usage: set PROPERTY VALUE"); - p = XInternAtom(display, argv[1], False); - a = XInternAtom(display, argv[2], False); - xatom_set(display, window, p, a); + p = XInternAtom(dpy, argv[1], False); + a = XInternAtom(dpy, argv[2], False); + xatom_set(dpy, window, p, a); return (0); } @@ -90,9 +88,9 @@ static int c_delete(int argc, char **argv) if (argc != 2) die(EXIT_FAILURE, "Usage: delete PROPERTY"); - if ((p = XInternAtom(display, argv[1], True)) == None) + if ((p = XInternAtom(dpy, argv[1], True)) == None) return (0); - xatom_delete(display, window, p); + xatom_delete(dpy, window, p); return (0); } @@ -105,16 +103,16 @@ static int c_wait(int argc, char **argv) if (argc < 2) die(EXIT_FAILURE, "Usage: wait PROPERTY [VALUE...]"); - p = XInternAtom(display, argv[1], False); + p = XInternAtom(dpy, argv[1], False); n = argc - 2; if (n) { aa = xmalloc(n * sizeof(Atom)); - XInternAtoms(display, argv + 2, n, False, aa); + XInternAtoms(dpy, argv + 2, n, False, aa); } - a = xatom_wait(display, window, p, aa, n); + a = xatom_wait(dpy, window, p, aa, n); if (n != 1) { - name = XGetAtomName(display, a); + name = XGetAtomName(dpy, a); puts(name); XFree(name); } @@ -136,11 +134,11 @@ static int c_wait(int argc, char **argv) static Window choosewindow(void) { - Cursor cross = XCreateFontCursor(display, XC_crosshair); + Cursor cross = XCreateFontCursor(dpy, XC_crosshair); XEvent event; - XGrabPointer(display, - DefaultRootWindow(display), + XGrabPointer(dpy, + DefaultRootWindow(dpy), False, ButtonPressMask, GrabModeAsync, @@ -150,19 +148,19 @@ static Window choosewindow(void) CurrentTime); for (;;) { - XNextEvent(display, &event); + XNextEvent(dpy, &event); switch (event.type) { case ButtonPress: switch (event.xbutton.button) { case 3: - XUngrabPointer(display, event.xbutton.time); + XUngrabPointer(dpy, event.xbutton.time); die(EXIT_FAILURE, "aborted window selection"); break; case 1: window = event.xbutton.subwindow; if (window == None) window = event.xbutton.window; - XUngrabPointer(display, event.xbutton.time); + XUngrabPointer(dpy, event.xbutton.time); return (window); } break; @@ -235,12 +233,12 @@ const struct cmd *findcmd(const char *name) for (c = cmds; c->name; c++) { if (strncmp(name, c->name, sz) == 0) { if (c->name[sz] == 0) { - chosen = c; - break; + chosen = c; + break; } else if (chosen) - die(EXIT_FAILURE, "ambiguous command name `%s'", name); + die(EXIT_FAILURE, "ambiguous command name `%s'", name); else - chosen = c; + chosen = c; } } if (!chosen) @@ -296,7 +294,7 @@ The following subcommands are understood:\n\n", int main(int argc, char *argv[]) { - const char *dpy = 0; + const char *display = 0; const char *win = 0; unsigned f = 0; @@ -308,10 +306,10 @@ int main(int argc, char *argv[]) for (;;) { static struct option opt[] = { - { "help", 0, 0, 'h' }, - { "usage", 0, 0, 'u' }, - { "version", 0, 0, 'v' }, - { "display", OPTF_ARGREQ, 0, 'd' }, + { "help", 0, 0, 'h' }, + { "usage", 0, 0, 'u' }, + { "version", 0, 0, 'v' }, + { "display", OPTF_ARGREQ, 0, 'd' }, { "window", OPTF_ARGREQ, 0, 'w' }, { 0, 0, 0, 0 } }; @@ -322,7 +320,7 @@ int main(int argc, char *argv[]) case 'h': help(argv + optind); exit(0); case 'u': usage(stdout); exit(0); case 'v': version(); exit(0); - case 'd': dpy = optarg; break; + case 'd': display = optarg; break; case 'w': win = optarg; break; default: f |= F_BOGUS; break; } @@ -335,13 +333,13 @@ int main(int argc, char *argv[]) /* --- Initialize --- */ autoreap(); - if ((display = XOpenDisplay(dpy)) == 0) + if ((dpy = XOpenDisplay(display)) == 0) die(EXIT_FAILURE, "couldn't open display"); /* --- Select a target window --- */ if (!win) - window = DefaultRootWindow(display); + window = DefaultRootWindow(dpy); else if (strcmp(win, "choose") == 0) window = choosewindow(); else