--- ray/src/common/x11findwind.c 1992/05/21 10:45:09 2.2 +++ ray/src/common/x11findwind.c 2003/02/25 02:47:22 2.5 @@ -1,15 +1,12 @@ -/* Copyright (c) 1991 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: x11findwind.c,v 2.5 2003/02/25 02:47:22 greg Exp $"; #endif - /* * find a window by its name under X - * - * 4/22/91 Greg Ward */ +#include "copyright.h" + #include #include @@ -23,20 +20,23 @@ int depth; { char *nr; Window rr, pr, *cl; + Window wr; unsigned int nc; + register int i; - if (XFetchName(dpy, win, &nr)) { - register int succ = !strcmp(nr, name); - free(nr); - if (succ) return(win); - } if (depth == 0) /* negative depths search all */ return(None); if (!XQueryTree(dpy, win, &rr, &pr, &cl, &nc) || nc == 0) return(None); - while (nc--) - if ((rr = xfindwind(dpy, cl[nc], name, depth-1)) != None) - break; + wr = None; /* breadth first search */ + for (i = 0; wr == None && i < nc; i++) + if (XFetchName(dpy, cl[i], &nr)) { + if (!strcmp(nr, name)) + wr = cl[i]; + free(nr); + } + for (i = 0; wr == None && i < nc; i++) + wr = xfindwind(dpy, cl[i], name, depth-1); XFree((char *)cl); - return(rr); + return(wr); }