From eafc7af60681e5397e72bcdf5b1b807c5f1e6713 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Tarl=C3=A1=20Cardoso=20Lemos?= Date: Sun, 13 Nov 2011 21:23:25 -0200 Subject: [PATCH] Make all programs use draw_text. --- i3-config-wizard/main.c | 8 ++++++-- i3-input/main.c | 5 +++-- i3-nagbar/main.c | 11 +++++------ src/render.c | 4 +++- src/sighandler.c | 8 ++------ src/x.c | 38 +++++++------------------------------- 6 files changed, 26 insertions(+), 48 deletions(-) diff --git a/i3-config-wizard/main.c b/i3-config-wizard/main.c index cdce0653..a6cd760d 100644 --- a/i3-config-wizard/main.c +++ b/i3-config-wizard/main.c @@ -112,9 +112,10 @@ static int handle_expose() { xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND, (uint32_t[]){ get_colorpixel("#000000") }); xcb_poly_fill_rectangle(conn, pixmap, pixmap_gc, 1, &border); - xcb_change_gc(conn, pixmap_gc, XCB_GC_FONT, (uint32_t[]){ font.id }); + set_font(&font); -#define txt(x, row, text) xcb_image_text_8(conn, strlen(text), pixmap, pixmap_gc, x, (row * font.height) + 2, text) +#define txt(x, row, text) \ + draw_text(text, strlen(text), false, pixmap, pixmap_gc, x, (row - 1) * font.height + 4) if (current_step == STEP_WELCOME) { /* restore font color */ @@ -150,12 +151,14 @@ static int handle_expose() { else txt(31, 4, ""); /* the selected modifier */ + set_font(&bold_font); xcb_change_gc(conn, pixmap_gc, XCB_GC_FONT, (uint32_t[]){ bold_font.id }); if (modifier == MOD_Mod4) txt(31, 4, ""); else txt(31, 5, ""); /* green */ + set_font(&font); xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND | XCB_GC_FONT, (uint32_t[]) { get_colorpixel("#00FF00"), font.id }); @@ -437,6 +440,7 @@ int main(int argc, char *argv[]) { xcb_numlock_mask = get_mod_mask_for(XCB_NUM_LOCK, symbols, modmap_reply); font = load_font(pattern, true); + set_font(&font); bold_font = load_font(patternbold, true); /* Open an input window */ diff --git a/i3-input/main.c b/i3-input/main.c index 3eabd15d..3d45206d 100644 --- a/i3-input/main.c +++ b/i3-input/main.c @@ -104,8 +104,8 @@ static int handle_expose(void *data, xcb_connection_t *conn, xcb_expose_event_t memcpy(full_text, prompt, prompt_len * 2); memcpy(full_text + (prompt_len * 2), con, input_position * 2); } - xcb_image_text_16(conn, input_position + prompt_len, pixmap, pixmap_gc, 4 /* X */, - font.height + 2 /* Y = baseline of font */, (xcb_char2b_t*)full_text); + if (input_position + prompt_len != 0) + draw_text(full_text, input_position + prompt_len, true, pixmap, pixmap_gc, 4, 4); /* Copy the contents of the pixmap to the real window */ xcb_copy_area(conn, pixmap, win, pixmap_gc, 0, 0, 0, 0, /* */ 500, font.height + 8); @@ -361,6 +361,7 @@ int main(int argc, char *argv[]) { symbols = xcb_key_symbols_alloc(conn); font = load_font(pattern, true); + set_font(&font); /* Open an input window */ win = xcb_generate_id(conn); diff --git a/i3-nagbar/main.c b/i3-nagbar/main.c index 4d4e253a..525e3221 100644 --- a/i3-nagbar/main.c +++ b/i3-nagbar/main.c @@ -135,8 +135,7 @@ static int handle_expose(xcb_connection_t *conn, xcb_expose_event_t *event) { values[0] = color_text; values[1] = color_background; xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND | XCB_GC_BACKGROUND, values); - xcb_image_text_8(conn, strlen(prompt), pixmap, pixmap_gc, 4 + 4/* X */, - font.height + 2 + 4 /* Y = baseline of font */, prompt); + draw_text(prompt, strlen(prompt), false, pixmap, pixmap_gc, 4 + 4, 4 + 4); /* render close button */ int line_width = 4; @@ -163,8 +162,7 @@ static int handle_expose(xcb_connection_t *conn, xcb_expose_event_t *event) { values[1] = color_button_background; values[2] = 1; xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND | XCB_GC_BACKGROUND | XCB_GC_LINE_WIDTH, values); - xcb_image_text_8(conn, strlen("x"), pixmap, pixmap_gc, y - w - line_width + (w / 2) - 4/* X */, - font.height + 2 + 4 - 1/* Y = baseline of font */, "X"); + draw_text("X", 1, false, pixmap, pixmap_gc, y - w - line_width + w / 2 - 4, 4 + 4 - 1); y -= w; y -= 20; @@ -194,8 +192,8 @@ static int handle_expose(xcb_connection_t *conn, xcb_expose_event_t *event) { values[0] = color_text; values[1] = color_button_background; xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND | XCB_GC_BACKGROUND, values); - xcb_image_text_8(conn, strlen(buttons[c].label), pixmap, pixmap_gc, y - w - line_width + 6/* X */, - font.height + 2 + 3/* Y = baseline of font */, buttons[c].label); + draw_text(buttons[c].label, strlen(buttons[c].label), false, pixmap, pixmap_gc, + y - w - line_width + 6, 4 + 3); y -= w; } @@ -304,6 +302,7 @@ int main(int argc, char *argv[]) { } font = load_font(pattern, true); + set_font(&font); /* Open an input window */ win = xcb_generate_id(conn); diff --git a/src/render.c b/src/render.c index d85d16a7..ed78895e 100644 --- a/src/render.c +++ b/src/render.c @@ -193,7 +193,9 @@ void render_con(Con *con, bool render_fullscreen) { } /* find the height for the decorations */ - int deco_height = config.font.height + 5; + int deco_height = config.font.height + 4; + if (config.font.height & 0x01) + ++deco_height; /* precalculate the sizes to be able to correct rounding errors */ int sizes[children]; diff --git a/src/sighandler.c b/src/sighandler.c index c7c9ce7f..c0abed9a 100644 --- a/src/sighandler.c +++ b/src/sighandler.c @@ -50,12 +50,8 @@ static int sig_draw_window(xcb_window_t win, int width, int height, int font_hei xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND, (uint32_t[]){ get_colorpixel("#FFFFFF") }); for (int i = 0; i < sizeof(crash_text) / sizeof(char*); i++) { - int text_len = strlen(crash_text[i]); - xcb_char2b_t *full_text = convert_utf8_to_ucs2(crash_text[i], &text_len); - xcb_image_text_16(conn, text_len, pixmap, pixmap_gc, 8 /* X */, - 3 + (i + 1) * font_height /* Y = baseline of font */, - (xcb_char2b_t*)full_text); - free(full_text); + draw_text(crash_text[i], strlen(crash_text[i]), false, + pixmap, pixmap_gc, 8, 3 + (i - 1) * font_height); } /* Copy the contents of the pixmap to the real window */ diff --git a/src/x.c b/src/x.c index 61824d58..f67de0ca 100644 --- a/src/x.c +++ b/src/x.c @@ -411,22 +411,15 @@ void x_draw_decoration(Con *con) { uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_BACKGROUND | XCB_GC_FONT; uint32_t values[] = { p->color->text, p->color->background, config.font.id }; xcb_change_gc(conn, parent->pm_gc, mask, values); - int text_offset_y = config.font.height + (con->deco_rect.height - config.font.height) / 2 - 1; + int text_offset_y = (con->deco_rect.height - config.font.height) / 2; struct Window *win = con->window; if (win == NULL || win->name_x == NULL) { /* this is a non-leaf container, we need to make up a good description */ // TODO: use a good description instead of just "another container" - xcb_image_text_8( - conn, - strlen("another container"), - parent->pixmap, - parent->pm_gc, - con->deco_rect.x + 2, - con->deco_rect.y + text_offset_y, - "another container" - ); - + draw_text("another container", strlen("another container"), false, + parent->pixmap, parent->pm_gc, + con->deco_rect.x + 2, con->deco_rect.y + text_offset_y); goto copy_pixmaps; } @@ -447,26 +440,9 @@ void x_draw_decoration(Con *con) { //DLOG("indent_level = %d, indent_mult = %d\n", indent_level, indent_mult); int indent_px = (indent_level * 5) * indent_mult; - if (win->uses_net_wm_name) - xcb_image_text_16( - conn, - win->name_len, - parent->pixmap, - parent->pm_gc, - con->deco_rect.x + 2 + indent_px, - con->deco_rect.y + text_offset_y, - (xcb_char2b_t*)win->name_x - ); - else - xcb_image_text_8( - conn, - win->name_len, - parent->pixmap, - parent->pm_gc, - con->deco_rect.x + 2 + indent_px, - con->deco_rect.y + text_offset_y, - win->name_x - ); + draw_text(win->name_x, win->name_len, win->uses_net_wm_name, + parent->pixmap, parent->pm_gc, + con->deco_rect.x + 2 + indent_px, con->deco_rect.y + text_offset_y); copy_pixmaps: xcb_copy_area(conn, con->pixmap, con->frame, con->pm_gc, 0, 0, 0, 0, con->rect.width, con->rect.height);