Implements configurable named workspaces

This commit is contained in:
Bapt
2009-07-24 17:30:27 +00:00
committed by Michael Stapelberg
parent 33e536113d
commit ddcb11baba
3 changed files with 69 additions and 8 deletions

View File

@ -418,7 +418,6 @@ static void render_internal_bar(xcb_connection_t *conn, Workspace *r_ws, int wid
i3Font *font = load_font(conn, config.font);
i3Screen *screen = r_ws->screen;
enum { SET_NORMAL = 0, SET_FOCUSED = 1 };
char label[3];
/* Fill the whole bar in black */
xcb_change_gc_single(conn, screen->bargc, XCB_GC_FOREGROUND, get_colorpixel(conn, "#000000"));
@ -436,17 +435,44 @@ 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));
xcb_draw_rect(conn, screen->bar, screen->bargc, color->border,
drawn * height, 1, height - 2, height - 2);
xcb_draw_rect(conn, screen->bar, screen->bargc, color->background,
drawn * height + 1, 2, height - 4, height - 4);
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 */
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);
xcb_draw_rect(conn, screen->bar, screen->bargc, color->border,
drawn, 1, str_width + 8, height - 2);
xcb_draw_rect(conn, screen->bar, screen->bargc, color->background,
drawn + 1, 2, str_width + 6, height - 4);
snprintf(label, sizeof(label), "%d", c+1);
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 * height + 5 /* X */,
xcb_image_text_8(conn, strlen(label), screen->bar, screen->bargc, drawn + 5 /* X */,
font->height + 1 /* Y = baseline of font */, label);
drawn++;
drawn+=str_width+8;
free(label);
}
LOG("done rendering internal\n");