3 * $Id: xshutdown.c,v 1.9 2004/04/08 01:36:29 mdw Exp $
5 * Pretty GTK interface to waking up an xwait
7 * (c) 1998 Straylight/Edgeware
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of the Edgeware X tools collection.
14 * X tools is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * X tools is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with X tools; if not, write to the Free Software Foundation,
26 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 /*----- Header files ------------------------------------------------------*/
36 #include <X11/Xutil.h>
39 #include <gdk/gdkprivate.h>
40 #include <gdk/gdkkeysyms.h>
42 #include <mLib/mdwopt.h>
43 #include <mLib/quis.h>
44 #include <mLib/report.h>
46 #include <mgLib/msg.h>
51 /*----- Main code ---------------------------------------------------------*/
53 /* --- @version@ --- */
55 static void version(FILE *fp
)
57 fprintf(fp
, "%s (xtoys version " VERSION
")\n", QUIS
);
62 static void usage(FILE *fp
)
64 fprintf(fp
, "Usage: %s [-p PROMPT] [-t TITLE] [ATOM:MSG]\n", QUIS
);
72 int main(int argc
, char *argv
[])
74 const char *atom
= XWAIT_DIE
;
75 const char *xmsg
= XWAIT_DIE_MSG
;
78 const char *prompt
= "Are you sure you want to shut down this session?";
81 gtk_init(&argc
, &argv
);
83 /* --- Parse options --- */
87 static struct option opt
[] = {
88 { "help", 0, 0, 'h' },
89 { "usage", 0, 0, 'u' },
90 { "version", 0, 0, 'v' },
91 { "atom", OPTF_ARGREQ
, 0, 'a' },
92 { "msg", OPTF_ARGREQ
, 0, 'm' },
93 { "prompt", OPTF_ARGREQ
, 0, 'p' },
94 { "title", OPTF_ARGREQ
, 0, 't' },
99 i
= getopt_long(argc
, argv
, "huv a:m:p:t:", opt
, 0);
111 "Kills a waiting `xwait' process. Pops up a confirmation window first.\n"
113 "Options available are:\n"
115 "-h, --help Display this help text\n"
116 "-u, --usage Display a short usage summary\n"
117 "-v, --version Display the program's version number\n"
119 "-a, --atom=ATOM\t Select the property name atom [deprecated]\n"
120 "-m, --msg=MSG Select the message to send [deprecated]\n"
121 "-p, --prompt=PROMPT Select the prompt string in the confirmation box\n"
122 "-t, --title=TITLE Select the title string in the confirmation box\n",
155 if ((atom
= strtok(argv
[optind
++], ":")) == 0)
156 die(EXIT_FAILURE
, "missing atom name");
157 if ((p
= strtok(0, ",")) != 0)
166 xa
= XInternAtom(gdk_display
, atom
, False
);
167 xm
= XInternAtom(gdk_display
, xmsg
, False
);
169 /* --- Decide whether there's an xwait listening --- *
171 * If not, pop up an error box and quit.
174 if (xatom_get(gdk_display
, DefaultRootWindow(gdk_display
), xa
) == None
) {
175 msg(QUIS
, "!:~OK", "no xwait listening for `%s'", atom
);
179 /* --- Main code --- */
181 if (msg(title
, "!:OK,~Cancel", "%s", prompt
) == 0)
182 xatom_set(gdk_display
, DefaultRootWindow(gdk_display
), xa
, xm
);
187 /*----- That's all, folks -------------------------------------------------*/