Drawable is not displayed

Junk Mail <ireallyhatespam-zJpx2rpV7r/[email protected]> Wed, 11 Mar 2020 07:58:42 -0300
Newsgroups gmane.comp.freedesktop.xcb
Message-ID <[email protected]>
I am trying to learn the XCB library. The following program does not even show the window. What am I doing wrong?

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <xcb/xcb.h>
#include <math.h>

// cc program.c -o program -lxcb -lm
int main(void)
{
xcb_connection_t *connection = xcb_connect(NULL, NULL);;
uint8_t coordinate_mode = XCB_COORD_MODE_ORIGIN;
const xcb_setup_t *setup = xcb_get_setup(connection);
xcb_screen_iterator_t screen_iterator = xcb_setup_roots_iterator(setup);
xcb_screen_t *screen = screen_iterator.data;
xcb_drawable_t drawable = screen -> root;
uint32_t value_mask = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES;
uint32_t value_list[2] = {screen -> black_pixel, 0};
xcb_gcontext_t gc = xcb_generate_id(connection);
uint32_t points_len = 0;
uint16_t res_width = 640;
uint16_t res_height = 480;
xcb_point_t *points = malloc(res_width * res_height * sizeof(xcb_point_t));
xcb_generic_event_t *event = NULL;

xcb_create_gc(connection, gc, drawable, value_mask, value_list);
value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
value_list[0] = screen -> white_pixel;
value_list[1] = XCB_EVENT_MASK_EXPOSURE;
xcb_create_window(connection,
XCB_COPY_FROM_PARENT,
drawable,
screen -> root,
0, 0,
res_width, res_height,
10,
XCB_WINDOW_CLASS_INPUT_OUTPUT,
screen -> root_visual,
value_mask, value_list);
xcb_map_window(connection, drawable);
xcb_flush(connection);
// Map centered circle in memory
while(points_len < 360) {
points[points_len].x = (res_width/2) + points_len;
points[points_len].y = 2 * points[points_len].x * pow(M_PI, 2);
++points_len;
}
// Set circle color
xcb_change_gc(connection, gc, value_mask, value_list);
// Draw it on the window
while((event = xcb_wait_for_event(connection))) {
switch(event -> response_type & ~0x80) { // What does this statement stand for?
case XCB_EXPOSE: {
xcb_poly_point(connection, coordinate_mode, drawable, gc, points_len, points);
xcb_flush(connection);
break;
}
default: {
break;
}
}
free(event);
}
sleep(5);
exit(EXIT_SUCCESS);
}

_______________________________________________
Xcb mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/xcb