[Xcb] Handling Close Event

Cinolt cinolt.yk at gmail.com
Fri Dec 31 10:00:33 PST 2010


I've changed the property as you specified, however it seems the event isn't
being sent. Here is my code:

#include <stdio.h>
#include <stdint.h>
#include <xcb/xcb.h>

int main()
{
  xcb_connection_t* c = xcb_connect(0, 0);
  xcb_screen_t* s = xcb_setup_roots_iterator(xcb_get_setup(c)).data;

  xcb_window_t w = xcb_generate_id(c);

  const uint32_t values = XCB_EVENT_MASK_EXPOSURE;

  xcb_create_window(c, 0, w, (*s).root, 0, 0, 128, 128, 0,
XCB_WINDOW_CLASS_INPUT_OUTPUT, (*s).root_visual, XCB_CW_EVENT_MASK,
&values);

  xcb_intern_atom_cookie_t cookie = xcb_intern_atom(c, 1, 12,
"WM_PROTOCOLS");
  xcb_intern_atom_reply_t* reply = xcb_intern_atom_reply(c, cookie, 0);

  xcb_change_property(c, XCB_PROP_MODE_REPLACE, w, (*reply).atom, 4, 32, 1,
"WM_DELETE_WINDOW");

  xcb_map_window(c, w);
  xcb_flush(c);

  xcb_generic_event_t* event;
  while((event = xcb_wait_for_event(c)))
  {
    puts("Event occurred");
    switch((*event).response_type & ~0x80)
    {
      case XCB_EXPOSE:
        puts("Expose");
        break;
    }
  }

  return 0;
}

It should output "Event occurred" when any event occurs, and it does for
Expose events, but not when I close out of the window. Any suggestions?

On Fri, Dec 31, 2010 at 5:55 AM, Vincent Torri <vtorri at univ-evry.fr> wrote:

>
>
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/xcb/attachments/20101231/3b132d55/attachment.html>


More information about the Xcb mailing list