diff options
Diffstat (limited to 'swaybar/main.c')
-rw-r--r-- | swaybar/main.c | 48 |
1 files changed, 30 insertions, 18 deletions
diff --git a/swaybar/main.c b/swaybar/main.c index 86ccfbb9..9f735f36 100644 --- a/swaybar/main.c +++ b/swaybar/main.c | |||
@@ -416,9 +416,29 @@ void render() { | |||
416 | struct status_block *block = status_line->items[i]; | 416 | struct status_block *block = status_line->items[i]; |
417 | if (block->full_text && block->full_text[0]) { | 417 | if (block->full_text && block->full_text[0]) { |
418 | get_text_size(window, &width, &height, "%s", block->full_text); | 418 | get_text_size(window, &width, &height, "%s", block->full_text); |
419 | |||
420 | int textwidth = width; | ||
421 | |||
422 | if (width < block->min_width) { | ||
423 | width = block->min_width; | ||
424 | } | ||
425 | |||
419 | moved += width + block->separator_block_width; | 426 | moved += width + block->separator_block_width; |
420 | blockpos = window->width - margin - moved; | 427 | blockpos = window->width - margin - moved; |
421 | cairo_move_to(window->cairo, blockpos, margin); | 428 | |
429 | int offset = 0; | ||
430 | |||
431 | if (strncmp(block->align, "left", 5) == 0) { | ||
432 | offset = blockpos; | ||
433 | } | ||
434 | else if (strncmp(block->align, "right", 5) == 0) { | ||
435 | offset = blockpos + width - textwidth; | ||
436 | } | ||
437 | else if (strncmp(block->align, "center", 6) == 0) { | ||
438 | offset = blockpos + (width - textwidth) / 2; | ||
439 | } | ||
440 | |||
441 | cairo_move_to(window->cairo, offset, margin); | ||
422 | cairo_set_source_u32(window->cairo, block->color); | 442 | cairo_set_source_u32(window->cairo, block->color); |
423 | pango_printf(window, "%s", block->full_text); | 443 | pango_printf(window, "%s", block->full_text); |
424 | if (corner) { | 444 | if (corner) { |
@@ -494,22 +514,6 @@ void free_status_block(void *item) { | |||
494 | } | 514 | } |
495 | 515 | ||
496 | void parse_json(const char *text) { | 516 | void parse_json(const char *text) { |
497 | /* the array of objects looks like this: | ||
498 | * [ { | ||
499 | * "full_text": "E: 10.0.0.1 (1000 Mbit/s)", | ||
500 | * "short_text": "10.0.0.1", | ||
501 | * "color": "#00ff00", | ||
502 | * "min_width": 300, | ||
503 | * "align": "right", | ||
504 | * "urgent": false, | ||
505 | * "name": "ethernet", | ||
506 | * "instance": "eth0", | ||
507 | * "separator": true, | ||
508 | * "separator_block_width": 9 | ||
509 | * }, | ||
510 | * { ... }, ... | ||
511 | * ] | ||
512 | */ | ||
513 | json_object *results = json_tokener_parse(text); | 517 | json_object *results = json_tokener_parse(text); |
514 | if (!results) { | 518 | if (!results) { |
515 | sway_log(L_DEBUG, "xxx Failed to parse json"); | 519 | sway_log(L_DEBUG, "xxx Failed to parse json"); |
@@ -567,7 +571,15 @@ void parse_json(const char *text) { | |||
567 | } | 571 | } |
568 | 572 | ||
569 | if (min_width) { | 573 | if (min_width) { |
570 | new->min_width = json_object_get_int(min_width); | 574 | json_type type = json_object_get_type(min_width); |
575 | if (type == json_type_int) { | ||
576 | new->min_width = json_object_get_int(min_width); | ||
577 | } | ||
578 | else if (type == json_type_string) { | ||
579 | int width, height; | ||
580 | get_text_size(window, &width, &height, "%s", json_object_get_string(min_width)); | ||
581 | new->min_width = width; | ||
582 | } | ||
571 | } | 583 | } |
572 | 584 | ||
573 | if (align) { | 585 | if (align) { |