diff options
author | 2016-02-27 16:18:50 -0500 | |
---|---|---|
committer | 2016-02-27 16:18:50 -0500 | |
commit | 3453910c3e887be900c69394b738e34d9d8ba095 (patch) | |
tree | 28e0d8d72557ac57a2f9aed5c94818c8ba20e97f /sway | |
parent | Set pointer pos before focusing view under it (diff) | |
parent | Free config before exiting sway. (diff) | |
download | sway-3453910c3e887be900c69394b738e34d9d8ba095.tar.gz sway-3453910c3e887be900c69394b738e34d9d8ba095.tar.zst sway-3453910c3e887be900c69394b738e34d9d8ba095.zip |
Merge pull request #492 from mikkeloscar/swaybar-multi-output
Display single swaybar on multiple outputs
Diffstat (limited to 'sway')
-rw-r--r-- | sway/commands.c | 9 | ||||
-rw-r--r-- | sway/config.c | 89 | ||||
-rw-r--r-- | sway/container.c | 5 | ||||
-rw-r--r-- | sway/ipc-server.c | 11 | ||||
-rw-r--r-- | sway/main.c | 4 |
5 files changed, 59 insertions, 59 deletions
diff --git a/sway/commands.c b/sway/commands.c index c4b7f6ab..3b8556ca 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -1526,14 +1526,7 @@ static struct cmd_results *cmd_reload(int argc, char **argv) { | |||
1526 | } | 1526 | } |
1527 | if (!load_config(NULL)) return cmd_results_new(CMD_FAILURE, "reload", "Error(s) reloading config."); | 1527 | if (!load_config(NULL)) return cmd_results_new(CMD_FAILURE, "reload", "Error(s) reloading config."); |
1528 | 1528 | ||
1529 | int i; | 1529 | load_swaybars(); |
1530 | swayc_t *cont = NULL; | ||
1531 | for (i = 0; i < root_container.children->length; ++i) { | ||
1532 | cont = root_container.children->items[i]; | ||
1533 | if (cont->type == C_OUTPUT) { | ||
1534 | load_swaybars(cont, i); | ||
1535 | } | ||
1536 | } | ||
1537 | 1530 | ||
1538 | arrange_windows(&root_container, -1, -1); | 1531 | arrange_windows(&root_container, -1, -1); |
1539 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 1532 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
diff --git a/sway/config.c b/sway/config.c index 65dba365..296e164c 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -23,6 +23,8 @@ | |||
23 | 23 | ||
24 | struct sway_config *config = NULL; | 24 | struct sway_config *config = NULL; |
25 | 25 | ||
26 | static void terminate_swaybar(pid_t pid); | ||
27 | |||
26 | static void free_variable(struct sway_variable *var) { | 28 | static void free_variable(struct sway_variable *var) { |
27 | free(var->name); | 29 | free(var->name); |
28 | free(var->value); | 30 | free(var->value); |
@@ -60,6 +62,11 @@ static void free_bar(struct bar_config *bar) { | |||
60 | if (bar->outputs) { | 62 | if (bar->outputs) { |
61 | free_flat_list(bar->outputs); | 63 | free_flat_list(bar->outputs); |
62 | } | 64 | } |
65 | |||
66 | if (bar->pid != 0) { | ||
67 | terminate_swaybar(bar->pid); | ||
68 | } | ||
69 | |||
63 | free(bar); | 70 | free(bar); |
64 | } | 71 | } |
65 | 72 | ||
@@ -79,7 +86,7 @@ static void free_workspace_output(struct workspace_output *wo) { | |||
79 | free(wo); | 86 | free(wo); |
80 | } | 87 | } |
81 | 88 | ||
82 | static void free_config(struct sway_config *config) { | 89 | void free_config(struct sway_config *config) { |
83 | int i; | 90 | int i; |
84 | for (i = 0; i < config->symbols->length; ++i) { | 91 | for (i = 0; i < config->symbols->length; ++i) { |
85 | free_variable(config->symbols->items[i]); | 92 | free_variable(config->symbols->items[i]); |
@@ -471,32 +478,23 @@ void merge_output_config(struct output_config *dst, struct output_config *src) { | |||
471 | } | 478 | } |
472 | } | 479 | } |
473 | 480 | ||
474 | static void invoke_swaybar(swayc_t *output, struct bar_config *bar, int output_i) { | 481 | static void invoke_swaybar(struct bar_config *bar) { |
475 | sway_log(L_DEBUG, "Invoking swaybar for output %s[%d] and bar %s", output->name, output_i, bar->id); | 482 | bar->pid = fork(); |
476 | 483 | if (bar->pid == 0) { | |
477 | size_t bufsize = 4; | ||
478 | char output_id[bufsize]; | ||
479 | snprintf(output_id, bufsize, "%d", output_i); | ||
480 | output_id[bufsize-1] = 0; | ||
481 | |||
482 | pid_t *pid = malloc(sizeof(pid_t)); | ||
483 | *pid = fork(); | ||
484 | if (*pid == 0) { | ||
485 | if (!bar->swaybar_command) { | 484 | if (!bar->swaybar_command) { |
486 | char *const cmd[] = { | 485 | char *const cmd[] = { |
487 | "swaybar", | 486 | "swaybar", |
488 | "-b", | 487 | "-b", |
489 | bar->id, | 488 | bar->id, |
490 | output_id, | ||
491 | NULL, | 489 | NULL, |
492 | }; | 490 | }; |
493 | 491 | ||
494 | execvp(cmd[0], cmd); | 492 | execvp(cmd[0], cmd); |
495 | } else { | 493 | } else { |
496 | // run custom swaybar | 494 | // run custom swaybar |
497 | int len = strlen(bar->swaybar_command) + strlen(bar->id) + strlen(output_id) + 6; | 495 | int len = strlen(bar->swaybar_command) + strlen(bar->id) + 5; |
498 | char *command = malloc(len * sizeof(char)); | 496 | char *command = malloc(len * sizeof(char)); |
499 | snprintf(command, len, "%s -b %s %s", bar->swaybar_command, bar->id, output_id); | 497 | snprintf(command, len, "%s -b %s", bar->swaybar_command, bar->id); |
500 | 498 | ||
501 | char *const cmd[] = { | 499 | char *const cmd[] = { |
502 | "sh", | 500 | "sh", |
@@ -509,30 +507,15 @@ static void invoke_swaybar(swayc_t *output, struct bar_config *bar, int output_i | |||
509 | free(command); | 507 | free(command); |
510 | } | 508 | } |
511 | } | 509 | } |
512 | |||
513 | // add swaybar pid to output | ||
514 | list_add(output->bar_pids, pid); | ||
515 | } | 510 | } |
516 | 511 | ||
517 | void terminate_swaybars(list_t *pids) { | 512 | static void terminate_swaybar(pid_t pid) { |
518 | int i, ret; | 513 | int ret = kill(pid, SIGTERM); |
519 | pid_t *pid; | 514 | if (ret != 0) { |
520 | for (i = 0; i < pids->length; ++i) { | 515 | sway_log(L_ERROR, "Unable to terminate swaybar [pid: %d]", pid); |
521 | pid = pids->items[i]; | 516 | } else { |
522 | ret = kill(*pid, SIGTERM); | 517 | int status; |
523 | if (ret != 0) { | 518 | waitpid(pid, &status, 0); |
524 | sway_log(L_ERROR, "Unable to terminate swaybar [pid: %d]", *pid); | ||
525 | } else { | ||
526 | int status; | ||
527 | waitpid(*pid, &status, 0); | ||
528 | } | ||
529 | } | ||
530 | |||
531 | // empty pids list | ||
532 | for (i = 0; i < pids->length; ++i) { | ||
533 | pid = pids->items[i]; | ||
534 | list_del(pids, i); | ||
535 | free(pid); | ||
536 | } | 519 | } |
537 | } | 520 | } |
538 | 521 | ||
@@ -546,7 +529,20 @@ void terminate_swaybg(pid_t pid) { | |||
546 | } | 529 | } |
547 | } | 530 | } |
548 | 531 | ||
549 | void load_swaybars(swayc_t *output, int output_idx) { | 532 | static bool active_output(const char *name) { |
533 | int i; | ||
534 | swayc_t *cont = NULL; | ||
535 | for (i = 0; i < root_container.children->length; ++i) { | ||
536 | cont = root_container.children->items[i]; | ||
537 | if (cont->type == C_OUTPUT && strcasecmp(name, cont->name) == 0) { | ||
538 | return true; | ||
539 | } | ||
540 | } | ||
541 | |||
542 | return false; | ||
543 | } | ||
544 | |||
545 | void load_swaybars() { | ||
550 | // Check for bars | 546 | // Check for bars |
551 | list_t *bars = create_list(); | 547 | list_t *bars = create_list(); |
552 | struct bar_config *bar = NULL; | 548 | struct bar_config *bar = NULL; |
@@ -558,7 +554,7 @@ void load_swaybars(swayc_t *output, int output_idx) { | |||
558 | int j; | 554 | int j; |
559 | for (j = 0; j < bar->outputs->length; ++j) { | 555 | for (j = 0; j < bar->outputs->length; ++j) { |
560 | char *o = bar->outputs->items[j]; | 556 | char *o = bar->outputs->items[j]; |
561 | if (!strcmp(o, "*") || !strcasecmp(o, output->name)) { | 557 | if (!strcmp(o, "*") || active_output(o)) { |
562 | apply = true; | 558 | apply = true; |
563 | break; | 559 | break; |
564 | } | 560 | } |
@@ -571,13 +567,13 @@ void load_swaybars(swayc_t *output, int output_idx) { | |||
571 | } | 567 | } |
572 | } | 568 | } |
573 | 569 | ||
574 | // terminate swaybar processes previously spawned for this | ||
575 | // output. | ||
576 | terminate_swaybars(output->bar_pids); | ||
577 | |||
578 | for (i = 0; i < bars->length; ++i) { | 570 | for (i = 0; i < bars->length; ++i) { |
579 | bar = bars->items[i]; | 571 | bar = bars->items[i]; |
580 | invoke_swaybar(output, bar, output_idx); | 572 | if (bar->pid != 0) { |
573 | terminate_swaybar(bar->pid); | ||
574 | } | ||
575 | sway_log(L_DEBUG, "Invoking swaybar for bar id '%s'", bar->id); | ||
576 | invoke_swaybar(bar); | ||
581 | } | 577 | } |
582 | 578 | ||
583 | list_free(bars); | 579 | list_free(bars); |
@@ -700,8 +696,8 @@ void apply_output_config(struct output_config *oc, swayc_t *output) { | |||
700 | } | 696 | } |
701 | } | 697 | } |
702 | 698 | ||
703 | // load swaybars for output | 699 | // reload swaybars |
704 | load_swaybars(output, output_i); | 700 | load_swaybars(); |
705 | } | 701 | } |
706 | 702 | ||
707 | char *do_var_replacement(char *str) { | 703 | char *do_var_replacement(char *str) { |
@@ -889,6 +885,7 @@ struct bar_config *default_bar_config(void) { | |||
889 | bar->strip_workspace_numbers = false; | 885 | bar->strip_workspace_numbers = false; |
890 | bar->binding_mode_indicator = true; | 886 | bar->binding_mode_indicator = true; |
891 | bar->tray_padding = 2; | 887 | bar->tray_padding = 2; |
888 | bar->pid = 0; | ||
892 | // set default colors | 889 | // set default colors |
893 | strcpy(bar->colors.background, "#000000ff"); | 890 | strcpy(bar->colors.background, "#000000ff"); |
894 | strcpy(bar->colors.statusline, "#ffffffff"); | 891 | strcpy(bar->colors.statusline, "#ffffffff"); |
diff --git a/sway/container.c b/sway/container.c index 746890c9..2db7b218 100644 --- a/sway/container.c +++ b/sway/container.c | |||
@@ -61,10 +61,6 @@ static void free_swayc(swayc_t *cont) { | |||
61 | if (cont->app_id) { | 61 | if (cont->app_id) { |
62 | free(cont->app_id); | 62 | free(cont->app_id); |
63 | } | 63 | } |
64 | if (cont->bar_pids) { | ||
65 | terminate_swaybars(cont->bar_pids); | ||
66 | free_flat_list(cont->bar_pids); | ||
67 | } | ||
68 | if (cont->bg_pid != 0) { | 64 | if (cont->bg_pid != 0) { |
69 | terminate_swaybg(cont->bg_pid); | 65 | terminate_swaybg(cont->bg_pid); |
70 | } | 66 | } |
@@ -123,7 +119,6 @@ swayc_t *new_output(wlc_handle handle) { | |||
123 | output->width = size->w; | 119 | output->width = size->w; |
124 | output->height = size->h; | 120 | output->height = size->h; |
125 | output->unmanaged = create_list(); | 121 | output->unmanaged = create_list(); |
126 | output->bar_pids = create_list(); | ||
127 | output->bg_pid = 0; | 122 | output->bg_pid = 0; |
128 | 123 | ||
129 | apply_output_config(oc, output); | 124 | apply_output_config(oc, output); |
diff --git a/sway/ipc-server.c b/sway/ipc-server.c index a63026c6..9ea034d1 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c | |||
@@ -628,6 +628,17 @@ json_object *ipc_json_describe_bar_config(struct bar_config *bar) { | |||
628 | 628 | ||
629 | json_object_object_add(json, "colors", colors); | 629 | json_object_object_add(json, "colors", colors); |
630 | 630 | ||
631 | // Add outputs if defined | ||
632 | if (bar->outputs && bar->outputs->length > 0) { | ||
633 | json_object *outputs = json_object_new_array(); | ||
634 | int i; | ||
635 | for (i = 0; i < bar->outputs->length; ++i) { | ||
636 | const char *name = bar->outputs->items[i]; | ||
637 | json_object_array_add(outputs, json_object_new_string(name)); | ||
638 | } | ||
639 | json_object_object_add(json, "outputs", outputs); | ||
640 | } | ||
641 | |||
631 | return json; | 642 | return json; |
632 | } | 643 | } |
633 | 644 | ||
diff --git a/sway/main.c b/sway/main.c index 7ea392b6..7c712281 100644 --- a/sway/main.c +++ b/sway/main.c | |||
@@ -228,6 +228,10 @@ int main(int argc, char **argv) { | |||
228 | 228 | ||
229 | ipc_terminate(); | 229 | ipc_terminate(); |
230 | 230 | ||
231 | if (config) { | ||
232 | free_config(config); | ||
233 | } | ||
234 | |||
231 | return exit_value; | 235 | return exit_value; |
232 | } | 236 | } |
233 | 237 | ||