3 * $Id: xshutdown.c,v 1.3 1998/11/30 22:36:49 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 /*----- Revision history --------------------------------------------------*
31 * $Log: xshutdown.c,v $
32 * Revision 1.3 1998/11/30 22:36:49 mdw
33 * Tidy up tabbing in help texts very slightly.
35 * Revision 1.2 1998/11/21 22:30:23 mdw
36 * Support GNU-style long options throughout, and introduce proper help
37 * text to all programs. Update manual pages to match.
39 * Revision 1.1 1998/11/16 23:00:49 mdw
44 /*----- Header files ------------------------------------------------------*/
51 #include <X11/Xutil.h>
54 #include <gdk/gdkprivate.h>
60 /*----- Static variables --------------------------------------------------*/
62 static char *atom = XWAIT_DIE;
63 static char *msg = XWAIT_DIE_MSG;
65 static Atom xwait_die;
67 /*----- Main code ---------------------------------------------------------*/
71 * Just end the main loop.
74 static void cancel(GtkWidget *w, gpointer *p)
81 * Send the xwait process a message.
84 static void ok(GtkWidget *w, gpointer *p)
87 XStringListToTextProperty(&msg, 1, &prop);
88 XSetTextProperty(gdk_display, DefaultRootWindow(gdk_display),
93 /* --- @version@ --- */
95 static void version(FILE *fp)
97 fprintf(fp, "%s (xtoys version " VERSION ")\n", QUIS);
100 /* --- @usage@ --- */
102 static void usage(FILE *fp)
104 fprintf(fp, "Usage: %s [-a ATOM] [-m MSG] [-p PROMPT] [-t TITLE]\n", QUIS);
112 int main(int argc, char *argv[])
114 char *prompt = "Are you sure you want to shut down this session?";
115 char *title = "xshutdown";
117 gtk_init(&argc, &argv);
119 /* --- Parse options --- */
122 static struct option opt[] = {
123 { "help", 0, 0, 'h' },
124 { "usage", 0, 0, 'u' },
125 { "version", 0, 0, 'v' },
126 { "atom", required_argument, 0, 'a' },
127 { "msg", required_argument, 0, 'm' },
128 { "prompt", required_argument, 0, 'p' },
129 { "title", required_argument, 0, 't' },
134 i = getopt_long(argc, argv, "huv a:m:p:t:", opt, 0);
146 "Kills a waiting `xwait' process. Pops up a confirmation window first.\n"
148 "Options available are:\n"
150 "-h, --help Display this help text\n"
151 "-u, --usage Display a short usage summary\n"
152 "-v, --version Display the program's version number\n"
154 "-a, --atom=ATOM\t Select the atom that `xwait' is waiting for\n"
155 "-m, --msg=MSG Select the message to send to `xwait'\n"
156 "-p, --prompt=PROMPT Select the prompt string in the confirmation box\n"
157 "-t, --title=TITLE Select the title string in the confirmation box\n",
188 xwait_die = XInternAtom(gdk_display, atom, False);
190 /* --- Decide whether there's an xwait listening --- *
192 * If not, pop up an error box and quit.
198 if (!XGetTextProperty(gdk_display, DefaultRootWindow(gdk_display),
201 GtkWidget *win = gtk_dialog_new();
204 /* --- Make the main window --- */
206 gtk_window_set_title(GTK_WINDOW(win), "xshutdown");
207 gtk_signal_connect(GTK_OBJECT(win), "destroy",
208 GTK_SIGNAL_FUNC(cancel), 0);
210 gtk_box_set_homogeneous(GTK_BOX(GTK_DIALOG(win)->action_area), 0);
212 /* --- Make the label --- */
214 sprintf(buf, "no xwait listening for `%s'\n", atom);
215 w = gtk_label_new(buf);
216 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(win)->vbox), w, 1, 1, 0);
217 gtk_misc_set_padding(GTK_MISC(w), 8, 8);
220 /* --- Make the little button --- */
222 w = gtk_button_new_with_label("OK");
223 gtk_box_pack_end(GTK_BOX(GTK_DIALOG(win)->action_area), w, 0, 0, 0);
224 GTK_WIDGET_SET_FLAGS(w, GTK_CAN_DEFAULT);
225 gtk_widget_grab_default(w);
226 gtk_signal_connect(GTK_OBJECT(w), "clicked",
227 GTK_SIGNAL_FUNC(cancel), 0);
230 /* --- Make everything work --- */
232 gtk_widget_show(win);
238 /* --- Main code --- */
244 /* --- Make the main dialogue box --- */
246 win = gtk_dialog_new();
247 gtk_window_set_title(GTK_WINDOW(win), title);
248 gtk_signal_connect(GTK_OBJECT(win), "destroy",
249 GTK_SIGNAL_FUNC(cancel), 0);
251 gtk_box_set_homogeneous(GTK_BOX(GTK_DIALOG(win)->action_area), 0);
253 /* --- Make the prompt label --- */
255 w = gtk_label_new(prompt);
256 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(win)->vbox), w, 1, 1, 0);
257 gtk_misc_set_padding(GTK_MISC(w), 8, 8);
260 /* --- Make the OK button --- */
262 w = gtk_button_new_with_label("OK");
263 gtk_box_pack_end(GTK_BOX(GTK_DIALOG(win)->action_area), w, 0, 0, 0);
264 gtk_signal_connect(GTK_OBJECT(w), "clicked", GTK_SIGNAL_FUNC(ok), 0);
265 GTK_WIDGET_SET_FLAGS(w, GTK_CAN_DEFAULT);
267 gtk_widget_grab_default(w);
269 /* --- And the cancel button --- */
271 w = gtk_button_new_with_label("Cancel");
272 gtk_box_pack_end(GTK_BOX(GTK_DIALOG(win)->action_area), w, 0, 0, 0);
273 gtk_signal_connect(GTK_OBJECT(w), "clicked", GTK_SIGNAL_FUNC(cancel), 0);
274 GTK_WIDGET_SET_FLAGS(w, GTK_CAN_DEFAULT);
277 /* --- Show the completed window --- */
279 gtk_widget_show(win);
282 /* --- Let rip --- */
288 /*----- That's all, folks -------------------------------------------------*/