diff --git a/src/restore_layout.c b/src/restore_layout.c index 9edf4b11..d567e971 100644 --- a/src/restore_layout.c +++ b/src/restore_layout.c @@ -15,6 +15,8 @@ #include #endif +#define TEXT_PADDING logical_px(2) + typedef struct placeholder_state { /** The X11 placeholder window. */ xcb_window_t window; @@ -24,10 +26,8 @@ typedef struct placeholder_state { /** Current size of the placeholder window (to detect size changes). */ Rect rect; - /** The pixmap to render on (back buffer). */ - xcb_pixmap_t pixmap; - /** The graphics context for “pixmap”. */ - xcb_gcontext_t gc; + /** The drawable surface */ + surface_t surface; TAILQ_ENTRY(placeholder_state) state; @@ -138,17 +138,15 @@ void restore_connect(void) { } static void update_placeholder_contents(placeholder_state *state) { - xcb_change_gc(restore_conn, state->gc, XCB_GC_FOREGROUND, - (uint32_t[]){config.client.placeholder.background.colorpixel}); - xcb_poly_fill_rectangle(restore_conn, state->pixmap, state->gc, 1, - (xcb_rectangle_t[]){{0, 0, state->rect.width, state->rect.height}}); + const color_t foreground = config.client.placeholder.text; + const color_t background = config.client.placeholder.background; + + draw_util_clear_surface(&(state->surface), background); // TODO: make i3font functions per-connection, at least these two for now…? xcb_flush(restore_conn); xcb_aux_sync(restore_conn); - set_font_colors(state->gc, config.client.placeholder.text, config.client.placeholder.background); - Match *swallows; int n = 0; TAILQ_FOREACH(swallows, &(state->con->swallow_head), matches) { @@ -175,7 +173,10 @@ static void update_placeholder_contents(placeholder_state *state) { DLOG("con %p (placeholder 0x%08x) line %d: %s\n", state->con, state->window, n, serialized); i3String *str = i3string_from_utf8(serialized); - draw_text(str, state->pixmap, state->gc, NULL, 2, (n * (config.font.height + 2)) + 2, state->rect.width - 2); + draw_util_text(str, &(state->surface), foreground, background, + TEXT_PADDING, + (n * (config.font.height + TEXT_PADDING)) + TEXT_PADDING, + state->rect.width - 2 * TEXT_PADDING); i3string_free(str); n++; free(serialized); @@ -186,7 +187,7 @@ static void update_placeholder_contents(placeholder_state *state) { int text_width = predict_text_width(line); int x = (state->rect.width / 2) - (text_width / 2); int y = (state->rect.height / 2) - (config.font.height / 2); - draw_text(line, state->pixmap, state->gc, NULL, x, y, text_width); + draw_util_text(line, &(state->surface), foreground, background, x, y, text_width); i3string_free(line); xcb_flush(conn); xcb_aux_sync(conn); @@ -228,11 +229,8 @@ static void open_placeholder_window(Con *con) { state->window = placeholder; state->con = con; state->rect = con->rect; - state->pixmap = xcb_generate_id(restore_conn); - xcb_create_pixmap(restore_conn, root_depth, state->pixmap, - state->window, state->rect.width, state->rect.height); - state->gc = xcb_generate_id(restore_conn); - xcb_create_gc(restore_conn, state->gc, state->pixmap, XCB_GC_GRAPHICS_EXPOSURES, (uint32_t[]){0}); + + draw_util_surface_init(conn, &(state->surface), placeholder, get_visualtype(root_screen), state->rect.width, state->rect.height); update_placeholder_contents(state); TAILQ_INSERT_TAIL(&state_head, state, state); @@ -286,8 +284,7 @@ bool restore_kill_placeholder(xcb_window_t placeholder) { continue; xcb_destroy_window(restore_conn, state->window); - xcb_free_pixmap(restore_conn, state->pixmap); - xcb_free_gc(restore_conn, state->gc); + draw_util_surface_free(restore_conn, &(state->surface)); TAILQ_REMOVE(&state_head, state, state); free(state); DLOG("placeholder window 0x%08x destroyed.\n", placeholder); @@ -306,14 +303,8 @@ static void expose_event(xcb_expose_event_t *event) { DLOG("refreshing window 0x%08x contents (con %p)\n", state->window, state->con); - /* Since we render to our pixmap on every change anyways, expose events - * only tell us that the X server lost (parts of) the window contents. We - * can handle that by copying the appropriate part from our pixmap to the - * window. */ - xcb_copy_area(restore_conn, state->pixmap, state->window, state->gc, - event->x, event->y, event->x, event->y, - event->width, event->height); - xcb_flush(restore_conn); + update_placeholder_contents(state); + return; } @@ -338,19 +329,10 @@ static void configure_notify(xcb_configure_notify_event_t *event) { state->rect.width = event->width; state->rect.height = event->height; - xcb_free_pixmap(restore_conn, state->pixmap); - xcb_free_gc(restore_conn, state->gc); - - state->pixmap = xcb_generate_id(restore_conn); - xcb_create_pixmap(restore_conn, root_depth, state->pixmap, - state->window, state->rect.width, state->rect.height); - state->gc = xcb_generate_id(restore_conn); - xcb_create_gc(restore_conn, state->gc, state->pixmap, XCB_GC_GRAPHICS_EXPOSURES, (uint32_t[]){0}); + draw_util_surface_set_size(&(state->surface), state->rect.width, state->rect.height); update_placeholder_contents(state); - xcb_copy_area(restore_conn, state->pixmap, state->window, state->gc, - 0, 0, 0, 0, state->rect.width, state->rect.height); - xcb_flush(restore_conn); + return; }