X-Git-Url: https://git.distorted.org.uk/~mdw/xtoys/blobdiff_plain/5ac66f5c6c2a9f1ebf035e9deb4a718d117fe3f8..d72bdcdbbe512494f64102d18879a08163f231a3:/xshutdown.c diff --git a/xshutdown.c b/xshutdown.c index c669871..499ff7c 100644 --- a/xshutdown.c +++ b/xshutdown.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: xshutdown.c,v 1.6 1998/12/11 09:51:51 mdw Exp $ + * $Id: xshutdown.c,v 1.7 1999/08/20 07:29:19 mdw Exp $ * * Pretty GTK interface to waking up an xwait * @@ -29,6 +29,9 @@ /*----- Revision history --------------------------------------------------* * * $Log: xshutdown.c,v $ + * Revision 1.7 1999/08/20 07:29:19 mdw + * New command line syntax, and new atom protocol. + * * Revision 1.6 1998/12/11 09:51:51 mdw * Use mgLib's `msg' box rather than doing things the hard way. * @@ -65,18 +68,13 @@ #include #include +#include #include +#include "xatom.h" #include "xwait.h" -/*----- Static variables --------------------------------------------------*/ - -static char *atom = XWAIT_DIE; -static char *xmsg = XWAIT_DIE_MSG; - -static Atom xwait_die; - /*----- Main code ---------------------------------------------------------*/ /* --- @version@ --- */ @@ -90,7 +88,7 @@ static void version(FILE *fp) static void usage(FILE *fp) { - fprintf(fp, "Usage: %s [-a ATOM] [-m MSG] [-p PROMPT] [-t TITLE]\n", QUIS); + fprintf(fp, "Usage: %s [-p PROMPT] [-t TITLE] [ATOM:MSG]\n", QUIS); } /* --- @main@ --- * @@ -100,6 +98,10 @@ static void usage(FILE *fp) int main(int argc, char *argv[]) { + char *atom = XWAIT_DIE; + char *xmsg = XWAIT_DIE_MSG; + Atom xa, xm; + char *prompt = "Are you sure you want to shut down this session?"; char *title = "xshutdown"; ego(argv[0]); @@ -109,14 +111,14 @@ int main(int argc, char *argv[]) for (;;) { static struct option opt[] = { - { "help", 0, 0, 'h' }, - { "usage", 0, 0, 'u' }, - { "version", 0, 0, 'v' }, - { "atom", required_argument, 0, 'a' }, - { "msg", required_argument, 0, 'm' }, - { "prompt", required_argument, 0, 'p' }, - { "title", required_argument, 0, 't' }, - { 0, 0, 0, 0 } + { "help", 0, 0, 'h' }, + { "usage", 0, 0, 'u' }, + { "version", 0, 0, 'v' }, + { "atom", OPTF_ARGREQ, 0, 'a' }, + { "msg", OPTF_ARGREQ, 0, 'm' }, + { "prompt", OPTF_ARGREQ, 0, 'p' }, + { "title", OPTF_ARGREQ, 0, 't' }, + { 0, 0, 0, 0 } }; int i; @@ -140,8 +142,8 @@ int main(int argc, char *argv[]) "-u, --usage Display a short usage summary\n" "-v, --version Display the program's version number\n" "\n" -"-a, --atom=ATOM\t Select the atom that `xwait' is waiting for\n" -"-m, --msg=MSG Select the message to send to `xwait'\n" +"-a, --atom=ATOM\t Select the property name atom [deprecated]\n" +"-m, --msg=MSG Select the message to send [deprecated]\n" "-p, --prompt=PROMPT Select the prompt string in the confirmation box\n" "-t, --title=TITLE Select the title string in the confirmation box\n", stdout); @@ -174,31 +176,36 @@ int main(int argc, char *argv[]) } } - xwait_die = XInternAtom(gdk_display, atom, False); + if (optind < argc) { + char *p; + if ((atom = strtok(argv[optind++], ":")) == 0) + die(EXIT_FAILURE, "missing atom name"); + if ((p = strtok(0, ",")) != 0) + xmsg = p; + } + + if (optind < argc) { + usage(stderr); + exit(EXIT_FAILURE); + } + + xa = XInternAtom(gdk_display, atom, False); + xm = XInternAtom(gdk_display, xmsg, False); /* --- Decide whether there's an xwait listening --- * * * If not, pop up an error box and quit. */ - { - XTextProperty prop; - - if (!XGetTextProperty(gdk_display, DefaultRootWindow(gdk_display), - &prop, xwait_die)) { - msg("!:~OK", "no xwait listening for `%s'", atom); - exit(EXIT_FAILURE); - } + if (xatom_get(gdk_display, DefaultRootWindow(gdk_display), xa) == None) { + msg("!:~OK", "no xwait listening for `%s'", atom); + exit(EXIT_FAILURE); } /* --- Main code --- */ - if (msg("!:OK,~Cancel", "%s", prompt) == 0) { - XTextProperty prop; - XStringListToTextProperty(&xmsg, 1, &prop); - XSetTextProperty(gdk_display, DefaultRootWindow(gdk_display), - &prop, xwait_die); - } + if (msg("!:OK,~Cancel", "%s", prompt) == 0) + xatom_set(gdk_display, DefaultRootWindow(gdk_display), xa, xm); return (0); }