]> git.sur5r.net Git - i3/i3/commitdiff
Implements configurable named workspaces
authorBapt <baptiste.daroussin@gmail.com>
Fri, 24 Jul 2009 17:30:27 +0000 (17:30 +0000)
committerMichael Stapelberg <michael@stapelberg.de>
Tue, 28 Jul 2009 11:08:03 +0000 (13:08 +0200)
include/data.h
src/config.c
src/layout.c

index 3ed8d65bee97f3ec36963bbecd5d58091bab5e60..eb4c2fd649c1209ab3b62364a00c5dbaeb967515 100644 (file)
@@ -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;
 
index ee188537845cb81054628ec8072e63210ca2c1ae..49c10b10c86c1a426e845316254e12c9595e71ec 100644 (file)
@@ -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);
index ce1541ab62e977691996888b68ecf99ea3e5c561..7bc22f1bffe63d8855ac0f826e388162d6802288 100644 (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));
 
+                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 * 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");