Back to index

radiance  4R0+20100331
x11findwind.c
Go to the documentation of this file.
00001 #ifndef lint
00002 static const char    RCSid[] = "$Id: x11findwind.c,v 2.6 2004/07/04 12:08:47 schorsch Exp $";
00003 #endif
00004 /*
00005  * find a window by its name under X
00006  */
00007 
00008 #include "copyright.h"
00009 
00010 #include <stdio.h>
00011 #include <string.h>
00012 #include <stdlib.h>
00013 #include <X11/Xlib.h>
00014 
00015 
00016 Window
00017 xfindwind(
00018        Display       *dpy,
00019        Window win,
00020        char   *name,
00021        int    depth
00022 )
00023 {
00024        char   *nr;
00025        Window rr, pr, *cl;
00026        Window wr;
00027        unsigned int  nc;
00028        register int  i;
00029 
00030        if (depth == 0)             /* negative depths search all */
00031               return(None);
00032        if (!XQueryTree(dpy, win, &rr, &pr, &cl, &nc) || nc == 0)
00033               return(None);
00034        wr = None;           /* breadth first search */
00035        for (i = 0; wr == None && i < nc; i++)
00036               if (XFetchName(dpy, cl[i], &nr)) {
00037                      if (!strcmp(nr, name))
00038                             wr = cl[i];
00039                      free(nr);
00040               }
00041        for (i = 0; wr == None && i < nc; i++)
00042               wr = xfindwind(dpy, cl[i], name, depth-1);
00043        XFree((char *)cl);
00044        return(wr);
00045 }