- /* For custom visuals, we need to create a colormap before creating
- * this window. It will be freed directly after creating the window. */
- xcb_visualid_t visual = get_visualid_by_depth(depth);
- xcb_colormap_t win_colormap = xcb_generate_id(conn);
- xcb_create_colormap_checked(conn, XCB_COLORMAP_ALLOC_NONE, win_colormap, root, visual);
+ xcb_visualid_t visual = get_visualid_by_depth(con->depth);
+ xcb_colormap_t win_colormap;
+ if (con->depth != root_depth) {
+ /* We need to create a custom colormap. */
+ win_colormap = xcb_generate_id(conn);
+ xcb_create_colormap(conn, XCB_COLORMAP_ALLOC_NONE, win_colormap, root, visual);
+ con->colormap = win_colormap;
+ } else {
+ /* Use the default colormap. */
+ win_colormap = colormap;
+ con->colormap = XCB_NONE;
+ }