From 98cb2cb01c798da7f1eb6509e85cff7e1562cfa4 Mon Sep 17 00:00:00 2001 From: Courtney Goeltzenleuchter Date: Thu, 6 Nov 2014 14:27:52 -0700 Subject: [PATCH] demo: cube: Process destroy window Demo was not exiting cleanly when the window close button was clicked. Found this solution on-line: http://lists.freedesktop.org/pipermail/xcb/2010-December/006713.html --- demos/cube.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/demos/cube.c b/demos/cube.c index e3f3c45..923b8a8 100644 --- a/demos/cube.c +++ b/demos/cube.c @@ -260,6 +260,7 @@ struct demo { XGL_CMD_BUFFER cmd; xcb_window_t window; + xcb_intern_atom_reply_t *atom_wm_delete_window; bool quit; XGL_UINT current_buffer; @@ -1136,10 +1137,17 @@ static void demo_prepare(struct demo *demo) static void demo_handle_event(struct demo *demo, const xcb_generic_event_t *event) { - switch (event->response_type & 0x7f) { + u_int8_t event_code = event->response_type & 0x7f; + switch (event_code) { case XCB_EXPOSE: demo_draw(demo); break; + case XCB_CLIENT_MESSAGE: + if((*(xcb_client_message_event_t*)event).data.data32[0] == + (*demo->atom_wm_delete_window).atom) { + demo->quit = true; + } + break; case XCB_KEY_RELEASE: { const xcb_key_release_event_t *key = @@ -1209,6 +1217,19 @@ static void demo_create_window(struct demo *demo) demo->screen->root_visual, value_mask, value_list); + /* Magic code that will send notification when window is destroyed */ + xcb_intern_atom_cookie_t cookie = xcb_intern_atom(demo->connection, 1, 12, + "WM_PROTOCOLS"); + xcb_intern_atom_reply_t* reply = xcb_intern_atom_reply(demo->connection, cookie, 0); + + xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(demo->connection, 0, 16, "WM_DELETE_WINDOW"); + demo->atom_wm_delete_window = xcb_intern_atom_reply(demo->connection, cookie2, 0); + + xcb_change_property(demo->connection, XCB_PROP_MODE_REPLACE, + demo->window, (*reply).atom, 4, 32, 1, + &(*demo->atom_wm_delete_window).atom); + free(reply); + xcb_map_window(demo->connection, demo->window); } -- 2.7.4