|
发表于 2007-10-15 22:58:32
|
显示全部楼层
这个和 gtk 没有关系, 得用 X11 底层 API.
X11 自带了 xwininfo 和 xprop 两个小工具, 可以帮助用户查看某个窗口的信息. 既可以用鼠标选择, 也可以根据窗口的名称或者id. 你研究一下这两个工具的源代码, 看看它们怎么实现的.
原来是通过递归来找的, Xlib 没有提供直接的 API
- /*
- * Window_With_Name: routine to locate a window with a given name on a display.
- * If no window with the given name is found, 0 is returned.
- * If more than one window has the given name, the first
- * one found will be returned. Only top and its subwindows
- * are looked at. Normally, top should be the RootWindow.
- */
- Window Window_With_Name(dpy, top, name)
- Display *dpy;
- Window top;
- char *name;
- {
- Window *children, dummy;
- unsigned int nchildren;
- int i;
- Window w=0;
- char *window_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);
- }
复制代码 |
|