| Revision: | 2.6 |
| Committed: | Sun Jul 4 12:08:47 2004 UTC (21 years, 4 months ago) by schorsch |
| Content type: | text/plain |
| Branch: | MAIN |
| CVS Tags: | rad5R4, rad5R2, rad5R3, rad5R0, rad5R1, rad4R2, rad3R7P2, rad3R7P1, rad6R0, rad4R1, rad4R0, rad3R6, rad3R6P1, rad3R8, rad3R9, rad4R2P1, rad4R2P2, HEAD |
| Changes since 2.5: | +9 -6 lines |
| Log Message: | Updated SCons build environment to work with a fresh download and on OS X, as suggested by Randolph Fritz. |
| # | Content |
|---|---|
| 1 | #ifndef lint |
| 2 | static const char RCSid[] = "$Id: x11findwind.c,v 2.5 2003/02/25 02:47:22 greg Exp $"; |
| 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 <string.h> |
| 12 | #include <stdlib.h> |
| 13 | #include <X11/Xlib.h> |
| 14 | |
| 15 | |
| 16 | Window |
| 17 | xfindwind( |
| 18 | Display *dpy, |
| 19 | Window win, |
| 20 | char *name, |
| 21 | int depth |
| 22 | ) |
| 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 | } |