Search code examples
linuxxcb

How to exit program with close button in XCB


Can not find any reference on how to close application by the "X" button. I'm programming using XCB and want to close the program by the "X" button. I looked and can't find anything about it. I know how to close by pressing a button. Also, by pressing the "X" button the window looks like it closes but doesn't.


Solution

  • I struggled on this topic some time ago as well.

    Look at http://marc.info/?l=freedesktop-xcb&m=129381953404497 .

    The key is to store the cookie for the WM_DELETE_WINDOW in a separate cookie...

    xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(c, 0, 16, "WM_DELETE_WINDOW");
    xcb_intern_atom_reply_t* reply2 = xcb_intern_atom_reply(c, cookie2, 0);
    

    and in the event loop compare the client_message with the cookie2

    case XCB_CLIENT_MESSAGE:
    {
        if((*(xcb_client_message_event_t*)event).data.data32[0] == (*reply2).atom) ...
    }