0

这是我的代码,我得到“失败请求的 X 错误:BadWindow(无效的窗口参数)”

xdo_t *xdo = xdo_new(":0");
XWindowAttributes attr;
XClassHint classhint;
Window window;
XGetWindowAttributes(xdo->xdpy, window, &attr);
if (XGetClassHint(xdo->xdpy, window, &classhint)) {
    classhint.res_name;
}
4

1 回答 1

3

我找到了解决方案,如错误消息显示“(无效的窗口参数)”,这意味着我应该首先获取窗口,在我的情况下 62914561 是 google-chrome 窗口 id(我用 得到它xdotool search google-chrome),下面的代码应该可以工作

#include <X11/Xutil.h>
#include <xdo.h>

int main(int argc, char **argv) {
    Display *display = XOpenDisplay(NULL);
    XWindowAttributes attr;
    XClassHint classhint;
    Window window = 62914561;
    XGetWindowAttributes(display, window, &attr);

    if (XGetClassHint(display, window, &classhint)) {
        classhint.res_name;
    }
}
于 2016-01-10T11:04:47.093 回答