英文:
How to get a list of windows in X11 with Go
问题
我想使用Go语言获取X11中所有打开窗口的窗口列表和窗口名称。我假设可以使用xgb包来实现。
英文:
I would like to get a list of windows + window names of all open windows in X11 using go. I assume that the xgb package would be used.
答案1
得分: 3
你可以使用C语言列出所有的窗口:
/*
Window *getDisplayWindows (Display *disp, unsigned long *len);
Window *getDisplayWindows (Display *disp, unsigned long *len) {
Atom prop = XInternAtom(disp,"_NET_CLIENT_LIST",False), type;
int form;
unsigned long remain;
unsigned char *list;
if (XGetWindowProperty(disp,XDefaultRootWindow(disp),prop,0,1024,False,XA_WINDOW,
&type,&form,len,&remain,&list) != Success) {
return 0;
}
return (Window*)list;
}
*/
import "C"
// 你的Go代码在下面
我在我的一个软件包中使用了这个方法,用于将窗口置于前台。希望对你有帮助!
英文:
You may use C and thus list all windows:
/*
Window *getDisplayWindows (Display *disp, unsigned long *len);
Window *getDisplayWindows (Display *disp, unsigned long *len) {
Atom prop = XInternAtom(disp,"_NET_CLIENT_LIST",False), type;
int form;
unsigned long remain;
unsigned char *list;
if (XGetWindowProperty(disp,XDefaultRootWindow(disp),prop,0,1024,False,XA_WINDOW,
&type,&form,len,&remain,&list) != Success) {
return 0;
}
return (Window*)list;
}
*/
import "C"
//your go code below
I used this for a package of mine to put a window foreground. Hope it helps ?
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论