From: Bapt Date: Fri, 24 Jul 2009 17:30:27 +0000 (+0000) Subject: Implements configurable named workspaces X-Git-Tag: 3.c~45 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=ddcb11babae761e9fcaa1b243cba3b27eb6d83e8;p=i3%2Fi3 Implements configurable named workspaces --- diff --git a/include/data.h b/include/data.h index 3ed8d65b..eb4c2fd6 100644 --- a/include/data.h +++ b/include/data.h @@ -165,6 +165,9 @@ struct Workspace { /** Number of this workspace, starting from 0 */ int num; + /** Name of the workspave */ + char *name; + /** x, y, width, height */ Rect rect; diff --git a/src/config.c b/src/config.c index ee188537..49c10b10 100644 --- a/src/config.c +++ b/src/config.c @@ -18,6 +18,7 @@ #include "util.h" #include "config.h" #include "xcb.h" +#include "table.h" Config config; @@ -295,6 +296,37 @@ void load_configuration(xcb_connection_t *conn, const char *override_configpath, continue; } + /* name "workspace number" "name of the workspace" */ + if (strcasecmp(key, "name") == 0) { + LOG("name workspace: %s\n",value); + char *ws_str = sstrdup(value); + char *end = strchr(ws_str, ' '); + if (end == NULL) + die("Malformed name, couln't find terminating space\n"); + *end='\0'; + + /* Strip trailing whitespace */ + while (strlen(value) > 0 && value[strlen(value)-1] == ' ') + value[strlen(value)-1] = '\0'; + + int ws_num=atoi(ws_str); + + if ( ws_num < 1 || ws_num > 10 ) + die("Malformed name, invalid workspace Number\n"); + + /* find the name */ + char *name= value; + name += strlen(ws_str) + 1; + + /* if no name reinitialize the name to NULL for reload */ + if (name == '\0') { + workspaces[ws_num - 1].name=NULL; + continue; + } + workspaces[ws_num - 1].name=sstrdup(name); + continue; + } + /* assign window class[/window title] → workspace */ if (strcasecmp(key, "assign") == 0) { LOG("assign: \"%s\"\n", value); diff --git a/src/layout.c b/src/layout.c index ce1541ab..7bc22f1b 100644 --- a/src/layout.c +++ b/src/layout.c @@ -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)); + 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; iid, + 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 * height, 1, height - 2, height - 2); + drawn, 1, str_width + 8, height - 2); xcb_draw_rect(conn, screen->bar, screen->bargc, color->background, - drawn * height + 1, 2, height - 4, height - 4); + 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");