ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/x11findwind.c
Revision: 2.3
Committed: Fri Dec 11 18:23:38 1992 UTC (31 years, 11 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.2: +12 -9 lines
Log Message:
changed to breadth-first search

File Contents

# Content
1 /* Copyright (c) 1991 Regents of the University of California */
2
3 #ifndef lint
4 static char SCCSid[] = "$SunId$ LBL";
5 #endif
6
7 /*
8 * find a window by its name under X
9 *
10 * 4/22/91 Greg Ward
11 */
12
13 #include <stdio.h>
14 #include <X11/Xlib.h>
15
16
17 Window
18 xfindwind(dpy, win, name, depth)
19 Display *dpy;
20 Window win;
21 char *name;
22 int depth;
23 {
24 char *nr;
25 Window rr, pr, *cl;
26 Window wr;
27 unsigned int nc;
28 register int i;
29
30 if (depth == 0) /* negative depths search all */
31 return(None);
32 if (!XQueryTree(dpy, win, &rr, &pr, &cl, &nc) || nc == 0)
33 return(None);
34 wr = None; /* breadth first search */
35 for (i = 0; wr == None && i < nc; i++)
36 if (XFetchName(dpy, cl[i], &nr)) {
37 if (!strcmp(nr, name))
38 wr = cl[i];
39 free(nr);
40 }
41 for (i = 0; wr == None && i < nc; i++)
42 wr = xfindwind(dpy, cl[i], name, depth-1);
43 XFree((char *)cl);
44 return(wr);
45 }