如何使用Go获取X11中的窗口列表

huangapple go评论91阅读模式
英文:

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 ?

huangapple
  • 本文由 发表于 2022年9月26日 19:32:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/73853550.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定