LinuxForum.Fans
Тема

Xlib: получение списка окон и их имен

Автор: unk 2 сообщений 1834 просмотров
#136169

Пытаюсь получить список окон и их имена

text

#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>

#include <assert.h>

static void* x11property(Display *dpy, Window win, Atom prop, Atom type, int *nitems) { Atom type_ret; int format_ret; unsigned long items_ret; unsigned long after_ret; unsigned char *prop_data = 0;

if (XGetWindowProperty(dpy, win, prop, 0, 0x7fffffff, False, type, &type_ret, &format_ret, &items_ret, &after_ret, &prop_data) != Success) return 0;

if (nitems) *nitems = items_ret;

return prop_data; }

int main() { Atom atom_client_list; Atom atom_netwmname; Atom atom_utf8; Display *dpy; Window root, *winlist, activewin; int num;

dpy = XOpenDisplay(NULL); assert(dpy != NULL);

root = DefaultRootWindow(dpy);

atom_client_list = XInternAtom(dpy, "_NET_CLIENT_LIST", False);

atom_netwmname = XInternAtom(dpy, "_NET_WM_NAME", False); atom_utf8 = XInternAtom(dpy, "UTF8_STRING", False);

winlist = (Window*)x11property(dpy, root, atom_client_list, XA_WINDOW, &num); if (winlist) { int i; for (i = 0; i < num; ++i) { /* char *name = NULL; XFetchName(dpy, winlist[i], &name); printf("%c %#lx %s\n", winlist[i] == activewin ? '*' : ' ', (unsigned long) winlist[i], name); XFree(name);*/ unsigned char *name = NULL; name = (unsigned char *)x11property(dpy, winlist[i], atom_netwmname, atom_utf8, NULL); printf("name == NULL - %s\n", name == NULL ? "True" : "False"); printf("%s\n", name); XFree(name); } XFree(winlist); }

XCloseDisplay(dpy);

return 0; }

но переменная name всегда == NULL. Не подскажите рабочий код?

#153746

Скорее всего название окна на русском языке. У меня в этом случае XFetchName тоже возвращает NULL. Для имен на английском все отрабатывает корректно.

Войдите или зарегистрируйтесь, чтобы ответить.