3 * $Id: xshutdown.c,v 1.2 1998/11/21 22:30:23 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.2 1998/11/21 22:30:23 mdw
33 * Support GNU-style long options throughout, and introduce proper help
34 * text to all programs. Update manual pages to match.
36 * Revision 1.1 1998/11/16 23:00:49 mdw
41 /*----- Header files ------------------------------------------------------*/
48 #include <X11/Xutil.h>
51 #include <gdk/gdkprivate.h>
57 /*----- Static variables --------------------------------------------------*/
59 static char *atom
= XWAIT_DIE
;
60 static char *msg
= XWAIT_DIE_MSG
;
62 static Atom xwait_die
;
64 /*----- Main code ---------------------------------------------------------*/
68 * Just end the main loop.
71 static void cancel(GtkWidget
*w
, gpointer
*p
)
78 * Send the xwait process a message.
81 static void ok(GtkWidget
*w
, gpointer
*p
)
84 XStringListToTextProperty(&msg
, 1, &prop
);
85 XSetTextProperty(gdk_display
, DefaultRootWindow(gdk_display
),
90 /* --- @version@ --- */
92 static void version(FILE *fp
)
94 fprintf(fp
, "%s (xtoys version " VERSION
")\n", QUIS
);
99 static void usage(FILE *fp
)
101 fprintf(fp
, "Usage: %s [-a ATOM] [-m MSG] [-p PROMPT] [-t TITLE]\n", QUIS
);
109 int main(int argc
, char *argv
[])
111 char *prompt
= "Are you sure you want to shut down this session?";
112 char *title
= "xshutdown";
114 gtk_init(&argc
, &argv
);
116 /* --- Parse options --- */
119 static struct option opt
[] = {
120 { "help", 0, 0, 'h' },
121 { "usage", 0, 0, 'u' },
122 { "version", 0, 0, 'v' },
123 { "atom", required_argument
, 0, 'a' },
124 { "msg", required_argument
, 0, 'm' },
125 { "prompt", required_argument
, 0, 'p' },
126 { "title", required_argument
, 0, 't' },
131 i
= getopt_long(argc
, argv
, "huv a:m:p:t:", opt
, 0);
143 "Kills a waiting `xwait' process. Pops up a confirmation window first.\n"
145 "Options available are:\n"
147 "-h, --help Display this help text\n"
148 "-u, --usage Display a short usage summary\n"
149 "-v, --version Display the program's version number\n"
151 "-a, --atom=ATOM Select the atom that `xwait' is waiting for\n"
152 "-m, --msg=MSG Select the message to send to `xwait'\n"
153 "-p, --prompt=PROMPT Select the prompt string in the confirmation box\n"
154 "-t, --title=TITLE Select the title string in the confirmation box\n",
185 xwait_die
= XInternAtom(gdk_display
, atom
, False
);
187 /* --- Decide whether there's an xwait listening --- *
189 * If not, pop up an error box and quit.
195 if (!XGetTextProperty(gdk_display
, DefaultRootWindow(gdk_display
),
198 GtkWidget
*win
= gtk_dialog_new();
201 /* --- Make the main window --- */
203 gtk_window_set_title(GTK_WINDOW(win
), "xshutdown");
204 gtk_signal_connect(GTK_OBJECT(win
), "destroy",
205 GTK_SIGNAL_FUNC(cancel
), 0);
207 gtk_box_set_homogeneous(GTK_BOX(GTK_DIALOG(win
)->action_area
), 0);
209 /* --- Make the label --- */
211 sprintf(buf
, "no xwait listening for `%s'\n", atom
);
212 w
= gtk_label_new(buf
);
213 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(win
)->vbox
), w
, 1, 1, 0);
214 gtk_misc_set_padding(GTK_MISC(w
), 8, 8);
217 /* --- Make the little button --- */
219 w
= gtk_button_new_with_label("OK");
220 gtk_box_pack_end(GTK_BOX(GTK_DIALOG(win
)->action_area
), w
, 0, 0, 0);
221 GTK_WIDGET_SET_FLAGS(w
, GTK_CAN_DEFAULT
);
222 gtk_widget_grab_default(w
);
223 gtk_signal_connect(GTK_OBJECT(w
), "clicked",
224 GTK_SIGNAL_FUNC(cancel
), 0);
227 /* --- Make everything work --- */
229 gtk_widget_show(win
);
235 /* --- Main code --- */
241 /* --- Make the main dialogue box --- */
243 win
= gtk_dialog_new();
244 gtk_window_set_title(GTK_WINDOW(win
), title
);
245 gtk_signal_connect(GTK_OBJECT(win
), "destroy",
246 GTK_SIGNAL_FUNC(cancel
), 0);
248 gtk_box_set_homogeneous(GTK_BOX(GTK_DIALOG(win
)->action_area
), 0);
250 /* --- Make the prompt label --- */
252 w
= gtk_label_new(prompt
);
253 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(win
)->vbox
), w
, 1, 1, 0);
254 gtk_misc_set_padding(GTK_MISC(w
), 8, 8);
257 /* --- Make the OK button --- */
259 w
= gtk_button_new_with_label("OK");
260 gtk_box_pack_end(GTK_BOX(GTK_DIALOG(win
)->action_area
), w
, 0, 0, 0);
261 gtk_signal_connect(GTK_OBJECT(w
), "clicked", GTK_SIGNAL_FUNC(ok
), 0);
262 GTK_WIDGET_SET_FLAGS(w
, GTK_CAN_DEFAULT
);
264 gtk_widget_grab_default(w
);
266 /* --- And the cancel button --- */
268 w
= gtk_button_new_with_label("Cancel");
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(cancel
), 0);
271 GTK_WIDGET_SET_FLAGS(w
, GTK_CAN_DEFAULT
);
274 /* --- Show the completed window --- */
276 gtk_widget_show(win
);
279 /* --- Let rip --- */
285 /*----- That's all, folks -------------------------------------------------*/