/* findwindow.c */ /* * Find a window by name and return its window ID. Modified to * search breadth-first instead of depth-first by Mike Manyin @ GSFC. * Input: dpy - the X display * scr - the X screen number * start - where to start search, usually root window * name - the window name to search for */ Window find_window( Display *dpy, int scr, Window start, char *name ) { Status stat; int n; unsigned int num; Window w, root, parent, *children; char *title; if (XFetchName( dpy, start, &title )==1) { if (strcmp( name, title )==0) { /* found it */ XFree( title ); return start; } XFree( title ); } /* get list of child windows */ stat = XQueryTree( dpy, start, &root, &parent, &children, &num ); if (stat==1) { /* search each child window for a match: */ for (n=num-1; n>=0; n--) { if (XFetchName( dpy, start, &title )==1) { if (strcmp( name, title )==0) { /* found it */ XFree( title ); return start; } XFree( title ); } } /* search the descendents of each child for a match: */ for (n=num-1; n>=0; n--) { w = find_window( dpy, scr, children[n], name ); if (w) { XFree( children ); return w; } } if ( children != NULL ) { XFree( children ); } } /* not found */ return 0; }