[Xcb] Handling Close Event

Vincent Torri vtorri at univ-evry.fr
Fri Dec 31 02:55:28 PST 2010



On Fri, 31 Dec 2010, Cinolt wrote:

> Hello, I'm assuming that I need to call xcb_change_property on my window to
> change one of its properties. What should I set the type argument to, and am
> I correct in assuming that the data argument should be "WM_DELETE_WINDOW"?
>
>    xcb_void_cookie_t xcb_change_property (xcb_connection_t *c,
> /* Connection to the X server */
>                                           uint8_t          mode,
> /* Property mode */
>                                           xcb_window_t     window,
> /* Window */
>                                           xcb_atom_t       property,
> /* Property to change */
>                                           xcb_atom_t       type,
> /* Type of the property */
>                                           uint8_t          format,
> /* Format of the property (8, 16, 32) */
>                                           uint32_t         data_len,
> /* Length of the data parameter */
>                                           const void      *data);    /* Data */

I give you the way to find it by yourself if later you need to use ICCCM 
or EWMH again).

In the link i gave you [1], it is a subsection of the ClientMessage events 
[2]. It is said that the window you want to delete should have the 
WM_PROTOCOLS property, with the atom WM_DELETE_WINDOW and that is it 
related to the ClientMessage event (see section 4.1.2.7) [3].

So you need to change the property of your window. And indeed, you use 
xcb_change_property() to do that:

xcb_void_cookie_t xcb_change_property(
   xcb_connection_t *c,        /* Connection */
   uint8_t          mode,      /* Property mode */
   xcb_window_t     window,    /* Window */
   xcb_atom_t       property,  /* Property to change */
   xcb_atom_t       type,      /* Type of the property */
   uint8_t          format,    /* Format of the property (8, 16, 32) */
   uint32_t         data_len,  /* Length of the data parameter */
   const void      *data);     /* Data */

  * the parameters c and window are trivial.
  * mode: what you do with that property (replacing a value, append or
    prepend it). Replace it by passing XCB_PROP_MODE_REPLACE
  * property: create an atom with the "WM_PROTOCOLS" string (see
    xcb_inter_atom* functions)
  * type: the type of the property WM_PROTOCOLS is an atom (first ine of
    [3], so create an atom with the "ATOM" string (or use the value 4
    for the parameter 'type' as it is a predefined value).
  * format: as [2] mentions, it is 32
  * data is an array of the atoms you want to set for the WM_PROTOCOLS
    property. Here, it is just one atom: the WM_DELETE_WINDOW one (create
    it with "WM_DELETE_WINDOW")
  * data_len is the length of the above array, so pass just 1.

Note that you can pass several atoms and not just only one: see [3] or 
[4].

So now, when that window is deleted by clicking on the cross of the 
titlebar, you'll get a ClientMessage event in your event loop. See [2] to 
know what to do with that event.

Vincent

[1] http://tronche.com/gui/x/icccm/sec-4.html#s-4.2.8.1
[2] http://tronche.com/gui/x/icccm/sec-4.html#s-4.2.8
[3] http://tronche.com/gui/x/icccm/sec-4.html#s-4.1.2.7
[4] http://standards.freedesktop.org/wm-spec/wm-spec-1.3.html#id2507897


More information about the Xcb mailing list