3 * $Id: xwait.c,v 1.1 1998/11/16 23:00:49 mdw Exp $
5 * Wait until prodded by another X client
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 --------------------------------------------------*
32 * Revision 1.1 1998/11/16 23:00:49 mdw
37 /*----- Header files ------------------------------------------------------*/
46 #include <X11/Xutil.h>
50 /*----- Main code ---------------------------------------------------------*/
52 int main(int argc, char *argv[])
58 char *atom = XWAIT_DIE;
59 char *msg = XWAIT_DIE_MSG;
66 /* --- Parse options --- */
69 int i = getopt(argc, argv, "d:a:m:f");
87 "Usage: xwait [-f] [-d DISPLAY] [-a ATOM] [-m MSG]\n");
93 /* --- Connect to the X display --- */
95 dpy = XOpenDisplay(display);
97 fprintf(stderr, "xwait: couldn't open display\n");
101 /* --- Fetch the property name atom --- */
103 xwait_die = XInternAtom(dpy, atom, False);
105 /* --- Mark ourselves as listening to all the screens --- */
109 int nsc = ScreenCount(dpy);
111 /* --- First pass: make sure there's not a process already here --- */
113 if ((f & f_force) == 0) {
114 for (i = 0; i < nsc; i++) {
115 Window win = RootWindow(dpy, i);
118 if (XGetTextProperty(dpy, win, &prop, xwait_die)) {
119 fprintf(stderr, "xwait: already waiting for `%s'\n", atom);
125 /* --- Second pass: set up listening to the property --- */
127 for (i = 0; i < nsc; i++) {
128 Window win = RootWindow(dpy, i);
130 char *imsg = "XWAIT_READY";
132 XStringListToTextProperty(&imsg, 1, &prop);
133 XSetTextProperty(dpy, win, &prop, xwait_die);
134 XSelectInput(dpy, win, PropertyChangeMask);
138 /* --- Now wait for an event --- */
141 XNextEvent(dpy, &ev);
144 if (ev.xproperty.atom == xwait_die) {
149 if (XGetTextProperty(dpy, ev.xproperty.window, &prop, xwait_die)) {
150 XTextPropertyToStringList(&prop, &sl, &c);
151 if (strcmp(sl[0], msg) == 0)
159 /* --- Finished: remove the property from all the screens --- */
164 int nsc = ScreenCount(dpy);
166 for (i = 0; i < nsc; i++)
167 XDeleteProperty(dpy, RootWindow(dpy, i), xwait_die);
170 /* --- Go away --- */
176 /*----- That's all, folks -------------------------------------------------*/