c++,x11,linux查找窗口

如题

点击查看代码
#include <X11/Xlib.h>
#include <stdio.h>
void findWindow(Display* display, Window window, char** windowName, Window* result)
{
    Window root, parent, *children;
    unsigned int nChildren;

    if(XFetchName(display, window, windowName) > 0)
    {
        if (windowName && strstr(*windowName, "Pluma") != NULL)
        {
            *result = window;
            return;
        }
    }

    if(XQueryTree(display, window, &root, &parent, &children, &nChildren) != 0)
    {
        int i;
        for(i = 0; i < nChildren; i++)
        {
            findWindow(display, children[i], windowName, result);
        }
        XFree(children);
    }
}

void MainWindow::onfindwnd()
{
    Display* display = XOpenDisplay(NULL);
    Window root = DefaultRootWindow(display);

    Window result = None;
    char** windowName = new (char*);
    findWindow(display, root, windowName, &result);

    printf("Found window with ID %lu\n", result);

    XCloseDisplay(display);
    delete windowName;
}

int main()
{
    Display* display = XOpenDisplay(NULL);
    Window root = DefaultRootWindow(display);

    Window result = None;
    char** windowName = new (char*);
    findWindow(display, root, windowName, &result);

    printf("Found window with ID %lu\n", result);

    XCloseDisplay(display);
    delete windowName;
    return 0;
}
posted @ 2023-04-26 10:24  hn_xs_zhongjx  阅读(183)  评论(0编辑  收藏  举报