summaryrefslogtreecommitdiffstats
path: root/swaybar
diff options
context:
space:
mode:
authorLibravatar crondog <crondog@gmail.com>2015-12-22 22:49:41 +1100
committerLibravatar crondog <crondog@gmail.com>2015-12-22 22:49:41 +1100
commit70b24fbb1f2ac5e82bf18b68a1b477fc2bf818e5 (patch)
tree54bb4472741a45d3cadc08e32716771fdfc1eff0 /swaybar
parentMake start on i3bar json parsing (diff)
downloadsway-70b24fbb1f2ac5e82bf18b68a1b477fc2bf818e5.tar.gz
sway-70b24fbb1f2ac5e82bf18b68a1b477fc2bf818e5.tar.zst
sway-70b24fbb1f2ac5e82bf18b68a1b477fc2bf818e5.zip
Clean up a bit
Diffstat (limited to 'swaybar')
-rw-r--r--swaybar/main.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/swaybar/main.c b/swaybar/main.c
index c568f6e9..8e92b18f 100644
--- a/swaybar/main.c
+++ b/swaybar/main.c
@@ -444,13 +444,13 @@ void parse_json(const char *text) {
444 * 444 *
445 * */ 445 * */
446 446
447 json_object *result = json_tokener_parse(text); 447 json_object *results = json_tokener_parse(text);
448 if (!result) { 448 if (!results) {
449 sway_log(L_DEBUG, "xxx Failed to parse json"); 449 sway_log(L_DEBUG, "xxx Failed to parse json");
450 return; 450 return;
451 } 451 }
452 452
453 if (json_object_array_length(result) < 1) { 453 if (json_object_array_length(results) < 1) {
454 return; 454 return;
455 } 455 }
456 456
@@ -459,14 +459,14 @@ void parse_json(const char *text) {
459 } 459 }
460 460
461 status_line = create_list(); 461 status_line = create_list();
462
463 462
464 int i; 463 int i;
465 for (i = 0; i < json_object_array_length(result); ++i) { 464 for (i = 0; i < json_object_array_length(results); ++i) {
466 json_object *full_text, *short_text, *color, *min_width, *align, *urgent; 465 json_object *full_text, *short_text, *color, *min_width, *align, *urgent;
467 json_object *name, *instance, *separator, *separator_block_width; 466 json_object *name, *instance, *separator, *separator_block_width;
468 467
469 json_object *json = json_object_array_get_idx(result, i); 468 json_object *json = json_object_array_get_idx(results, i);
469
470 if (!json) { 470 if (!json) {
471 continue; 471 continue;
472 } 472 }
@@ -503,34 +503,45 @@ void parse_json(const char *text) {
503 if (min_width) { 503 if (min_width) {
504 new->min_width = json_object_get_int(min_width); 504 new->min_width = json_object_get_int(min_width);
505 } 505 }
506
506 if (align) { 507 if (align) {
507 new->align = strdup(json_object_get_string(align)); 508 new->align = strdup(json_object_get_string(align));
508 } 509 }
510 else {
511 new->align = strdup("left");
512 }
513
509 if (urgent) { 514 if (urgent) {
510 new->urgent = json_object_get_int(urgent); 515 new->urgent = json_object_get_int(urgent);
511 } 516 }
517
512 if (name) { 518 if (name) {
513 new->name = strdup(json_object_get_string(name)); 519 new->name = strdup(json_object_get_string(name));
514 } 520 }
521
515 if (instance) { 522 if (instance) {
516 new->instance = strdup(json_object_get_string(instance)); 523 new->instance = strdup(json_object_get_string(instance));
517 } 524 }
525
518 if (separator) { 526 if (separator) {
519 new->separator = json_object_get_int(separator); 527 new->separator = json_object_get_int(separator);
520 } 528 }
521 else { 529 else {
522 new->separator = true; // i3bar spec 530 new->separator = true; // i3bar spec
523 } 531 }
532
524 if (separator_block_width) { 533 if (separator_block_width) {
525 new->separator_block_width = json_object_get_int(separator_block_width); 534 new->separator_block_width = json_object_get_int(separator_block_width);
526 } 535 }
527 else { 536 else {
528 new->separator_block_width = 9; // i3bar spec 537 new->separator_block_width = 9; // i3bar spec
529 } 538 }
539
530 list_add(status_line, new); 540 list_add(status_line, new);
531 541
532 } 542 }
533 543
544 json_object_put(results);
534 545
535} 546}
536 547