<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Linux Forum &mdash; Xlib: получение списка окон и их имен]]></title>
	<link rel="self" href="https://linuxforum.ru/extern.php?action=feed&amp;tid=11560&amp;type=atom" />
	<updated>2011-04-21T10:16:38Z</updated>
	<generator>PunBB</generator>
	<id>https://linuxforum.ru/viewtopic.php?id=11560</id>
		<entry>
			<title type="html"><![CDATA[Re: Xlib: получение списка окон и их имен]]></title>
			<link rel="alternate" href="https://linuxforum.ru/viewtopic.php?pid=170685#p170685" />
			<content type="html"><![CDATA[<p>Скорее всего название окна на русском языке. У меня в этом случае XFetchName тоже возвращает NULL. Для имен на английском все отрабатывает корректно.</p>]]></content>
			<author>
				<name><![CDATA[j5ew9]]></name>
				<uri>https://linuxforum.ru/profile.php?id=16893</uri>
			</author>
			<updated>2011-04-21T10:16:38Z</updated>
			<id>https://linuxforum.ru/viewtopic.php?pid=170685#p170685</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Xlib: получение списка окон и их имен]]></title>
			<link rel="alternate" href="https://linuxforum.ru/viewtopic.php?pid=152459#p152459" />
			<content type="html"><![CDATA[<p>Пытаюсь получить список окон и их имена<br /></p><div class="codebox"><pre><code>#include &lt;stdio.h&gt;
#include &lt;X11/Xlib.h&gt;
#include &lt;X11/Xatom.h&gt;

#include &lt;assert.h&gt;

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,
         &amp;type_ret, &amp;format_ret, &amp;items_ret, &amp;after_ret, &amp;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, &quot;_NET_CLIENT_LIST&quot;, False);

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

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

    XCloseDisplay(dpy);

    return 0;
}</code></pre></div><p>но переменная name всегда == NULL. Не подскажите рабочий код?</p>]]></content>
			<author>
				<name><![CDATA[unk]]></name>
				<uri>https://linuxforum.ru/profile.php?id=1383</uri>
			</author>
			<updated>2011-03-04T09:57:34Z</updated>
			<id>https://linuxforum.ru/viewtopic.php?pid=152459#p152459</id>
		</entry>
</feed>
