/* -*-c-*-
*
- * $Id: xshutdown.c,v 1.6 1998/12/11 09:51:51 mdw Exp $
+ * $Id: xshutdown.c,v 1.9 2004/04/08 01:36:29 mdw Exp $
*
* Pretty GTK interface to waking up an xwait
*
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-/*----- Revision history --------------------------------------------------*
- *
- * $Log: xshutdown.c,v $
- * Revision 1.6 1998/12/11 09:51:51 mdw
- * Use mgLib's `msg' box rather than doing things the hard way.
- *
- * Revision 1.5 1998/12/03 01:00:19 mdw
- * Honour escape presses in the dialogue boxes.
- *
- * Revision 1.4 1998/12/03 00:39:45 mdw
- * Force focus when starting up.
- *
- * Revision 1.3 1998/11/30 22:36:49 mdw
- * Tidy up tabbing in help texts very slightly.
- *
- * Revision 1.2 1998/11/21 22:30:23 mdw
- * Support GNU-style long options throughout, and introduce proper help
- * text to all programs. Update manual pages to match.
- *
- * Revision 1.1 1998/11/16 23:00:49 mdw
- * Initial versions.
- *
- */
-
/*----- Header files ------------------------------------------------------*/
#include <stdio.h>
#include <mLib/mdwopt.h>
#include <mLib/quis.h>
+#include <mLib/report.h>
#include <mgLib/msg.h>
+#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@ --- */
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@ --- *
int main(int argc, char *argv[])
{
- char *prompt = "Are you sure you want to shut down this session?";
- char *title = "xshutdown";
+ const char *atom = XWAIT_DIE;
+ const char *xmsg = XWAIT_DIE_MSG;
+ Atom xa, xm;
+
+ const char *prompt = "Are you sure you want to shut down this session?";
+ const char *title;
ego(argv[0]);
gtk_init(&argc, &argv);
/* --- Parse options --- */
+ title = QUIS;
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;
"-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);
}
}
- 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(QUIS, "!:~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(title, "!:OK,~Cancel", "%s", prompt) == 0)
+ xatom_set(gdk_display, DefaultRootWindow(gdk_display), xa, xm);
return (0);
}