Discussion:
[Xcb] Examples on using xcb-util-wm?
Christophe Lohr
2018-09-27 15:41:31 UTC
Permalink
Hi,
  I'm looking for some piece of code showing the use of the xcb_ewmh module.
Let say I want to retreive _NET_CURRENT_DESKTOP and _NET_CLIENT_LIST
(i.e. or something like the "wmctrl -l" command)
How to proceed?
What documentation should I read?

Best regards
Christophe
Uli Schlachter
2018-09-27 16:21:17 UTC
Permalink
Post by Christophe Lohr
Hi,
  I'm looking for some piece of code showing the use of the xcb_ewmh module.
Let say I want to retreive _NET_CURRENT_DESKTOP and _NET_CLIENT_LIST
(i.e. or something like the "wmctrl -l" command)
How to proceed?
What documentation should I read?
I took a look at the header file:

You begin by initializing a xcb_ewmh_connection_t via

xcb_ewmh_connection_t ewmh;
if (!xcb_ewmh_init_atoms_replies(&ewmh,
xcb_ewmh_init_atoms(c, &ewmh), NULL))
puts("init failed");

Then you can query _NET_CURRENT_DESKTOP via:

uint32_t current_desktop;
xcb_ewmh_get_current_desktop_reply(&ewmh,
xcb_ewmh_get_current_desktop(&ewmh, 0),
&current_desktop, 0);
(This function returns 0 on errors)
(now current_desktop contains the current desktop value)


Querying the client list works similar, but instead of an uint32_t, you
get an xcb_ewmh_get_windows_reply_t that is filled for you. This has a
an array ->windows of size ->windows_len containing the windows.

You can clean this up with xcb_ewmh_get_windows_reply_wipe() (think: free).

I hope this helps.

Cheers,
Uli
--
Sent from my Game Boy.
Christophe Lohr
2018-09-28 06:41:44 UTC
Permalink
Hi,
  Many thanks for your indications.

Could you please tell me more about the  _unchecked()  variants ?

Is it because sometimes the X11 specifications says "This property
SHOULD be set and updated by the Window Manager." ?
Or is it because errors are managed in a specific way?
or something else?

Regards
Christophe
Post by Uli Schlachter
Post by Christophe Lohr
Hi,
  I'm looking for some piece of code showing the use of the xcb_ewmh module.
Let say I want to retreive _NET_CURRENT_DESKTOP and _NET_CLIENT_LIST
(i.e. or something like the "wmctrl -l" command)
How to proceed?
What documentation should I read?
You begin by initializing a xcb_ewmh_connection_t via
xcb_ewmh_connection_t ewmh;
if (!xcb_ewmh_init_atoms_replies(&ewmh,
xcb_ewmh_init_atoms(c, &ewmh), NULL))
puts("init failed");
uint32_t current_desktop;
xcb_ewmh_get_current_desktop_reply(&ewmh,
xcb_ewmh_get_current_desktop(&ewmh, 0),
&current_desktop, 0);
(This function returns 0 on errors)
(now current_desktop contains the current desktop value)
Querying the client list works similar, but instead of an uint32_t, you
get an xcb_ewmh_get_windows_reply_t that is filled for you. This has a
an array ->windows of size ->windows_len containing the windows.
You can clean this up with xcb_ewmh_get_windows_reply_wipe() (think: free).
I hope this helps.
Cheers,
Uli
Uli Schlachter
2018-09-28 07:53:38 UTC
Permalink
Hi,

I would bet that the _unchecked() variants do the same thing that they
do in libxcb:

With a checked request, any error that this causes is returned to you
via the last argument to the _reply() function. For example:

xcb_generic_error *e = NULL;
xcb_get_FOO_reply(c, xcb_get_FOO(c), &e);

if FOO failed, e, will now point to the error.

If you use an unchecked request, the error is not given to you, but is
instead given to your main loop as an event (via e.g. xcb_wait_for_event()).

Cheers,
Uli
Post by Christophe Lohr
Hi,
  Many thanks for your indications.
