Implements configurable named workspaces
This commit is contained in:
parent
33e536113d
commit
ddcb11baba
|
@ -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;
|
||||
|
||||
|
|
32
src/config.c
32
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);
|
||||
|
|
42
src/layout.c
42
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));
|
||||
|
||||
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");
|
||||
|
|
Loading…
Reference in New Issue