90b2c5d4 |
1 | /* -*-c-*- |
2 | * |
47747dbe |
3 | * $Id: xshutdown.c,v 1.9 2004/04/08 01:36:29 mdw Exp $ |
90b2c5d4 |
4 | * |
5 | * Pretty GTK interface to waking up an xwait |
6 | * |
7 | * (c) 1998 Straylight/Edgeware |
8 | */ |
9 | |
10 | /*----- Licensing notice --------------------------------------------------* |
11 | * |
12 | * This file is part of the Edgeware X tools collection. |
13 | * |
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. |
18 | * |
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. |
23 | * |
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. |
27 | */ |
28 | |
90b2c5d4 |
29 | /*----- Header files ------------------------------------------------------*/ |
30 | |
31 | #include <stdio.h> |
32 | #include <stdlib.h> |
33 | #include <string.h> |
34 | |
35 | #include <X11/Xlib.h> |
36 | #include <X11/Xutil.h> |
37 | |
38 | #include <gtk/gtk.h> |
39 | #include <gdk/gdkprivate.h> |
87dabe6f |
40 | #include <gdk/gdkkeysyms.h> |
90b2c5d4 |
41 | |
aa8f2c90 |
42 | #include <mLib/mdwopt.h> |
43 | #include <mLib/quis.h> |
d72bdcdb |
44 | #include <mLib/report.h> |
aa8f2c90 |
45 | |
46 | #include <mgLib/msg.h> |
47 | |
d72bdcdb |
48 | #include "xatom.h" |
90b2c5d4 |
49 | #include "xwait.h" |
50 | |
90b2c5d4 |
51 | /*----- Main code ---------------------------------------------------------*/ |
52 | |
f3b35b6b |
53 | /* --- @version@ --- */ |
54 | |
55 | static void version(FILE *fp) |
56 | { |
57 | fprintf(fp, "%s (xtoys version " VERSION ")\n", QUIS); |
58 | } |
59 | |
60 | /* --- @usage@ --- */ |
61 | |
62 | static void usage(FILE *fp) |
63 | { |
d72bdcdb |
64 | fprintf(fp, "Usage: %s [-p PROMPT] [-t TITLE] [ATOM:MSG]\n", QUIS); |
f3b35b6b |
65 | } |
66 | |
90b2c5d4 |
67 | /* --- @main@ --- * |
68 | * |
69 | * Main program. |
70 | */ |
71 | |
72 | int main(int argc, char *argv[]) |
73 | { |
bf980fa9 |
74 | const char *atom = XWAIT_DIE; |
75 | const char *xmsg = XWAIT_DIE_MSG; |
d72bdcdb |
76 | Atom xa, xm; |
77 | |
bf980fa9 |
78 | const char *prompt = "Are you sure you want to shut down this session?"; |
79 | const char *title; |
f3b35b6b |
80 | ego(argv[0]); |
90b2c5d4 |
81 | gtk_init(&argc, &argv); |
82 | |
83 | /* --- Parse options --- */ |
84 | |
bf980fa9 |
85 | title = QUIS; |
90b2c5d4 |
86 | for (;;) { |
87 | static struct option opt[] = { |
d72bdcdb |
88 | { "help", 0, 0, 'h' }, |
89 | { "usage", 0, 0, 'u' }, |
90 | { "version", 0, 0, 'v' }, |
91 | { "atom", OPTF_ARGREQ, 0, 'a' }, |
92 | { "msg", OPTF_ARGREQ, 0, 'm' }, |
93 | { "prompt", OPTF_ARGREQ, 0, 'p' }, |
94 | { "title", OPTF_ARGREQ, 0, 't' }, |
95 | { 0, 0, 0, 0 } |
90b2c5d4 |
96 | }; |
97 | int i; |
98 | |
f3b35b6b |
99 | i = getopt_long(argc, argv, "huv a:m:p:t:", opt, 0); |
90b2c5d4 |
100 | |
101 | if (i < 0) |
102 | break; |
103 | |
104 | switch (i) { |
f3b35b6b |
105 | case 'h': |
106 | version(stdout); |
107 | fputs("\n", stdout); |
108 | usage(stdout); |
109 | fputs( |
110 | "\n" |
111 | "Kills a waiting `xwait' process. Pops up a confirmation window first.\n" |
112 | "\n" |
113 | "Options available are:\n" |
114 | "\n" |
115 | "-h, --help Display this help text\n" |
116 | "-u, --usage Display a short usage summary\n" |
117 | "-v, --version Display the program's version number\n" |
118 | "\n" |
d72bdcdb |
119 | "-a, --atom=ATOM\t Select the property name atom [deprecated]\n" |
120 | "-m, --msg=MSG Select the message to send [deprecated]\n" |
f3b35b6b |
121 | "-p, --prompt=PROMPT Select the prompt string in the confirmation box\n" |
122 | "-t, --title=TITLE Select the title string in the confirmation box\n", |
123 | stdout); |
124 | exit(0); |
125 | break; |
126 | case 'u': |
127 | usage(stdout); |
128 | exit(0); |
129 | break; |
130 | case 'v': |
131 | version(stdout); |
132 | exit(0); |
133 | break; |
134 | |
90b2c5d4 |
135 | case 'a': |
136 | atom = optarg; |
137 | break; |
138 | case 'm': |
aa8f2c90 |
139 | xmsg = optarg; |
90b2c5d4 |
140 | break; |
141 | case 'p': |
142 | prompt = optarg; |
143 | break; |
144 | case 't': |
145 | title = optarg; |
146 | break; |
147 | default: |
f3b35b6b |
148 | usage(stderr); |
90b2c5d4 |
149 | exit(EXIT_FAILURE); |
150 | } |
151 | } |
152 | |
d72bdcdb |
153 | if (optind < argc) { |
154 | char *p; |
155 | if ((atom = strtok(argv[optind++], ":")) == 0) |
156 | die(EXIT_FAILURE, "missing atom name"); |
157 | if ((p = strtok(0, ",")) != 0) |
158 | xmsg = p; |
159 | } |
160 | |
161 | if (optind < argc) { |
162 | usage(stderr); |
163 | exit(EXIT_FAILURE); |
164 | } |
165 | |
166 | xa = XInternAtom(gdk_display, atom, False); |
167 | xm = XInternAtom(gdk_display, xmsg, False); |
90b2c5d4 |
168 | |
169 | /* --- Decide whether there's an xwait listening --- * |
170 | * |
171 | * If not, pop up an error box and quit. |
172 | */ |
173 | |
d72bdcdb |
174 | if (xatom_get(gdk_display, DefaultRootWindow(gdk_display), xa) == None) { |
bf980fa9 |
175 | msg(QUIS, "!:~OK", "no xwait listening for `%s'", atom); |
d72bdcdb |
176 | exit(EXIT_FAILURE); |
90b2c5d4 |
177 | } |
178 | |
179 | /* --- Main code --- */ |
180 | |
bf980fa9 |
181 | if (msg(title, "!:OK,~Cancel", "%s", prompt) == 0) |
d72bdcdb |
182 | xatom_set(gdk_display, DefaultRootWindow(gdk_display), xa, xm); |
90b2c5d4 |
183 | |
90b2c5d4 |
184 | return (0); |
185 | } |
186 | |
187 | /*----- That's all, folks -------------------------------------------------*/ |