为什么 XGetWindowProperty 返回 null? [英] Why is XGetWindowProperty returning null?

查看:39
本文介绍了为什么 XGetWindowProperty 返回 null?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下命令获取所有 X 窗口的名称:

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);
    }
  }

但在我的日志中,我只是为每个窗口获取 (null) .我做错了什么?

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

推荐答案

需要相应地将 req_type 指定为 UTF8_STRING:

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);
    }
  }

这篇关于为什么 XGetWindowProperty 返回 null?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