Why is XGetWindowProperty returning null?

蹲街弑〆低调 提交于 2019-12-05 04:04:40

问题


I'm using the following to get the names of all X windows:

  Atom nameAtom = XInternAtom(dpy,"_NET_WM_NAME",false);
  Atom type;
  int format;
  unsigned long nitems, after;
  unsigned char *data = 0;

  if (Success == XGetWindowProperty(dpy, window, nameAtom, 0, 65536,
                                    false, XA_ATOM, &type, &format,
                                    &nitems, &after, &data)) {
    if (data) {
      Atom windowName = *(Atom*)data;
      const char* name = XGetAtomName(dpy, windowName);
      log.debug("Name: %s", name);
      XFree(data);
    }
  }

But in my log I'm just getting (null) for every single window. What am I doing wrong?


回答1:


What was required was to specify the req_type as UTF8_STRING accordingly:

  Atom nameAtom = XInternAtom(dpy,"_NET_WM_NAME",false);
  Atom utf8Atom = XInternAtom(dpy,"UTF8_STRING",false);
  Atom type;
  int format;
  unsigned long nitems, after;
  unsigned char *data = 0;

  if (Success == XGetWindowProperty(dpy, window, nameAtom, 0, 65536,
                                    false, utf8Atom, &type, &format,
                                    &nitems, &after, &data)) {
    if (data) {
      log.debug("Name: %s", data);
      XFree(data);
    }
  }


来源:https://stackoverflow.com/questions/8925377/why-is-xgetwindowproperty-returning-null

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!