Some little fixes for bapt’s patch, use predict_text_width, support UTF8, pre-render workspace names

This commit is contained in:
Michael Stapelberg
2009-07-28 13:55:09 +02:00
parent ddcb11baba
commit e6198ad6c8
7 changed files with 115 additions and 46 deletions

View File

@ -434,45 +434,31 @@ static void render_internal_bar(xcb_connection_t *conn, Workspace *r_ws, int wid
struct Colortriple *color = (screen->current_workspace == c ? &(config.bar.focused) :
&(config.bar.unfocused));
Workspace *ws = &workspaces[c];
char *label=NULL;
if ( workspaces[c].name != NULL )
asprintf(&label, "%d: %s",c+1, workspaces[c].name);
else
asprintf(&label, "%d", c+1);
/* Calculate the length of a string in a given font */
int text_width = predict_text_width(conn, config.font, ws->name, ws->name_len);
xcb_query_text_extents_cookie_t extents_cookie;
xcb_query_text_extents_reply_t *extents_reply;
xcb_char2b_t *chars;
int str_width;
int i;
chars = malloc(strlen(label) * sizeof(xcb_char2b_t));
for (i=0; i<strlen(label); i++) {
chars[i].byte1 = '\0';
chars[i].byte2 = label[i];
}
extents_cookie = xcb_query_text_extents_unchecked(conn,
font->id,
strlen(label),
chars);
extents_reply = xcb_query_text_extents_reply(conn,
extents_cookie,
NULL);
free(chars);
str_width = extents_reply->overall_width;
free(extents_reply);
/* Draw the outer rect */
xcb_draw_rect(conn, screen->bar, screen->bargc, color->border,
drawn, 1, str_width + 8, height - 2);
drawn, /* x */
1, /* y */
text_width + 5 + 5, /* width = text width + 5 px left + 5px right */
height - 2 /* height = max. height - 1 px upper and 1 px bottom border */);
/* Draw the background of this rect */
xcb_draw_rect(conn, screen->bar, screen->bargc, color->background,
drawn + 1, 2, str_width + 6, height - 4);
drawn + 1,
2,
text_width + 4 + 4,
height - 4);
xcb_change_gc_single(conn, screen->bargc, XCB_GC_FOREGROUND, color->text);
xcb_change_gc_single(conn, screen->bargc, XCB_GC_BACKGROUND, color->background);
xcb_image_text_8(conn, strlen(label), screen->bar, screen->bargc, drawn + 5 /* X */,
font->height + 1 /* Y = baseline of font */, label);
drawn+=str_width+8;
free(label);
xcb_image_text_16(conn, ws->name_len, screen->bar, screen->bargc, drawn + 5 /* X */,
font->height + 1 /* Y = baseline of font */,
(xcb_char2b_t*)ws->name);
drawn += text_width + 12;
}
LOG("done rendering internal\n");