Could you please tell me more about the  _unchecked()  variants ?
Is it because sometimes the X11 specifications says "This property
SHOULD be set and updated by the Window Manager." ?
Or is it because errors are managed in a specific way?
or something else?
Regards
Christophe
Post by Uli Schlachter
Post by Christophe Lohr
Hi,
  I'm looking for some piece of code showing the use of the xcb_ewmh module.
Let say I want to retreive _NET_CURRENT_DESKTOP and _NET_CLIENT_LIST
(i.e. or something like the "wmctrl -l" command)
How to proceed?
What documentation should I read?
You begin by initializing a xcb_ewmh_connection_t via
xcb_ewmh_connection_t ewmh;
if (!xcb_ewmh_init_atoms_replies(&ewmh,
xcb_ewmh_init_atoms(c, &ewmh), NULL))
puts("init failed");
uint32_t current_desktop;
xcb_ewmh_get_current_desktop_reply(&ewmh,
xcb_ewmh_get_current_desktop(&ewmh, 0),
&current_desktop, 0);
(This function returns 0 on errors)
(now current_desktop contains the current desktop value)
Querying the client list works similar, but instead of an uint32_t, you
get an xcb_ewmh_get_windows_reply_t that is filled for you. This has a
an array ->windows of size ->windows_len containing the windows.
You can clean this up with xcb_ewmh_get_windows_reply_wipe() (think: free).
I hope this helps.
Cheers,
Uli
_______________________________________________
Xcb mailing list
https://lists.freedesktop.org/mailman/listinfo/xcb
--
Sent from my Game Boy.
Christophe Lohr
2018-09-28 08:30:55 UTC
Permalink
Hi,
  Many thanks for your explanations.

Does it means that processing a checked reply is "more synchronous" than
processing an unchechecked one?
In other words, what would you recommend?

Best regards
Christophe
Post by Uli Schlachter
Hi,
I would bet that the _unchecked() variants do the same thing that they
With a checked request, any error that this causes is returned to you
xcb_generic_error *e = NULL;
xcb_get_FOO_reply(c, xcb_get_FOO(c), &e);
if FOO failed, e, will now point to the error.
If you use an unchecked request, the error is not given to you, but is
instead given to your main loop as an event (via e.g. xcb_wait_for_event()).
Cheers,
Uli
Uli Schlachter
2018-09-28 08:49:43 UTC
Permalink
Hi,
Post by Christophe Lohr
Does it means that processing a checked reply is "more synchronous" than
processing an unchechecked one?
In both cases, xcb has to wait for either a reply or an error (so that
it knows there will be no answer). So, in terms of waiting for the X11
server, this is the same.
Post by Christophe Lohr
In other words, what would you recommend?
I would recommend not to worry too much about "waiting for the X11
server" unless something actually is so slow that it causes issues.

Cheers,
Uli
--
Sent from my Game Boy.
Christophe Lohr
2018-09-28 15:11:53 UTC
Permalink
Hi,
  May I ask another question: what is the purpose of 
xcb_ewmh_get_*_from_reply() functions?

Let's say I want to check if a given windows is fullscreen.
The answer is within atoms returned by xcb_ewmh_get_wm_state_reply().
Does xcb_ewmh_get_wm_state_from_reply() helps me to check
_NET_WM_STATE_FULLSCREEN?
How?

Best regards
Christophe
Uli Schlachter
2018-09-29 06:17:24 UTC
Permalink
Hi,
Post by Christophe Lohr
  May I ask another question: what is the purpose of 
xcb_ewmh_get_*_from_reply() functions?
I can't really say what the purpose should be, but I would say that
*_reply() just calls xcb_get_property_reply() and then *_from_reply()
with the result of that.
Post by Christophe Lohr
Let's say I want to check if a given windows is fullscreen.
The answer is within atoms returned by xcb_ewmh_get_wm_state_reply().
Does xcb_ewmh_get_wm_state_from_reply() helps me to check
_NET_WM_STATE_FULLSCREEN?
How?
Well, you use the library to set up an instance of
xcb_ewmh_get_atoms_reply_t. Then you check if any of the ->atoms_len
entries in ->atoms is equal to the _NET_WM_STATE_FULLSCREEN atom (which
you previously got via xcb_intern_atom).

Uli
--
Sent from my Game Boy.
Loading...