From 5f05ca6b5d50fdabb72512afc8d2d3c289d2603c Mon Sep 17 00:00:00 2001 From: Artem Shinkarov Date: Sun, 27 Jan 2013 20:27:21 +0000 Subject: [PATCH] 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. --- docs/i3bar-protocol | 8 ++++++++ docs/ipc | 2 ++ docs/userguide | 4 ++++ i3bar/include/common.h | 4 ++++ i3bar/include/xcb.h | 1 + i3bar/src/child.c | 10 ++++++++++ i3bar/src/config.c | 2 ++ i3bar/src/xcb.c | 13 +++++++++---- include/config.h | 1 + parser-specs/config.spec | 2 +- src/config_directives.c | 5 ++++- src/ipc.c | 1 + 12 files changed, 47 insertions(+), 6 deletions(-) diff --git a/docs/i3bar-protocol b/docs/i3bar-protocol index 2cf6dd0a..758628da 100644 --- a/docs/i3bar-protocol +++ b/docs/i3bar-protocol @@ -154,6 +154,14 @@ urgent:: A boolean which specifies whether the current value is urgent. Examples are battery charge values below 1 percent or no more available disk space (for non-root users). The presentation of urgency is up to i3bar. +separator:: + The boolean value false disables drawing of a separating line after the + block. If the field is not present then the separator will be still + drawn. Keep in mind that absence of a separator is only responsible for + the line itself, the gap between the items would be still present. +separator_block_width:: + The integer value that sets the width of the gap between items in pixels. + In the middle of the gap, a separating line is going to be drawn. If you want to put in your own entries into a block, prefix the key with an underscore (_). i3bar will ignore all keys it doesn’t understand, and prefixing diff --git a/docs/ipc b/docs/ipc index c32c59e3..e1a1fc5f 100644 --- a/docs/ipc +++ b/docs/ipc @@ -507,6 +507,8 @@ background:: Background color of the bar. statusline:: Text color to be used for the statusline. +separator:: + Text color to be used for the separator. focused_workspace_text/focused_workspace_bg:: Text color/background color for a workspace button when the workspace has focus. diff --git a/docs/userguide b/docs/userguide index 4bf3cc79..a0f521c2 100644 --- a/docs/userguide +++ b/docs/userguide @@ -1155,6 +1155,8 @@ background:: Background color of the bar. statusline:: Text color to be used for the statusline. +separator:: + Text color to be used for the separator. focused_workspace:: Border, background and text color for a workspace button when the workspace has focus. @@ -1176,6 +1178,7 @@ urgent_workspace:: colors { background statusline + separator colorclass } @@ -1187,6 +1190,7 @@ bar { colors { background #000000 statusline #ffffff + separator #666666 focused_workspace #4c7899 #285577 #ffffff active_workspace #333333 #5f676a #ffffff diff --git a/i3bar/include/common.h b/i3bar/include/common.h index 05fb5aa1..1365082f 100644 --- a/i3bar/include/common.h +++ b/i3bar/include/common.h @@ -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(). */ diff --git a/i3bar/include/xcb.h b/i3bar/include/xcb.h index 69440537..d8d0c090 100644 --- a/i3bar/include/xcb.h +++ b/i3bar/include/xcb.h @@ -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; diff --git a/i3bar/src/child.c b/i3bar/src/child.c index bea1d58e..72e4e745 100644 --- a/i3bar/src/child.c +++ b/i3bar/src/child.c @@ -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; } diff --git a/i3bar/src/config.c b/i3bar/src/config.c index 69355b69..6c7286c4 100644 --- a/i3bar/src/config.c +++ b/i3bar/src/config.c @@ -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); diff --git a/i3bar/src/xcb.c b/i3bar/src/xcb.c index 71331179..d354d596 100644 --- a/i3bar/src/xcb.c +++ b/i3bar/src/xcb.c @@ -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"); diff --git a/include/config.h b/include/config.h index 4a95d43f..7056af85 100644 --- a/include/config.h +++ b/include/config.h @@ -267,6 +267,7 @@ struct Barconfig { struct bar_colors { char *background; char *statusline; + char *separator; char *focused_workspace_border; char *focused_workspace_bg; diff --git a/parser-specs/config.spec b/parser-specs/config.spec index 7538bf38..9a4bf559 100644 --- a/parser-specs/config.spec +++ b/parser-specs/config.spec @@ -419,7 +419,7 @@ state BAR_COLORS: end -> '#' -> BAR_COLORS_IGNORE_LINE 'set' -> BAR_COLORS_IGNORE_LINE - colorclass = 'background', 'statusline' + colorclass = 'background', 'statusline', 'separator' -> BAR_COLORS_SINGLE colorclass = 'focused_workspace', 'active_workspace', 'inactive_workspace', 'urgent_workspace' -> BAR_COLORS_BORDER diff --git a/src/config_directives.c b/src/config_directives.c index 8b636c02..0a83d46f 100644 --- a/src/config_directives.c +++ b/src/config_directives.c @@ -526,7 +526,10 @@ CFGFUN(bar_tray_output, const char *output) { CFGFUN(bar_color_single, const char *colorclass, const char *color) { if (strcmp(colorclass, "background") == 0) current_bar.colors.background = sstrdup(color); - else current_bar.colors.statusline = sstrdup(color); + else if (strcmp(colorclass, "separator") == 0) + current_bar.colors.separator = sstrdup(color); + else + current_bar.colors.statusline = sstrdup(color); } CFGFUN(bar_status_command, const char *command) { diff --git a/src/ipc.c b/src/ipc.c index 2379ba5f..cf253573 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -677,6 +677,7 @@ IPC_HANDLER(get_bar_config) { y(map_open); YSTR_IF_SET(background); YSTR_IF_SET(statusline); + YSTR_IF_SET(separator); YSTR_IF_SET(focused_workspace_border); YSTR_IF_SET(focused_workspace_bg); YSTR_IF_SET(focused_workspace_text); -- 2.39.5