X11 获取窗口列表

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ice__snow/article/details/79979298

ENV

  • Ubuntu 16.04
  • CLion 2018.1
  • GCC 5.4.0

source

#include <xcb/xcb.h>
#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;
        XGetWindowAttributes(display, window, &attrs);

        std::cout << "#" << i <<":" << "(" << attrs.width << ", " << attrs.height << ")" << std::endl;
    }

    XFree(child_list);
    XCloseDisplay(display);

    return 0;
}
阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页