X-Git-Url: https://git.distorted.org.uk/~mdw/xtoys/blobdiff_plain/5ac66f5c6c2a9f1ebf035e9deb4a718d117fe3f8..d72bdcdbbe512494f64102d18879a08163f231a3:/xtell.c diff --git a/xtell.c b/xtell.c index 76d53d3..79f2709 100644 --- a/xtell.c +++ b/xtell.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: xtell.c,v 1.4 1998/12/11 09:50:06 mdw Exp $ + * $Id: xtell.c,v 1.5 1999/08/20 07:29:19 mdw Exp $ * * Wake up a waiting xwait process * @@ -29,6 +29,9 @@ /*----- Revision history --------------------------------------------------* * * $Log: xtell.c,v $ + * Revision 1.5 1999/08/20 07:29:19 mdw + * New command line syntax, and new atom protocol. + * * Revision 1.4 1998/12/11 09:50:06 mdw * Minor modifications to work with mLib and mgLib. * @@ -55,7 +58,9 @@ #include #include +#include +#include "xatom.h" #include "xwait.h" /*----- Main code ---------------------------------------------------------*/ @@ -67,14 +72,14 @@ static void version(FILE *fp) static void usage(FILE *fp) { - fprintf(fp, "Usage: %s [-d DISPLAY] [-a ATOM] [-m MSG]\n", QUIS); + fprintf(fp, "Usage: %s [-d DISPLAY] [ATOM:MSG]\n", QUIS); } int main(int argc, char *argv[]) { char *display = 0; Display *dpy; - Atom xwait_die; + Atom a, m; char *atom = XWAIT_DIE; char *msg = XWAIT_DIE_MSG; @@ -84,16 +89,16 @@ int main(int argc, char *argv[]) for (;;) { static struct option opt[] = { - { "help", 0, 0, 'h' }, - { "usage", 0, 0, 'u' }, - { "version", 0, 0, 'v' }, - { "display", required_argument, 0, 'd' }, - { "atom", required_argument, 0, 'a' }, - { "msg", required_argument, 0, 'm' }, - { 0, 0, 0, 0 } + { "help", 0, 0, 'h' }, + { "usage", 0, 0, 'u' }, + { "version", 0, 0, 'v' }, + { "display", OPTF_ARGREQ, 0, 'd' }, + { "atom", OPTF_ARGREQ, 0, 'a' }, + { "msg", OPTF_ARGREQ, 0, 'm' }, + { 0, 0, 0, 0 } }; - int i = getopt_long(argc, argv, "d:a:m:", opt, 0); + int i = mdwopt(argc, argv, "d:a:m:", opt, 0, 0, 0); if (i < 0) break; switch (i) { @@ -113,8 +118,8 @@ int main(int argc, char *argv[]) "-v, --version Display the program's version number\n" "\n" "-d, --display=DISPLAY Choose X display to connect to\n" -"-a, --atom=ATOM\t Choose property name to set\n" -"-m, --msg=MSG Choose value of property to set\n", +"-a, --atom=ATOM\t Choose property name to set [deprecated]\n" +"-m, --msg=MSG Choose value of property to set [deprecated]\n", stdout); exit(0); break; @@ -137,37 +142,33 @@ int main(int argc, char *argv[]) msg = optarg; break; default: - fprintf(stderr, "Usage: xtell [-d DISPLAY] [-a ATOM] [-m MSG]\n"); + usage(stderr); exit(EXIT_FAILURE); break; } } - /* --- Connect to the display --- */ + if (optind < argc) { + char *p; + if ((atom = strtok(argv[optind++], ":")) == 0) + die(EXIT_FAILURE, "missing atom name"); + if ((p = strtok(0, ",")) != 0) + msg = p; + } - dpy = XOpenDisplay(display); - if (!dpy) { - fprintf(stderr, "xtell: couldn't open display\n"); + if (optind < argc) { + usage(stderr); exit(EXIT_FAILURE); } - /* --- Find the right atom --- */ - - xwait_die = XInternAtom(dpy, atom, False); + /* --- Set the property value and exit --- */ - /* --- Set the property value --- */ - - { - XTextProperty prop; - if (!XGetTextProperty(dpy, DefaultRootWindow(dpy), &prop, xwait_die)) { - fprintf(stderr, "xtell: no xwait listening for `%s'\n", atom); - exit(EXIT_FAILURE); - } - XStringListToTextProperty(&msg, 1, &prop); - XSetTextProperty(dpy, DefaultRootWindow(dpy), &prop, xwait_die); - } + if ((dpy = XOpenDisplay(display)) == 0) + die(EXIT_FAILURE, "couldn't open display"); - /* --- Done --- */ + a = XInternAtom(dpy, atom, False); + m = XInternAtom(dpy, msg, False); + xatom_set(dpy, DefaultRootWindow(dpy), a, m); XCloseDisplay(dpy); return (0);