3 * $Id: xshutdown.c,v 1.4 1998/12/03 00:39:45 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.4 1998/12/03 00:39:45 mdw
33 * Force focus when starting up.
35 * Revision 1.3 1998/11/30 22:36:49 mdw
36 * Tidy up tabbing in help texts very slightly.
38 * Revision 1.2 1998/11/21 22:30:23 mdw
39 * Support GNU-style long options throughout, and introduce proper help
40 * text to all programs. Update manual pages to match.
42 * Revision 1.1 1998/11/16 23:00:49 mdw
47 /*----- Header files ------------------------------------------------------*/
54 #include <X11/Xutil.h>
57 #include <gdk/gdkprivate.h>
64 /*----- Static variables --------------------------------------------------*/
66 static char *atom
= XWAIT_DIE
;
67 static char *msg
= XWAIT_DIE_MSG
;
69 static Atom xwait_die
;
71 /*----- Main code ---------------------------------------------------------*/
75 * Just end the main loop.
78 static void cancel(GtkWidget
*w
, gpointer
*p
)
85 * Send the xwait process a message.
88 static void ok(GtkWidget
*w
, gpointer
*p
)
91 XStringListToTextProperty(&msg
, 1, &prop
);
92 XSetTextProperty(gdk_display
, DefaultRootWindow(gdk_display
),
97 /* --- @version@ --- */
99 static void version(FILE *fp
)
101 fprintf(fp
, "%s (xtoys version " VERSION
")\n", QUIS
);
104 /* --- @usage@ --- */
106 static void usage(FILE *fp
)
108 fprintf(fp
, "Usage: %s [-a ATOM] [-m MSG] [-p PROMPT] [-t TITLE]\n", QUIS
);
116 int main(int argc
, char *argv
[])
118 char *prompt
= "Are you sure you want to shut down this session?";
119 char *title
= "xshutdown";
121 gtk_init(&argc
, &argv
);
123 /* --- Parse options --- */
126 static struct option opt
[] = {
127 { "help", 0, 0, 'h' },
128 { "usage", 0, 0, 'u' },
129 { "version", 0, 0, 'v' },
130 { "atom", required_argument
, 0, 'a' },
131 { "msg", required_argument
, 0, 'm' },
132 { "prompt", required_argument
, 0, 'p' },
133 { "title", required_argument
, 0, 't' },
138 i
= getopt_long(argc
, argv
, "huv a:m:p:t:", opt
, 0);
150 "Kills a waiting `xwait' process. Pops up a confirmation window first.\n"
152 "Options available are:\n"
154 "-h, --help Display this help text\n"
155 "-u, --usage Display a short usage summary\n"
156 "-v, --version Display the program's version number\n"
158 "-a, --atom=ATOM\t Select the atom that `xwait' is waiting for\n"
159 "-m, --msg=MSG Select the message to send to `xwait'\n"
160 "-p, --prompt=PROMPT Select the prompt string in the confirmation box\n"
161 "-t, --title=TITLE Select the title string in the confirmation box\n",
192 xwait_die
= XInternAtom(gdk_display
, atom
, False
);
194 /* --- Decide whether there's an xwait listening --- *
196 * If not, pop up an error box and quit.
202 if (!XGetTextProperty(gdk_display
, DefaultRootWindow(gdk_display
),
205 GtkWidget
*win
= gtk_dialog_new();
208 /* --- Make the main window --- */
210 gtk_window_set_title(GTK_WINDOW(win
), "xshutdown");
211 gtk_signal_connect(GTK_OBJECT(win
), "destroy",
212 GTK_SIGNAL_FUNC(cancel
), 0);
214 gtk_box_set_homogeneous(GTK_BOX(GTK_DIALOG(win
)->action_area
), 0);
216 /* --- Make the label --- */
218 sprintf(buf
, "no xwait listening for `%s'\n", atom
);
219 w
= gtk_label_new(buf
);
220 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(win
)->vbox
), w
, 1, 1, 0);
221 gtk_misc_set_padding(GTK_MISC(w
), 8, 8);
224 /* --- Make the little button --- */
226 w
= gtk_button_new_with_label("OK");
227 gtk_box_pack_end(GTK_BOX(GTK_DIALOG(win
)->action_area
), w
, 0, 0, 0);
228 GTK_WIDGET_SET_FLAGS(w
, GTK_CAN_DEFAULT
);
229 gtk_widget_grab_default(w
);
230 gtk_signal_connect(GTK_OBJECT(w
), "clicked",
231 GTK_SIGNAL_FUNC(cancel
), 0);
234 /* --- Make everything work --- */
236 gtk_widget_realize(win
);
238 gtk_widget_show(win
);
244 /* --- Main code --- */
250 /* --- Make the main dialogue box --- */
252 win
= gtk_dialog_new();
253 gtk_window_set_title(GTK_WINDOW(win
), title
);
254 gtk_signal_connect(GTK_OBJECT(win
), "destroy",
255 GTK_SIGNAL_FUNC(cancel
), 0);
257 gtk_box_set_homogeneous(GTK_BOX(GTK_DIALOG(win
)->action_area
), 0);
259 /* --- Make the prompt label --- */
261 w
= gtk_label_new(prompt
);
262 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(win
)->vbox
), w
, 1, 1, 0);
263 gtk_misc_set_padding(GTK_MISC(w
), 8, 8);
266 /* --- Make the OK button --- */
268 w
= gtk_button_new_with_label("OK");
269 gtk_box_pack_end(GTK_BOX(GTK_DIALOG(win
)->action_area
), w
, 0, 0, 0);
270 gtk_signal_connect(GTK_OBJECT(w
), "clicked", GTK_SIGNAL_FUNC(ok
), 0);
271 GTK_WIDGET_SET_FLAGS(w
, GTK_CAN_DEFAULT
);
273 gtk_widget_grab_default(w
);
275 /* --- And the cancel button --- */
277 w
= gtk_button_new_with_label("Cancel");
278 gtk_box_pack_end(GTK_BOX(GTK_DIALOG(win
)->action_area
), w
, 0, 0, 0);
279 gtk_signal_connect(GTK_OBJECT(w
), "clicked", GTK_SIGNAL_FUNC(cancel
), 0);
280 GTK_WIDGET_SET_FLAGS(w
, GTK_CAN_DEFAULT
);
283 /* --- Show the completed window --- */
285 gtk_widget_realize(win
);
287 gtk_widget_show(win
);
290 /* --- Let rip --- */
296 /*----- That's all, folks -------------------------------------------------*/