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 |
int nc; |
27 |
|
28 |
if (XFetchName(dpy, win, &nr)) { |
29 |
register int succ = !strcmp(nr, name); |
30 |
free(nr); |
31 |
if (succ) return(win); |
32 |
} |
33 |
if (depth == 0) /* negative depths search all */ |
34 |
return(None); |
35 |
if (!XQueryTree(dpy, win, &rr, &pr, &cl, &nc) || nc == 0) |
36 |
return(None); |
37 |
while (nc--) |
38 |
if ((rr = xfindwind(dpy, cl[nc], name, depth-1)) != None) |
39 |
break; |
40 |
XFree((char *)cl); |
41 |
return(rr); |
42 |
} |