<div><p>I am trying to learn the XCB library. The following program does not even show the window. What am I doing wrong?</p><p> </p><p>#include <unistd.h><br />#include <stdio.h><br />#include <stdlib.h><br />#include <xcb/xcb.h><br />#include <math.h><br /> <br />// cc program.c -o program -lxcb -lm<br />int main(void)<br />{<!-- --><br />        xcb_connection_t *connection          = xcb_connect(NULL, NULL);;<br />        uint8_t coordinate_mode               = XCB_COORD_MODE_ORIGIN;<br />        const xcb_setup_t *setup              = xcb_get_setup(connection);<br />        xcb_screen_iterator_t screen_iterator = xcb_setup_roots_iterator(setup);<br />        xcb_screen_t *screen                  = screen_iterator.data;<br />        xcb_drawable_t drawable               = screen -> root;<br />        uint32_t value_mask                   = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES;<br />        uint32_t value_list[2]                = {screen -> black_pixel, 0};<br />        xcb_gcontext_t gc                     = xcb_generate_id(connection);<br />        uint32_t points_len                   = 0;<br />        uint16_t res_width                    = 640;<br />        uint16_t res_height                   = 480;<br />        xcb_point_t *points                   = malloc(res_width * res_height * sizeof(xcb_point_t));<br />        xcb_generic_event_t *event            = NULL;<br /> <br />        xcb_create_gc(connection, gc, drawable, value_mask, value_list);<br />        value_mask                            = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;<br />        value_list[0]                         = screen -> white_pixel;<br />        value_list[1]                         = XCB_EVENT_MASK_EXPOSURE;<br />        xcb_create_window(connection,<br />                        XCB_COPY_FROM_PARENT,<br />                        drawable,<br />                        screen -> root,<br />                        0, 0,<br />                        res_width, res_height,<br />                        10,<br />                        XCB_WINDOW_CLASS_INPUT_OUTPUT,<br />                        screen -> root_visual,<br />                        value_mask, value_list);<br />        xcb_map_window(connection, drawable);<br />        xcb_flush(connection);<br />        // Map centered circle in memory<br />        while(points_len < 360) {<!-- --><br />                points[points_len].x          = (res_width/2) + points_len;<br />                points[points_len].y          = 2 * points[points_len].x * pow(M_PI, 2);<br />                ++points_len;<br />        }<br />        // Set circle color<br />        xcb_change_gc(connection, gc, value_mask, value_list);<br />        // Draw it on the window<br />        while((event = xcb_wait_for_event(connection))) {<!-- --><br />                switch(event -> response_type & ~0x80) { // What does this statement stand for?<br />                        case XCB_EXPOSE: {<!-- --><br />                                xcb_poly_point(connection, coordinate_mode, drawable, gc, points_len, points);<br />                                xcb_flush(connection);<br />                                break;<br />                        }<br />                        default: {<!-- --><br />                                break;<br />                        }<br />                }<br />                free(event);<br />        }<br />        sleep(5);<br />        exit(EXIT_SUCCESS);<br />}<br /> <br /> </p></div>