Obviously I could read in the results of grepping that, but it wouldn't be
so pretty, any help would be appreciated!
> I'd like to use Xlib to retrieve a list of window ids - the
> same list which xprop -root returns under _NET_CLIENT_LIST(WINDOW).
Well, have you looked at how xprop does it?
http://cvs.freedesktop.org/*checkout*/xorg/xc/programs/xprop/xprop.c?content-type=text%2Fplain
The Show_Prop function there looks like the relevant one.
On Sat, 26 Feb 2005 06:51:06 +0200, Kalle Olavi Niemitalo wrote:
> Thanks, I have now. That looks to me like a general property showing
> function and I can't see where it would be called from with the specific
> details for the net client list?
Show_Prop() also arranges to read the property from the server.
Put a breakpoint there and run "xprop -root _NET_CLIENT_LIST".
> Thanks. I read up on break points, when to give them a go and then
> discovered I couldn't figure out how to compile xprop.c! I've tried a
> bunch of versions and a bunch of different gcc commands, without much
> success. :(
You also need dsimple.c and dsimple.h from xc/programs/xlsfonts.
Place these and xprop.c in a director, type
gcc -g -o xprop xprop.c dsimple.c -L/usr/X11R6/lib -lX11 -lXmu
and you'll hopefully get a brand new xprop executable.
--
Måns Rullgård
m...@inprovide.com
I've got as far as working out that it uses XInternAtom(d,
"_NET_CLIENT_LIST", True); to extract the 'atom'. I guess there's a way to
extract the window list from the atom. I think it uses XGetWindowProperty
afterward for that purpose. But I'm not sure - it seems to need a window
id for that and I don't think atoms are supposed to have window ids -
indeed it's window ids I'm after!
Rich
> Ah, spot on, thank you.
>
> I've got as far as working out that it uses XInternAtom(d,
> "_NET_CLIENT_LIST", True); to extract the 'atom'. I guess there's a way to
> extract the window list from the atom. I think it uses XGetWindowProperty
> afterward for that purpose. But I'm not sure - it seems to need a window
> id for that and I don't think atoms are supposed to have window ids -
> indeed it's window ids I'm after!
An atom is just a unique mapping from a text string to an integer,
used for reasons of efficiency, I presume.
As for the window id, use the root window. DefaultRootWindow(display)
is usually a good start.
--
Måns Rullgård
m...@inprovide.com
Ok, so _NET_CLIENT_LIST seems to map to the integer 301, at least in the
instance I tried it. What does that integer represent?
I tried using XWindowGetProperty with the _NET_CLIENT_LIST atom and the
root window, but then I wasn't sure what to do with the returned data and
printing it out (at least the ways I tried) didn't show anything in plain
text.
>> An atom is just a unique mapping from a text string to an integer,
>> used for reasons of efficiency, I presume.
>>
>> As for the window id, use the root window. DefaultRootWindow(display)
>> is usually a good start.
>
> Ok, so _NET_CLIENT_LIST seems to map to the integer 301, at least in the
> instance I tried it. What does that integer represent?
The integer is just a number used as a shorthand for _NET_CLIENT_LIST.
Ignore the value of it, it is meaningless.
> I tried using XWindowGetProperty with the _NET_CLIENT_LIST atom and the
> root window, but then I wasn't sure what to do with the returned data and
> printing it out (at least the ways I tried) didn't show anything in plain
> text.
You are probably getting a list of window IDs. These make very little
sense as text.
--
Måns Rullgård
m...@inprovide.com
I was getting unusual characters - diamonds, etc. I've now cast the output
to ints and got something a bit more sane - this list looks more like
yet more atoms than window IDs to me?
141
0
64
1
137
0
32
This is the code (the numbers might mean more this way?):
#include <iostream>
#include <X11/Xlib.h>
#include <unistd.h>
using namespace std;
main()
{
Display *d = XOpenDisplay(0);
if ( d )
{
Atom atom = XInternAtom(d, "_NET_CLIENT_LIST", True);
XFlush(d);
Atom actual_type;
int actual_format;
int max_len = 10000;
unsigned long nitems;
unsigned long bytes_after;
unsigned char *prop;
int status = XGetWindowProperty(d, DefaultRootWindow(d), atom, 0, (max_len+3)/4, False, AnyPropertyType, &actual_type, &actual_format, &nitems, &bytes_after, &prop);
for (int i = 0; i < nitems; i++)
{
int id = prop[i];
cout << id << "\n";
}
}
return 0;
}
>> You are probably getting a list of window IDs. These make very little
>> sense as text.
>
> I was getting unusual characters - diamonds, etc. I've now cast the output
> to ints and got something a bit more sane - this list looks more like
> yet more atoms than window IDs to me?
>
> 141
> 0
> 64
> 1
> 137
> 0
> 32
Window IDs are 32 bits, so the first four of those number are parts of
a single window ID: 0x140008d.
> This is the code (the numbers might mean more this way?):
>
> #include <iostream>
> #include <X11/Xlib.h>
> #include <unistd.h>
> using namespace std;
>
> main()
> {
> Display *d = XOpenDisplay(0);
> if ( d )
> {
> Atom atom = XInternAtom(d, "_NET_CLIENT_LIST", True);
> XFlush(d);
> Atom actual_type;
> int actual_format;
> int max_len = 10000;
> unsigned long nitems;
> unsigned long bytes_after;
> unsigned char *prop;
> int status = XGetWindowProperty(d,
> DefaultRootWindow(d), atom, 0, (max_len+3)/4,
Why the (max_len + 3)/4? Looks like you're rounding it up to a
multiple of 4, but why?
> False, AnyPropertyType, &actual_type,
> &actual_format, &nitems, &bytes_after, &prop);
Use actual_type and actual_format to check what you got.
> for (int i = 0; i < nitems; i++)
> {
> int id = prop[i];
> cout << id << "\n";
> }
As I said above, you are printing individual bytes from 32-bit window
IDs. Cast your prop pointer to something better matching the type of
the values.
--
Måns Rullgård
m...@inprovide.com
I'm sure I figured this out last time, but a couple of dead hard drives
later I'm back at this problem.
Can anyone help me with what data type I should use for my prop
pointer?
Thanks
Rich