#include "util.h"
#include "config.h"
#include "xcb.h"
+#include "table.h"
Config config;
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);
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"));
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");