dd62b262131f47dff1ae48fa435ea9801f241f9f
3 * $Id: xshutdown.c,v 1.1 1998/11/16 23:00: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.1 1998/11/16 23:00:49 mdw
37 /*----- Header files ------------------------------------------------------*/
44 #include <X11/Xutil.h>
47 #include <gdk/gdkprivate.h>
52 /*----- Static variables --------------------------------------------------*/
54 static char *atom
= XWAIT_DIE
;
55 static char *msg
= XWAIT_DIE_MSG
;
57 static Atom xwait_die
;
59 /*----- Main code ---------------------------------------------------------*/
63 * Just end the main loop.
66 static void cancel(GtkWidget
*w
, gpointer
*p
)
73 * Send the xwait process a message.
76 static void ok(GtkWidget
*w
, gpointer
*p
)
79 XStringListToTextProperty(&msg
, 1, &prop
);
80 XSetTextProperty(gdk_display
, DefaultRootWindow(gdk_display
),
90 int main(int argc
, char *argv
[])
92 char *prompt
= "Are you sure you want to shut down this session?";
93 char *title
= "xshutdown";
94 gtk_init(&argc
, &argv
);
96 /* --- Parse options --- */
99 static struct option opt
[] = {
100 { "atom", required_argument
, 0, 'a' },
101 { "msg", required_argument
, 0, 'm' },
102 { "prompt", required_argument
, 0, 'p' },
103 { "title", required_argument
, 0, 't' },
108 i
= getopt_long(argc
, argv
, "a:m:p:t:", opt
, 0);
131 xwait_die
= XInternAtom(gdk_display
, atom
, False
);
133 /* --- Decide whether there's an xwait listening --- *
135 * If not, pop up an error box and quit.
141 if (!XGetTextProperty(gdk_display
, DefaultRootWindow(gdk_display
),
144 GtkWidget
*win
= gtk_dialog_new();
147 /* --- Make the main window --- */
149 gtk_window_set_title(GTK_WINDOW(win
), "xshutdown");
150 gtk_signal_connect(GTK_OBJECT(win
), "destroy",
151 GTK_SIGNAL_FUNC(cancel
), 0);
153 gtk_box_set_homogeneous(GTK_BOX(GTK_DIALOG(win
)->action_area
), 0);
155 /* --- Make the label --- */
157 sprintf(buf
, "no xwait listening for `%s'\n", atom
);
158 w
= gtk_label_new(buf
);
159 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(win
)->vbox
), w
, 1, 1, 0);
160 gtk_misc_set_padding(GTK_MISC(w
), 8, 8);
163 /* --- Make the little button --- */
165 w
= gtk_button_new_with_label("OK");
166 gtk_box_pack_end(GTK_BOX(GTK_DIALOG(win
)->action_area
), w
, 0, 0, 0);
167 GTK_WIDGET_SET_FLAGS(w
, GTK_CAN_DEFAULT
);
168 gtk_widget_grab_default(w
);
169 gtk_signal_connect(GTK_OBJECT(w
), "clicked",
170 GTK_SIGNAL_FUNC(cancel
), 0);
173 /* --- Make everything work --- */
175 gtk_widget_show(win
);
181 /* --- Main code --- */
187 /* --- Make the main dialogue box --- */
189 win
= gtk_dialog_new();
190 gtk_window_set_title(GTK_WINDOW(win
), title
);
191 gtk_signal_connect(GTK_OBJECT(win
), "destroy",
192 GTK_SIGNAL_FUNC(cancel
), 0);
194 gtk_box_set_homogeneous(GTK_BOX(GTK_DIALOG(win
)->action_area
), 0);
196 /* --- Make the prompt label --- */
198 w
= gtk_label_new(prompt
);
199 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(win
)->vbox
), w
, 1, 1, 0);
200 gtk_misc_set_padding(GTK_MISC(w
), 8, 8);
203 /* --- Make the OK button --- */
205 w
= gtk_button_new_with_label("OK");
206 gtk_box_pack_end(GTK_BOX(GTK_DIALOG(win
)->action_area
), w
, 0, 0, 0);
207 gtk_signal_connect(GTK_OBJECT(w
), "clicked", GTK_SIGNAL_FUNC(ok
), 0);
208 GTK_WIDGET_SET_FLAGS(w
, GTK_CAN_DEFAULT
);
210 gtk_widget_grab_default(w
);
212 /* --- And the cancel button --- */
214 w
= gtk_button_new_with_label("Cancel");
215 gtk_box_pack_end(GTK_BOX(GTK_DIALOG(win
)->action_area
), w
, 0, 0, 0);
216 gtk_signal_connect(GTK_OBJECT(w
), "clicked", GTK_SIGNAL_FUNC(cancel
), 0);
217 GTK_WIDGET_SET_FLAGS(w
, GTK_CAN_DEFAULT
);
220 /* --- Show the completed window --- */
222 gtk_widget_show(win
);
225 /* --- Let rip --- */
231 /*----- That's all, folks -------------------------------------------------*/