我正在尝试获取X11会话中所有顶层桌面窗口的列表。基本上,我想获取所有在窗口管理器应用程序切换UI中显示的窗口列表(通常在用户按下 ALT+TAB 时打开)。
我以前没有进行过任何 X11 编程,但到目前为止,我已经成功枚举了整个窗口列表,代码看起来类似于这样:
void CSoftwareInfoLinux::enumerateWindows(Display *display, Window rootWindow)
{
Window parent;
Window *children;
Window *child;
quint32 nNumChildren;
XTextProperty wmName;
XTextProperty wmCommand;
int status = XGetWMName(display, rootWindow, &wmName);
if (status && wmName.value && wmName.nitems)
{
int i;
char **list;
status = XmbTextPropertyToTextList(display, &wmName, &list, &i);
if (status >= Success && i && *list)
{
qDebug() << "Found window with name:" << (char*) *list;
}
status = XGetCommand(display, rootWindow, &list, &i);
if (status >= Success && i && *list)
{
qDebug() << "... and Command:" << i << (char*) *list;
}
Window tf;
status = XGetTransientForHint(display, rootWindow, &tf);
if (status >= Success && tf)
{
qDebug() << "TF set!";
}
XWMHints *pHints = XGetWMHints(display, rootWindow);
if (pHints)
{
qDebug() << "Flags:" << pHints->flags
<< "Window group:" << pHints->window_group;
}
}
status = XQueryTree(display, rootWindow, &rootWindow, &parent, &children, &nNumChildren);
if (status == 0)
{
// Could not query window tree further, aborting
return;
}
if (nNumChildren == 0)
{
// No more children found. Aborting
return;
}
for (int i = 0; i < nNumChildren; i++)
{
enumerateWindows(display, children[i]);
}
XFree((char*) children);
}
使用enumerateWindows()
,最初用根窗口调用。
这个函数能够打印出数百个窗口的信息。我需要确定一个给定的Window
是顶级桌面应用程序窗口(不确定官方术语是什么)还是其他类型的窗口。请问有人能够提供一些帮助吗?我找到的所有X11编程参考文献都过于枯燥难懂。或许有人可以指点我一个更好的资源?