+/* This code form X11-utils */
+Window Window_With_Name( Display *dpy, Window top, char *name)
+{
+ Window *children, dummy;
+ unsigned int nchildren;
+ int i;
+ Window w=0;
+ char *window_name;
+
+ XClassHint *class_hint;
+ class_hint = XAllocClassHint();
+ XGetClassHint(dpy, top, class_hint);
+ if (class_hint->res_name && name && !strcmp(class_hint->res_name, name)){
+ XFree(class_hint->res_class);
+ XFree(class_hint->res_name);
+ return(top);
+ }
+ XFree(class_hint->res_class);
+ XFree(class_hint->res_name);
+
+ if (XFetchName(dpy, top, &window_name) && !strcmp(window_name, name))
+ return(top);
+
+ if (!XQueryTree(dpy, top, &dummy, &dummy, &children, &nchildren))
+ return(0);
+
+ for (i=0; i<nchildren; i++) {
+ w = Window_With_Name(dpy, children[i], name);
+ if (w)
+ break;
+ }
+ if (children) XFree ((char *)children);
+ return(w);
+}
+
+/*******************************************************************************/