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, 4 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

# User Rev Content
1 greg 1.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 greg 2.3 Window wr;
27 greg 2.2 unsigned int nc;
28 greg 2.3 register int i;
29 greg 1.1
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 greg 2.3 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 greg 1.1 XFree((char *)cl);
44 greg 2.3 return(wr);
45 greg 1.1 }