3 * $Id: xshutdown.c,v 1.5 1998/12/03 01:00:19 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.5 1998/12/03 01:00:19 mdw
33 * Honour escape presses in the dialogue boxes.
35 * Revision 1.4 1998/12/03 00:39:45 mdw
36 * Force focus when starting up.
38 * Revision 1.3 1998/11/30 22:36:49 mdw
39 * Tidy up tabbing in help texts very slightly.
41 * Revision 1.2 1998/11/21 22:30:23 mdw
42 * Support GNU-style long options throughout, and introduce proper help
43 * text to all programs. Update manual pages to match.
45 * Revision 1.1 1998/11/16 23:00:49 mdw
50 /*----- Header files ------------------------------------------------------*/
57 #include <X11/Xutil.h>
60 #include <gdk/gdkprivate.h>
61 #include <gdk/gdkkeysyms.h>
68 /*----- Static variables --------------------------------------------------*/
70 static char *atom
= XWAIT_DIE
;
71 static char *msg
= XWAIT_DIE_MSG
;
73 static Atom xwait_die
;
75 /*----- Main code ---------------------------------------------------------*/
77 /* --- @check_escape@ --- *
79 * Arguments: @GtkWidget *w@ = widget raising the signal
80 * @GdkEventKey *ev@ = pointer to event data
81 * @gpointer *p@ = widget to activate in response
85 * Use: Activates a widget when an escape keypress is detected.
88 static gboolean
check_escape(GtkWidget
*w
, GdkEventKey
*ev
, gpointer
*p
)
90 if (ev
->keyval
== GDK_Escape
) {
92 gtk_widget_activate(GTK_WIDGET(p
));
94 gtk_object_destroy(GTK_OBJECT(w
));
100 /* --- @cancel@ --- *
102 * Just end the main loop.
105 static void cancel(GtkWidget
*w
, gpointer
*p
)
112 * Send the xwait process a message.
115 static void ok(GtkWidget
*w
, gpointer
*p
)
118 XStringListToTextProperty(&msg
, 1, &prop
);
119 XSetTextProperty(gdk_display
, DefaultRootWindow(gdk_display
),
124 /* --- @version@ --- */
126 static void version(FILE *fp
)
128 fprintf(fp
, "%s (xtoys version " VERSION
")\n", QUIS
);
131 /* --- @usage@ --- */
133 static void usage(FILE *fp
)
135 fprintf(fp
, "Usage: %s [-a ATOM] [-m MSG] [-p PROMPT] [-t TITLE]\n", QUIS
);
143 int main(int argc
, char *argv
[])
145 char *prompt
= "Are you sure you want to shut down this session?";
146 char *title
= "xshutdown";
148 gtk_init(&argc
, &argv
);
150 /* --- Parse options --- */
153 static struct option opt
[] = {
154 { "help", 0, 0, 'h' },
155 { "usage", 0, 0, 'u' },
156 { "version", 0, 0, 'v' },
157 { "atom", required_argument
, 0, 'a' },
158 { "msg", required_argument
, 0, 'm' },
159 { "prompt", required_argument
, 0, 'p' },
160 { "title", required_argument
, 0, 't' },
165 i
= getopt_long(argc
, argv
, "huv a:m:p:t:", opt
, 0);
177 "Kills a waiting `xwait' process. Pops up a confirmation window first.\n"
179 "Options available are:\n"
181 "-h, --help Display this help text\n"
182 "-u, --usage Display a short usage summary\n"
183 "-v, --version Display the program's version number\n"
185 "-a, --atom=ATOM\t Select the atom that `xwait' is waiting for\n"
186 "-m, --msg=MSG Select the message to send to `xwait'\n"
187 "-p, --prompt=PROMPT Select the prompt string in the confirmation box\n"
188 "-t, --title=TITLE Select the title string in the confirmation box\n",
219 xwait_die
= XInternAtom(gdk_display
, atom
, False
);
221 /* --- Decide whether there's an xwait listening --- *
223 * If not, pop up an error box and quit.
229 if (!XGetTextProperty(gdk_display
, DefaultRootWindow(gdk_display
),
232 GtkWidget
*win
= gtk_dialog_new();
235 /* --- Make the main window --- */
237 gtk_window_set_title(GTK_WINDOW(win
), "xshutdown");
238 gtk_signal_connect(GTK_OBJECT(win
), "destroy",
239 GTK_SIGNAL_FUNC(cancel
), 0);
240 gtk_signal_connect(GTK_OBJECT(win
), "key_press_event",
241 GTK_SIGNAL_FUNC(check_escape
), 0);
243 gtk_box_set_homogeneous(GTK_BOX(GTK_DIALOG(win
)->action_area
), 0);
245 /* --- Make the label --- */
247 sprintf(buf
, "no xwait listening for `%s'\n", atom
);
248 w
= gtk_label_new(buf
);
249 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(win
)->vbox
), w
, 1, 1, 0);
250 gtk_misc_set_padding(GTK_MISC(w
), 8, 8);
253 /* --- Make the little button --- */
255 w
= gtk_button_new_with_label("OK");
256 gtk_box_pack_end(GTK_BOX(GTK_DIALOG(win
)->action_area
), w
, 0, 0, 0);
257 GTK_WIDGET_SET_FLAGS(w
, GTK_CAN_DEFAULT
);
258 gtk_widget_grab_default(w
);
259 gtk_signal_connect(GTK_OBJECT(w
), "clicked",
260 GTK_SIGNAL_FUNC(cancel
), 0);
263 /* --- Make everything work --- */
265 gtk_widget_realize(win
);
267 gtk_widget_show(win
);
273 /* --- Main code --- */
279 /* --- Make the main dialogue box --- */
281 win
= gtk_dialog_new();
282 gtk_window_set_title(GTK_WINDOW(win
), title
);
283 gtk_signal_connect(GTK_OBJECT(win
), "destroy",
284 GTK_SIGNAL_FUNC(cancel
), 0);
286 gtk_box_set_homogeneous(GTK_BOX(GTK_DIALOG(win
)->action_area
), 0);
288 /* --- Make the prompt label --- */
290 w
= gtk_label_new(prompt
);
291 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(win
)->vbox
), w
, 1, 1, 0);
292 gtk_misc_set_padding(GTK_MISC(w
), 8, 8);
295 /* --- Make the OK button --- */
297 w
= gtk_button_new_with_label("OK");
298 gtk_box_pack_end(GTK_BOX(GTK_DIALOG(win
)->action_area
), w
, 0, 0, 0);
299 gtk_signal_connect(GTK_OBJECT(w
), "clicked", GTK_SIGNAL_FUNC(ok
), 0);
300 GTK_WIDGET_SET_FLAGS(w
, GTK_CAN_DEFAULT
);
302 gtk_widget_grab_default(w
);
304 /* --- And the cancel button --- */
306 w
= gtk_button_new_with_label("Cancel");
307 gtk_box_pack_end(GTK_BOX(GTK_DIALOG(win
)->action_area
), w
, 0, 0, 0);
308 gtk_signal_connect(GTK_OBJECT(w
), "clicked", GTK_SIGNAL_FUNC(cancel
), 0);
309 GTK_WIDGET_SET_FLAGS(w
, GTK_CAN_DEFAULT
);
312 /* --- Show the completed window --- */
314 gtk_signal_connect(GTK_OBJECT(win
), "key_press_event",
315 GTK_SIGNAL_FUNC(check_escape
), 0);
316 gtk_widget_realize(win
);
318 gtk_widget_show(win
);
321 /* --- Let rip --- */
327 /*----- That's all, folks -------------------------------------------------*/