列举窗口示例, 编译指令
g++ -lX11 list_win.cpp -o list_win
#include <X11/Xlib.h>
#include <iostream>
int main()
{
auto display = XOpenDisplay(nullptr);
auto root_window = DefaultRootWindow(display);
Window root_return, parent_return;
Window * child_list = nullptr;
unsigned int child_num = 0;
XQueryTree(display, root_window, &root_return, &parent_return, &child_list, &child_num);
for(unsigned int i = 0; i < child_num; ++i) {
auto window = child_list[i];
XWindowAttributes attrs;
char* title = nullptr;
XGetWindowAttributes(display, window, &attrs);
XFetchName(display, window, &title);
std::cout << "#" << i <<":" << "(" << attrs.width << ", " << attrs.height << ")";
if(title){
std::cout << title;
}
std::cout << std::endl;
XFree(title);
}
XFree(child_list);
XCloseDisplay(display);
return 0;
}