aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/bar
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2019-09-02 21:41:11 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2019-09-04 16:48:50 -1000
commit1fd2c6ba498e61f4fe823bf552f9d2fce8612de4 (patch)
tree8e2d9adab3451f1f05c76340d466a442c840e558 /sway/commands/bar
parentseatop_default: only focus container on press (diff)
downloadsway-1fd2c6ba498e61f4fe823bf552f9d2fce8612de4.tar.gz
sway-1fd2c6ba498e61f4fe823bf552f9d2fce8612de4.tar.zst
sway-1fd2c6ba498e61f4fe823bf552f9d2fce8612de4.zip
swaybar: complete barconfig_update event handling
This adds complete support for the barconfig_update ipc event. This also changes the bar command and subcommand handlers to correctly emit the event. This makes it so all bar subcommands other than id and swaybar_command are dynamically changeable at runtime. sway-bar.5 has been updated accordingly
Diffstat (limited to 'sway/commands/bar')
-rw-r--r--sway/commands/bar/hidden_state.c8
-rw-r--r--sway/commands/bar/mode.c8
-rw-r--r--sway/commands/bar/output.c15
-rw-r--r--sway/commands/bar/status_command.c5
-rw-r--r--sway/commands/bar/tray_output.c12
5 files changed, 35 insertions, 13 deletions
diff --git a/sway/commands/bar/hidden_state.c b/sway/commands/bar/hidden_state.c
index b2c2d245..1f08a5d2 100644
--- a/sway/commands/bar/hidden_state.c
+++ b/sway/commands/bar/hidden_state.c
@@ -23,7 +23,7 @@ static struct cmd_results *bar_set_hidden_state(struct bar_config *bar,
23 return cmd_results_new(CMD_INVALID, "Invalid value %s", hidden_state); 23 return cmd_results_new(CMD_INVALID, "Invalid value %s", hidden_state);
24 } 24 }
25 if (strcmp(old_state, bar->hidden_state) != 0) { 25 if (strcmp(old_state, bar->hidden_state) != 0) {
26 if (!config->reading) { 26 if (!config->current_bar) {
27 ipc_event_barconfig_update(bar); 27 ipc_event_barconfig_update(bar);
28 } 28 }
29 sway_log(SWAY_DEBUG, "Setting hidden_state: '%s' for bar: %s", 29 sway_log(SWAY_DEBUG, "Setting hidden_state: '%s' for bar: %s",
@@ -47,6 +47,12 @@ struct cmd_results *bar_cmd_hidden_state(int argc, char **argv) {
47 "Unexpected value %s in config mode", argv[1]); 47 "Unexpected value %s in config mode", argv[1]);
48 } 48 }
49 49
50 if (config->current_bar && argc == 2 &&
51 strcmp(config->current_bar->id, argv[1]) != 0) {
52 return cmd_results_new(CMD_INVALID, "Conflicting bar ids: %s and %s",
53 config->current_bar->id, argv[1]);
54 }
55
50 const char *state = argv[0]; 56 const char *state = argv[0];
51 if (config->reading) { 57 if (config->reading) {
52 error = bar_set_hidden_state(config->current_bar, state); 58 error = bar_set_hidden_state(config->current_bar, state);
diff --git a/sway/commands/bar/mode.c b/sway/commands/bar/mode.c
index 1081ad4b..8b3fb275 100644
--- a/sway/commands/bar/mode.c
+++ b/sway/commands/bar/mode.c
@@ -27,7 +27,7 @@ static struct cmd_results *bar_set_mode(struct bar_config *bar, const char *mode
27 } 27 }
28 28
29 if (strcmp(old_mode, bar->mode) != 0) { 29 if (strcmp(old_mode, bar->mode) != 0) {
30 if (!config->reading) { 30 if (!config->current_bar) {
31 ipc_event_barconfig_update(bar); 31 ipc_event_barconfig_update(bar);
32 } 32 }
33 sway_log(SWAY_DEBUG, "Setting mode: '%s' for bar: %s", bar->mode, bar->id); 33 sway_log(SWAY_DEBUG, "Setting mode: '%s' for bar: %s", bar->mode, bar->id);
@@ -51,6 +51,12 @@ struct cmd_results *bar_cmd_mode(int argc, char **argv) {
51 "Unexpected value %s in config mode", argv[1]); 51 "Unexpected value %s in config mode", argv[1]);
52 } 52 }
53 53
54 if (config->current_bar && argc == 2 &&
55 strcmp(config->current_bar->id, argv[1]) != 0) {
56 return cmd_results_new(CMD_INVALID, "Conflicting bar ids: %s and %s",
57 config->current_bar->id, argv[1]);
58 }
59
54 const char *mode = argv[0]; 60 const char *mode = argv[0];
55 if (config->reading) { 61 if (config->reading) {
56 error = bar_set_mode(config->current_bar, mode); 62 error = bar_set_mode(config->current_bar, mode);
diff --git a/sway/commands/bar/output.c b/sway/commands/bar/output.c
index 6a78b30d..cac1d056 100644
--- a/sway/commands/bar/output.c
+++ b/sway/commands/bar/output.c
@@ -21,16 +21,19 @@ struct cmd_results *bar_cmd_output(int argc, char **argv) {
21 bool add_output = true; 21 bool add_output = true;
22 if (strcmp("*", output) == 0) { 22 if (strcmp("*", output) == 0) {
23 // remove all previous defined outputs and replace with '*' 23 // remove all previous defined outputs and replace with '*'
24 for (int i = 0; i < outputs->length; ++i) { 24 while (outputs->length) {
25 free(outputs->items[i]); 25 free(outputs->items[0]);
26 list_del(outputs, i); 26 list_del(outputs, 0);
27 } 27 }
28 } else { 28 } else {
29 // only add output if not already defined with either the same 29 // only add output if not already defined, if the list has '*', remove
30 // name or as '*' 30 // it, in favor of a manual list
31 for (int i = 0; i < outputs->length; ++i) { 31 for (int i = 0; i < outputs->length; ++i) {
32 const char *find = outputs->items[i]; 32 const char *find = outputs->items[i];
33 if (strcmp("*", find) == 0 || strcmp(output, find) == 0) { 33 if (strcmp("*", find) == 0) {
34 free(outputs->items[i]);
35 list_del(outputs, i);
36 } else if (strcmp(output, find) == 0) {
34 add_output = false; 37 add_output = false;
35 break; 38 break;
36 } 39 }
diff --git a/sway/commands/bar/status_command.c b/sway/commands/bar/status_command.c
index 77a73ab6..bb92e8e0 100644
--- a/sway/commands/bar/status_command.c
+++ b/sway/commands/bar/status_command.c
@@ -19,10 +19,5 @@ struct cmd_results *bar_cmd_status_command(int argc, char **argv) {
19 } else { 19 } else {
20 free(new_command); 20 free(new_command);
21 } 21 }
22
23 if (config->active && !config->validating) {
24 load_swaybar(config->current_bar);
25 }
26
27 return cmd_results_new(CMD_SUCCESS, NULL); 22 return cmd_results_new(CMD_SUCCESS, NULL);
28} 23}
diff --git a/sway/commands/bar/tray_output.c b/sway/commands/bar/tray_output.c
index 8bfdf193..eb3b486e 100644
--- a/sway/commands/bar/tray_output.c
+++ b/sway/commands/bar/tray_output.c
@@ -24,9 +24,21 @@ struct cmd_results *bar_cmd_tray_output(int argc, char **argv) {
24 free(outputs->items[i]); 24 free(outputs->items[i]);
25 } 25 }
26 outputs->length = 0; 26 outputs->length = 0;
27 } else if (strcmp(argv[0], "*") == 0) {
28 sway_log(SWAY_DEBUG, "Showing tray on all outputs for bar: %s",
29 config->current_bar->id);
30 while (outputs->length) {
31 free(outputs->items[0]);
32 list_del(outputs, 0);
33 }
34 return cmd_results_new(CMD_SUCCESS, NULL);
27 } else { 35 } else {
28 sway_log(SWAY_DEBUG, "Showing tray on output '%s' for bar: %s", argv[0], 36 sway_log(SWAY_DEBUG, "Showing tray on output '%s' for bar: %s", argv[0],
29 config->current_bar->id); 37 config->current_bar->id);
38 if (outputs->length == 1 && strcmp(outputs->items[0], "none") == 0) {
39 free(outputs->items[0]);
40 list_del(outputs, 0);
41 }
30 } 42 }
31 list_add(outputs, strdup(argv[0])); 43 list_add(outputs, strdup(argv[0]));
32 44