diff --git a/swaybar/main.c b/swaybar/main.c index 49aa08cd..05c1fd75 100644 --- a/swaybar/main.c +++ b/swaybar/main.c @@ -75,6 +75,7 @@ char *output, *status_command; struct registry *registry; struct window *window; bool dirty = true; +char *separator_symbol = NULL; typedef enum {UNDEF, TEXT, I3BAR} command_protocol; command_protocol protocol = UNDEF; @@ -289,7 +290,7 @@ void bar_ipc_init(int outputi, const char *bar_id) { json_object *bar_config = json_tokener_parse(res); json_object *tray_output, *mode, *hidden_state, *position, *_status_command; json_object *font, *bar_height, *workspace_buttons, *strip_workspace_numbers; - json_object *binding_mode_indicator, *verbose, *_colors; + json_object *binding_mode_indicator, *verbose, *_colors, *sep_symbol; json_object_object_get_ex(bar_config, "tray_output", &tray_output); json_object_object_get_ex(bar_config, "mode", &mode); json_object_object_get_ex(bar_config, "hidden_state", &hidden_state); @@ -301,6 +302,7 @@ void bar_ipc_init(int outputi, const char *bar_id) { json_object_object_get_ex(bar_config, "strip_workspace_numbers", &strip_workspace_numbers); json_object_object_get_ex(bar_config, "binding_mode_indicator", &binding_mode_indicator); json_object_object_get_ex(bar_config, "verbose", &verbose); + json_object_object_get_ex(bar_config, "separator_symbol", &sep_symbol); json_object_object_get_ex(bar_config, "colors", &_colors); // TODO: More of these options @@ -317,6 +319,10 @@ void bar_ipc_init(int outputi, const char *bar_id) { window->font = parse_font(json_object_get_string(font)); } + if (sep_symbol) { + separator_symbol = strdup(json_object_get_string(sep_symbol)); + } + if (bar_height) { int width, height; get_text_size(window, &width, &height, "Test string for measuring purposes"); @@ -438,7 +444,7 @@ void render_sharp_line(cairo_t *cairo, uint32_t color, double x, double y, doubl } void render_block(struct status_block *block, double *x, bool edge) { - int width, height; + int width, height, sep_width; get_text_size(window, &width, &height, "%s", block->full_text); int textwidth = width; @@ -462,6 +468,13 @@ void render_block(struct status_block *block, double *x, bool edge) { // Add separator if (!edge) { + if (separator_symbol) { + get_text_size(window, &sep_width, &height, "%s", separator_symbol); + if (sep_width > block->separator_block_width) { + block->separator_block_width = sep_width + margin * 2; + } + } + *x -= block->separator_block_width; } else { *x -= margin; @@ -535,14 +548,23 @@ void render_block(struct status_block *block, double *x, bool edge) { pos += block->border_right; } + sway_log(L_DEBUG, "%s", separator_symbol); + // render separator - // TODO: Handle custom separator if (!edge && block->separator) { cairo_set_source_u32(window->cairo, colors.separator); - cairo_set_line_width(window->cairo, 1); - cairo_move_to(window->cairo, pos + block->separator_block_width/2, margin); - cairo_line_to(window->cairo, pos + block->separator_block_width/2, window->height - margin); - cairo_stroke(window->cairo); + if (separator_symbol) { + offset = pos + (block->separator_block_width - sep_width) / 2; + cairo_move_to(window->cairo, offset, margin); + pango_printf(window, "%s", separator_symbol); + } else { + cairo_set_line_width(window->cairo, 1); + cairo_move_to(window->cairo, pos + block->separator_block_width/2, + margin); + cairo_line_to(window->cairo, pos + block->separator_block_width/2, + window->height - margin); + cairo_stroke(window->cairo); + } } }