From d48c9b1e337a3eb663c6f0f8af28c3b52f405ab4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ingo=20B=C3=BCrk?= Date: Wed, 14 Sep 2016 09:13:17 +0200 Subject: [PATCH] Fix colormap handling for containers. (#2450) This commit correctly handles colormaps by * Using the static default colormap we determine on startup if the con has the corresponding depth. This avoids creating pointless colormaps. * Not freeing the default colormap to not have stray colormaps on containers. This fixes an issue with certain programs such as xwd. * Creating a custom colormap when necessary and freeing it when the container is killed. fixes #2435 --- include/data.h | 3 +++ src/x.c | 22 +++++++++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/include/data.h b/include/data.h index 9f835a23..247cd3c5 100644 --- a/include/data.h +++ b/include/data.h @@ -699,4 +699,7 @@ struct Con { /* Depth of the container window */ uint16_t depth; + + /* The colormap for this con if a custom one is used. */ + xcb_colormap_t colormap; }; diff --git a/src/x.c b/src/x.c index 6fd3297a..f3e02fa4 100644 --- a/src/x.c +++ b/src/x.c @@ -105,11 +105,18 @@ void x_con_init(Con *con) { uint32_t mask = 0; uint32_t values[5]; - /* 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(con->depth); - xcb_colormap_t win_colormap = xcb_generate_id(conn); - xcb_create_colormap_checked(conn, XCB_COLORMAP_ALLOC_NONE, win_colormap, root, visual); + 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; + } /* We explicitly set a background color and border color (even though we * don’t even have a border) because the X11 server requires us to when @@ -144,9 +151,6 @@ void x_con_init(Con *con) { (strlen("i3-frame") + 1) * 2, "i3-frame\0i3-frame\0"); - if (win_colormap != XCB_NONE) - xcb_free_colormap(conn, win_colormap); - struct con_state *state = scalloc(1, sizeof(struct con_state)); state->id = con->frame.id; state->mapped = false; @@ -229,6 +233,10 @@ void x_move_win(Con *src, Con *dest) { void x_con_kill(Con *con) { con_state *state; + if (con->colormap != XCB_NONE) { + xcb_free_colormap(conn, con->colormap); + } + draw_util_surface_free(conn, &(con->frame)); draw_util_surface_free(conn, &(con->frame_buffer)); xcb_destroy_window(conn, con->frame.id); -- 2.39.2