问题
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