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