0

here is my code, I get "X Error of failed request: BadWindow (invalid Window parameter)"

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;
}
pozklundw
  • 505
  • 1
  • 9
  • 16

1 Answers1

3

I find the solution, as error message show"(invalid Window parameter)”, it means I should first get window, in my case 62914561 is google-chrome window id(I get it with xdotool search google-chrome), following code should work

#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;
    }
}
pozklundw
  • 505
  • 1
  • 9
  • 16