static gboolean _eventd_nd_xcb_get_colormap(EventdNdBackendContext *self) { xcb_depth_t *root_depth = NULL; xcb_visualtype_t *root_visual = NULL; xcb_depth_iterator_t depth_iter; for ( depth_iter = xcb_screen_allowed_depths_iterator(self->screen) ; depth_iter.rem ; xcb_depth_next(&depth_iter) ) { xcb_depth_t *d = depth_iter.data; xcb_visualtype_iterator_t visual_iter; for ( visual_iter = xcb_depth_visuals_iterator(d) ; visual_iter.rem ; xcb_visualtype_next(&visual_iter) ) { xcb_visualtype_t *v = visual_iter.data; if ( ( d->depth == 32 ) && ( v->_class >= XCB_VISUAL_CLASS_TRUE_COLOR ) ) { self->depth = d; self->visual = v; } if ( self->screen->root_visual == v->visual_id ) { root_depth = d; root_visual = v; } } } if ( self->visual != NULL ) { xcb_void_cookie_t c; xcb_generic_error_t *e; self->map = xcb_generate_id(self->xcb_connection); c = xcb_create_colormap_checked(self->xcb_connection, XCB_COLORMAP_ALLOC_NONE, self->map, self->screen->root, self->visual->visual_id); e = xcb_request_check(self->xcb_connection, c); if ( e == NULL ) return TRUE; xcb_free_colormap(self->xcb_connection, self->map); free(e); } self->depth = root_depth; self->visual = root_visual; self->map = self->screen->default_colormap; return FALSE; }
void x11_create_visual_and_colormap ( void ) { xcb_depth_iterator_t depth_iter; for ( depth_iter = xcb_screen_allowed_depths_iterator ( xcb->screen ); depth_iter.rem; xcb_depth_next ( &depth_iter ) ) { xcb_depth_t *d = depth_iter.data; xcb_visualtype_iterator_t visual_iter; for ( visual_iter = xcb_depth_visuals_iterator ( d ); visual_iter.rem; xcb_visualtype_next ( &visual_iter ) ) { xcb_visualtype_t *v = visual_iter.data; if ( ( d->depth == 32 ) && ( v->_class == XCB_VISUAL_CLASS_TRUE_COLOR ) ) { depth = d; visual = v; } if ( xcb->screen->root_visual == v->visual_id ) { root_depth = d; root_visual = v; } } } if ( visual != NULL ) { xcb_void_cookie_t c; xcb_generic_error_t *e; map = xcb_generate_id ( xcb->connection ); c = xcb_create_colormap_checked ( xcb->connection, XCB_COLORMAP_ALLOC_NONE, map, xcb->screen->root, visual->visual_id ); e = xcb_request_check ( xcb->connection, c ); if ( e ) { depth = NULL; visual = NULL; free ( e ); } } if ( visual == NULL ) { depth = root_depth; visual = root_visual; map = xcb->screen->default_colormap; } }