Separator color via config; separator width and on/off via ipc

This patch adds the following features:
1) Configure a color of the separator via config.  It is done like
   bar {
      colors {
         separator #000000
      }
   }
2) A block can have an integer entry "separator_block_width" which
   sets the width of the gap which would follow after the current block.

3) A block can have a boolean entry "separator" and if it is set
   to false, then the drawing of the separating line would be disabled.
This commit is contained in:
Artem Shinkarov
2013-01-27 20:27:21 +00:00
committed by Michael Stapelberg
parent a52b1b4bb0
commit 5f05ca6b5d
12 changed files with 47 additions and 6 deletions

View File

@ -43,6 +43,10 @@ struct status_block {
blockalign_t align;
bool urgent;
bool no_separator;
/* The amount of pixels necessary to render a separater after the block. */
uint32_t sep_block_width;
/* The amount of pixels necessary to render this block. These variables are
* only temporarily used in refresh_statusline(). */

View File

@ -28,6 +28,7 @@
struct xcb_color_strings_t {
char *bar_fg;
char *bar_bg;
char *sep_fg;
char *active_ws_fg;
char *active_ws_bg;
char *active_ws_border;

View File

@ -98,6 +98,10 @@ static int stdin_start_array(void *context) {
static int stdin_start_map(void *context) {
parser_ctx *ctx = context;
memset(&(ctx->block), '\0', sizeof(struct status_block));
/* Default width of the separator block. */
ctx->block.sep_block_width = 9;
return 1;
}
@ -117,6 +121,9 @@ static int stdin_boolean(void *context, int val) {
if (strcasecmp(ctx->last_map_key, "urgent") == 0) {
ctx->block.urgent = val;
}
if (strcasecmp(ctx->last_map_key, "separator") == 0) {
ctx->block.no_separator = !val;
}
return 1;
}
@ -153,6 +160,9 @@ static int stdin_integer(void *context, long val) {
if (strcasecmp(ctx->last_map_key, "min_width") == 0) {
ctx->block.min_width = (uint32_t)val;
}
if (strcasecmp(ctx->last_map_key, "separator_block_width") == 0) {
ctx->block.sep_block_width = (uint32_t)val;
}
return 1;
}

View File

@ -161,6 +161,7 @@ static int config_string_cb(void *params_, const unsigned char *val, unsigned in
COLOR(statusline, bar_fg);
COLOR(background, bar_bg);
COLOR(separator, sep_fg);
COLOR(focused_workspace_border, focus_ws_border);
COLOR(focused_workspace_bg, focus_ws_bg);
COLOR(focused_workspace_text, focus_ws_fg);
@ -260,6 +261,7 @@ void free_colors(struct xcb_color_strings_t *colors) {
} while (0)
FREE_COLOR(bar_fg);
FREE_COLOR(bar_bg);
FREE_COLOR(sep_fg);
FREE_COLOR(active_ws_fg);
FREE_COLOR(active_ws_bg);
FREE_COLOR(active_ws_border);

View File

@ -84,6 +84,7 @@ static mode binding;
struct xcb_colors_t {
uint32_t bar_fg;
uint32_t bar_bg;
uint32_t sep_fg;
uint32_t active_ws_fg;
uint32_t active_ws_bg;
uint32_t active_ws_border;
@ -149,7 +150,8 @@ void refresh_statusline(void) {
/* If this is not the last block, add some pixels for a separator. */
if (TAILQ_NEXT(block, blocks) != NULL)
block->width += 9;
block->width += block->sep_block_width;
statusline_width += block->width + block->x_offset + block->x_append;
}
@ -174,12 +176,14 @@ void refresh_statusline(void) {
draw_text(block->full_text, statusline_pm, statusline_ctx, x + block->x_offset, 1, block->width);
x += block->width + block->x_offset + block->x_append;
if (TAILQ_NEXT(block, blocks) != NULL) {
if (TAILQ_NEXT(block, blocks) != NULL && !block->no_separator && block->sep_block_width > 0) {
/* This is not the last block, draw a separator. */
set_font_colors(statusline_ctx, get_colorpixel("#666666"), colors.bar_bg);
uint32_t sep_offset = block->sep_block_width/2 + block->sep_block_width % 2;
set_font_colors(statusline_ctx, colors.sep_fg, colors.bar_bg);
xcb_poly_line(xcb_connection, XCB_COORD_MODE_ORIGIN, statusline_pm,
statusline_ctx, 2,
(xcb_point_t[]){ { x - 5, 2 }, { x - 5, font.height - 2 } });
(xcb_point_t[]){ { x - sep_offset, 2 },
{ x - sep_offset, font.height - 2 } });
}
}
}
@ -259,6 +263,7 @@ void init_colors(const struct xcb_color_strings_t *new_colors) {
} while (0)
PARSE_COLOR(bar_fg, "#FFFFFF");
PARSE_COLOR(bar_bg, "#000000");
PARSE_COLOR(sep_fg, "#666666");
PARSE_COLOR(active_ws_fg, "#FFFFFF");
PARSE_COLOR(active_ws_bg, "#333333");
PARSE_COLOR(active_ws_border, "#333333");