diff options
author | Ian Fan <ianfan0@gmail.com> | 2018-10-12 20:32:48 +0100 |
---|---|---|
committer | Ian Fan <ianfan0@gmail.com> | 2018-10-14 13:33:12 +0100 |
commit | bcc61e5147fb57a3b4bfb9a2a33065a0cf6da67b (patch) | |
tree | 873a09eca473242c15299ea1053966e9d163f6c6 /swaybar/ipc.c | |
parent | swaybar: streamline ipc handling (diff) | |
download | sway-bcc61e5147fb57a3b4bfb9a2a33065a0cf6da67b.tar.gz sway-bcc61e5147fb57a3b4bfb9a2a33065a0cf6da67b.tar.zst sway-bcc61e5147fb57a3b4bfb9a2a33065a0cf6da67b.zip |
swaybar: handle mode/hidden_state changes
As well as adding the hidden_state property to the bar config struct,
this commit handles barconfig_update events when the mode or
hidden_state changes, and uses a new function determine_bar_visibility
to hide or show the bar as required, using, respectively,
destroy_layer_surface, which is also newly added, and add_layer_surface,
which has been changed to allow dynamically adding the surface.
Diffstat (limited to 'swaybar/ipc.c')
-rw-r--r-- | swaybar/ipc.c | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/swaybar/ipc.c b/swaybar/ipc.c index 6013c2de..56379fdb 100644 --- a/swaybar/ipc.c +++ b/swaybar/ipc.c | |||
@@ -152,12 +152,12 @@ static bool ipc_parse_config( | |||
152 | json_object_put(bar_config); | 152 | json_object_put(bar_config); |
153 | return false; | 153 | return false; |
154 | } | 154 | } |
155 | json_object *markup, *mode, *hidden_bar, *position, *status_command; | 155 | json_object *markup, *mode, *hidden_state, *position, *status_command; |
156 | json_object *font, *bar_height, *wrap_scroll, *workspace_buttons, *strip_workspace_numbers; | 156 | json_object *font, *bar_height, *wrap_scroll, *workspace_buttons, *strip_workspace_numbers; |
157 | json_object *binding_mode_indicator, *verbose, *colors, *sep_symbol, *outputs; | 157 | json_object *binding_mode_indicator, *verbose, *colors, *sep_symbol, *outputs; |
158 | json_object *bindings; | 158 | json_object *bindings; |
159 | json_object_object_get_ex(bar_config, "mode", &mode); | 159 | json_object_object_get_ex(bar_config, "mode", &mode); |
160 | json_object_object_get_ex(bar_config, "hidden_bar", &hidden_bar); | 160 | json_object_object_get_ex(bar_config, "hidden_state", &hidden_state); |
161 | json_object_object_get_ex(bar_config, "position", &position); | 161 | json_object_object_get_ex(bar_config, "position", &position); |
162 | json_object_object_get_ex(bar_config, "status_command", &status_command); | 162 | json_object_object_get_ex(bar_config, "status_command", &status_command); |
163 | json_object_object_get_ex(bar_config, "font", &font); | 163 | json_object_object_get_ex(bar_config, "font", &font); |
@@ -220,6 +220,14 @@ static bool ipc_parse_config( | |||
220 | list_add(config->bindings, binding); | 220 | list_add(config->bindings, binding); |
221 | } | 221 | } |
222 | } | 222 | } |
223 | if (hidden_state) { | ||
224 | free(config->hidden_state); | ||
225 | config->hidden_state = strdup(json_object_get_string(hidden_state)); | ||
226 | } | ||
227 | if (mode) { | ||
228 | free(config->mode); | ||
229 | config->mode = strdup(json_object_get_string(mode)); | ||
230 | } | ||
223 | 231 | ||
224 | struct config_output *output, *tmp; | 232 | struct config_output *output, *tmp; |
225 | wl_list_for_each_safe(output, tmp, &config->outputs, link) { | 233 | wl_list_for_each_safe(output, tmp, &config->outputs, link) { |
@@ -367,6 +375,37 @@ bool ipc_initialize(struct swaybar *bar) { | |||
367 | return true; | 375 | return true; |
368 | } | 376 | } |
369 | 377 | ||
378 | static bool handle_barconfig_update(struct swaybar *bar, | ||
379 | json_object *json_config) { | ||
380 | json_object *json_id; | ||
381 | json_object_object_get_ex(json_config, "id", &json_id); | ||
382 | const char *id = json_object_get_string(json_id); | ||
383 | if (strcmp(id, bar->id) != 0) { | ||
384 | return false; | ||
385 | } | ||
386 | |||
387 | struct swaybar_config *config = bar->config; | ||
388 | |||
389 | json_object *json_state; | ||
390 | json_object_object_get_ex(json_config, "hidden_state", &json_state); | ||
391 | const char *new_state = json_object_get_string(json_state); | ||
392 | char *old_state = config->hidden_state; | ||
393 | if (strcmp(new_state, old_state) != 0) { | ||
394 | wlr_log(WLR_DEBUG, "Changing bar hidden state to %s", new_state); | ||
395 | free(old_state); | ||
396 | config->hidden_state = strdup(new_state); | ||
397 | return determine_bar_visibility(bar, false); | ||
398 | } | ||
399 | |||
400 | free(config->mode); | ||
401 | json_object *json_mode; | ||
402 | json_object_object_get_ex(json_config, "mode", &json_mode); | ||
403 | config->mode = strdup(json_object_get_string(json_mode)); | ||
404 | wlr_log(WLR_DEBUG, "Changing bar mode to %s", config->mode); | ||
405 | |||
406 | return determine_bar_visibility(bar, true); | ||
407 | } | ||
408 | |||
370 | bool handle_ipc_readable(struct swaybar *bar) { | 409 | bool handle_ipc_readable(struct swaybar *bar) { |
371 | struct ipc_response *resp = ipc_recv_response(bar->ipc_event_socketfd); | 410 | struct ipc_response *resp = ipc_recv_response(bar->ipc_event_socketfd); |
372 | if (!resp) { | 411 | if (!resp) { |
@@ -402,6 +441,9 @@ bool handle_ipc_readable(struct swaybar *bar) { | |||
402 | } | 441 | } |
403 | break; | 442 | break; |
404 | } | 443 | } |
444 | case IPC_EVENT_BARCONFIG_UPDATE: | ||
445 | bar_is_dirty = handle_barconfig_update(bar, result); | ||
446 | break; | ||
405 | default: | 447 | default: |
406 | bar_is_dirty = false; | 448 | bar_is_dirty = false; |
407 | break; | 449 | break; |