chiark / gitweb /
Set focus on the entry field, rather than leaving things to luck.
[xtoys] / xtell.c
1 /* -*-c-*-
2  *
3  * $Id: xtell.c,v 1.3 1998/11/30 22:36:51 mdw Exp $
4  *
5  * Wake up a waiting xwait process
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
29 /*----- Revision history --------------------------------------------------* 
30  *
31  * $Log: xtell.c,v $
32  * Revision 1.3  1998/11/30 22:36:51  mdw
33  * Tidy up tabbing in help texts very slightly.
34  *
35  * Revision 1.2  1998/11/21 22:30:25  mdw
36  * Support GNU-style long options throughout, and introduce proper help
37  * text to all programs.  Update manual pages to match.
38  *
39  * Revision 1.1  1998/11/16 23:00:49  mdw
40  * Initial versions.
41  *
42  */
43
44 /*----- Header files ------------------------------------------------------*/
45
46 #include <stdio.h>
47 #include <stdlib.h>
48 #include <string.h>
49
50 #include <X11/Xlib.h>
51 #include <X11/Xutil.h>
52
53 #include "mdwopt.h"
54 #include "quis.h"
55 #include "xwait.h"
56
57 /*----- Main code ---------------------------------------------------------*/
58
59 static void version(FILE *fp)
60 {
61   fprintf(fp, "%s (xtoys version " VERSION ")\n", QUIS);
62 }
63
64 static void usage(FILE *fp)
65 {
66   fprintf(fp, "Usage: %s [-d DISPLAY] [-a ATOM] [-m MSG]\n", QUIS);
67 }
68
69 int main(int argc, char *argv[])
70 {
71   char *display = 0;
72   Display *dpy;
73   Atom xwait_die;
74   char *atom = XWAIT_DIE;
75   char *msg = XWAIT_DIE_MSG;
76
77   /* --- Parse options --- */
78
79   ego(argv[0]);
80
81   for (;;) {
82     static struct option opt[] = {
83       { "help",         0,                      0,      'h' },
84       { "usage",        0,                      0,      'u' },
85       { "version",      0,                      0,      'v' },
86       { "display",      required_argument,      0,      'd' },
87       { "atom",         required_argument,      0,      'a' },
88       { "msg",          required_argument,      0,      'm' },
89       { 0,              0,                      0,      0 }
90     };
91
92     int i = getopt_long(argc, argv, "d:a:m:", opt, 0);
93     if (i < 0)
94       break;
95     switch (i) {
96       case 'h':
97         version(stdout);
98         fputs("\n", stdout);
99         usage(stdout);
100         fputs(
101 "\n"
102 "Signals a waiting `xwait' process.  Specifically, writes a property\n"
103 "named ATOM to the X root window, with value MSG.\n"
104 "\n"
105 "Options:\n"
106 "\n"
107 "-h, --help             Display this help text\n"
108 "-u, --usage            Display a short usage summary\n"
109 "-v, --version          Display the program's version number\n"
110 "\n"
111 "-d, --display=DISPLAY  Choose X display to connect to\n"
112 "-a, --atom=ATOM\t      Choose property name to set\n"
113 "-m, --msg=MSG          Choose value of property to set\n",
114           stdout);
115         exit(0);
116         break;
117       case 'u':
118         usage(stdout);
119         exit(0);
120         break;
121       case 'v':
122         version(stdout);
123         exit(0);
124         break;
125         
126       case 'd':
127         display = optarg;
128         break;
129       case 'a':
130         atom = optarg;
131         break;
132       case 'm':
133         msg = optarg;
134         break;
135       default:
136         fprintf(stderr, "Usage: xtell [-d DISPLAY] [-a ATOM] [-m MSG]\n");
137         exit(EXIT_FAILURE);
138         break;
139     }
140   }
141
142   /* --- Connect to the display --- */
143
144   dpy = XOpenDisplay(display);
145   if (!dpy) {
146     fprintf(stderr, "xtell: couldn't open display\n");
147     exit(EXIT_FAILURE);
148   }
149
150   /* --- Find the right atom --- */
151
152   xwait_die = XInternAtom(dpy, atom, False);
153
154   /* --- Set the property value --- */
155
156   {
157     XTextProperty prop;
158     if (!XGetTextProperty(dpy, DefaultRootWindow(dpy), &prop, xwait_die)) {
159       fprintf(stderr, "xtell: no xwait listening for `%s'\n", atom);
160       exit(EXIT_FAILURE);
161     }
162     XStringListToTextProperty(&msg, 1, &prop);
163     XSetTextProperty(dpy, DefaultRootWindow(dpy), &prop, xwait_die);
164   }
165
166   /* --- Done --- */
167
168   XCloseDisplay(dpy);
169   return (0);
170 }
171
172 /*----- That's all, folks -------------------------------------------------*/