diff options
Diffstat (limited to 'swaybar/main.c')
-rw-r--r-- | swaybar/main.c | 36 |
1 files changed, 29 insertions, 7 deletions
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; | |||
75 | struct registry *registry; | 75 | struct registry *registry; |
76 | struct window *window; | 76 | struct window *window; |
77 | bool dirty = true; | 77 | bool dirty = true; |
78 | char *separator_symbol = NULL; | ||
78 | typedef enum {UNDEF, TEXT, I3BAR} command_protocol; | 79 | typedef enum {UNDEF, TEXT, I3BAR} command_protocol; |
79 | command_protocol protocol = UNDEF; | 80 | command_protocol protocol = UNDEF; |
80 | 81 | ||
@@ -289,7 +290,7 @@ void bar_ipc_init(int outputi, const char *bar_id) { | |||
289 | json_object *bar_config = json_tokener_parse(res); | 290 | json_object *bar_config = json_tokener_parse(res); |
290 | json_object *tray_output, *mode, *hidden_state, *position, *_status_command; | 291 | json_object *tray_output, *mode, *hidden_state, *position, *_status_command; |
291 | json_object *font, *bar_height, *workspace_buttons, *strip_workspace_numbers; | 292 | json_object *font, *bar_height, *workspace_buttons, *strip_workspace_numbers; |
292 | json_object *binding_mode_indicator, *verbose, *_colors; | 293 | json_object *binding_mode_indicator, *verbose, *_colors, *sep_symbol; |
293 | json_object_object_get_ex(bar_config, "tray_output", &tray_output); | 294 | json_object_object_get_ex(bar_config, "tray_output", &tray_output); |
294 | json_object_object_get_ex(bar_config, "mode", &mode); | 295 | json_object_object_get_ex(bar_config, "mode", &mode); |
295 | json_object_object_get_ex(bar_config, "hidden_state", &hidden_state); | 296 | 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) { | |||
301 | json_object_object_get_ex(bar_config, "strip_workspace_numbers", &strip_workspace_numbers); | 302 | json_object_object_get_ex(bar_config, "strip_workspace_numbers", &strip_workspace_numbers); |
302 | json_object_object_get_ex(bar_config, "binding_mode_indicator", &binding_mode_indicator); | 303 | json_object_object_get_ex(bar_config, "binding_mode_indicator", &binding_mode_indicator); |
303 | json_object_object_get_ex(bar_config, "verbose", &verbose); | 304 | json_object_object_get_ex(bar_config, "verbose", &verbose); |
305 | json_object_object_get_ex(bar_config, "separator_symbol", &sep_symbol); | ||
304 | json_object_object_get_ex(bar_config, "colors", &_colors); | 306 | json_object_object_get_ex(bar_config, "colors", &_colors); |
305 | 307 | ||
306 | // TODO: More of these options | 308 | // TODO: More of these options |
@@ -317,6 +319,10 @@ void bar_ipc_init(int outputi, const char *bar_id) { | |||
317 | window->font = parse_font(json_object_get_string(font)); | 319 | window->font = parse_font(json_object_get_string(font)); |
318 | } | 320 | } |
319 | 321 | ||
322 | if (sep_symbol) { | ||
323 | separator_symbol = strdup(json_object_get_string(sep_symbol)); | ||
324 | } | ||
325 | |||
320 | if (bar_height) { | 326 | if (bar_height) { |
321 | int width, height; | 327 | int width, height; |
322 | get_text_size(window, &width, &height, "Test string for measuring purposes"); | 328 | 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 | |||
438 | } | 444 | } |
439 | 445 | ||
440 | void render_block(struct status_block *block, double *x, bool edge) { | 446 | void render_block(struct status_block *block, double *x, bool edge) { |
441 | int width, height; | 447 | int width, height, sep_width; |
442 | get_text_size(window, &width, &height, "%s", block->full_text); | 448 | get_text_size(window, &width, &height, "%s", block->full_text); |
443 | 449 | ||
444 | int textwidth = width; | 450 | int textwidth = width; |
@@ -462,6 +468,13 @@ void render_block(struct status_block *block, double *x, bool edge) { | |||
462 | 468 | ||
463 | // Add separator | 469 | // Add separator |
464 | if (!edge) { | 470 | if (!edge) { |
471 | if (separator_symbol) { | ||
472 | get_text_size(window, &sep_width, &height, "%s", separator_symbol); | ||
473 | if (sep_width > block->separator_block_width) { | ||
474 | block->separator_block_width = sep_width + margin * 2; | ||
475 | } | ||
476 | } | ||
477 | |||
465 | *x -= block->separator_block_width; | 478 | *x -= block->separator_block_width; |
466 | } else { | 479 | } else { |
467 | *x -= margin; | 480 | *x -= margin; |
@@ -535,14 +548,23 @@ void render_block(struct status_block *block, double *x, bool edge) { | |||
535 | pos += block->border_right; | 548 | pos += block->border_right; |
536 | } | 549 | } |
537 | 550 | ||
551 | sway_log(L_DEBUG, "%s", separator_symbol); | ||
552 | |||
538 | // render separator | 553 | // render separator |
539 | // TODO: Handle custom separator | ||
540 | if (!edge && block->separator) { | 554 | if (!edge && block->separator) { |
541 | cairo_set_source_u32(window->cairo, colors.separator); | 555 | cairo_set_source_u32(window->cairo, colors.separator); |
542 | cairo_set_line_width(window->cairo, 1); | 556 | if (separator_symbol) { |
543 | cairo_move_to(window->cairo, pos + block->separator_block_width/2, margin); | 557 | offset = pos + (block->separator_block_width - sep_width) / 2; |
544 | cairo_line_to(window->cairo, pos + block->separator_block_width/2, window->height - margin); | 558 | cairo_move_to(window->cairo, offset, margin); |
545 | cairo_stroke(window->cairo); | 559 | pango_printf(window, "%s", separator_symbol); |
560 | } else { | ||
561 | cairo_set_line_width(window->cairo, 1); | ||
562 | cairo_move_to(window->cairo, pos + block->separator_block_width/2, | ||
563 | margin); | ||
564 | cairo_line_to(window->cairo, pos + block->separator_block_width/2, | ||
565 | window->height - margin); | ||
566 | cairo_stroke(window->cairo); | ||
567 | } | ||
546 | } | 568 | } |
547 | 569 | ||
548 | } | 570 | } |