diff options
author | Mikkel Oscar Lyderik <mikkeloscar@gmail.com> | 2016-01-05 23:18:59 +0100 |
---|---|---|
committer | Mikkel Oscar Lyderik <mikkeloscar@gmail.com> | 2016-01-05 23:18:59 +0100 |
commit | 843e2ad2c140288733110691f7dc8252fbe4dc16 (patch) | |
tree | 3244491ed6cc45666e0599f8cbb3099864f627eb /sway/config.c | |
parent | a8402035e910efc0ee702bb75a1ea5bfed1287bb (diff) |
Only send modifier event once for active modifiers
This makes sure that a modifier event is only sent for active bar
modifiers, and that it is only sent once for each of those modifiers.
An active bar modifier is a modifier defined for a bar with `mode hide`
and `hidden_state hide`.
Diffstat (limited to 'sway/config.c')
-rw-r--r-- | sway/config.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/sway/config.c b/sway/config.c index 87b1342d..95d8f339 100644 --- a/sway/config.c +++ b/sway/config.c @@ -103,6 +103,8 @@ static void free_config(struct sway_config *config) { free_output_config(config->output_configs->items[i]); } list_free(config->output_configs); + + list_free(config->active_bar_modifiers); free(config); } @@ -145,6 +147,33 @@ static void config_defaults(struct sway_config *config) { config->edge_gaps = true; config->gaps_inner = 0; config->gaps_outer = 0; + + config->active_bar_modifiers = create_list(); +} + +static int compare_modifiers(const void *left, const void *right) { + uint32_t a = *(uint32_t *)left; + uint32_t b = *(uint32_t *)right; + + return a - b; +} + +void update_active_bar_modifiers() { + if (config->active_bar_modifiers->length > 0) { + list_free(config->active_bar_modifiers); + config->active_bar_modifiers = create_list(); + } + + struct bar_config *bar; + int i; + for (i = 0; i < config->bars->length; ++i) { + bar = config->bars->items[i]; + if (strcmp(bar->mode, "hide") == 0 && strcmp(bar->hidden_state, "hide") == 0) { + if (list_seq_find(config->active_bar_modifiers, compare_modifiers, &bar->modifier) < 0) { + list_add(config->active_bar_modifiers, &bar->modifier); + } + } + } } static char *get_config_path(void) { @@ -215,6 +244,8 @@ bool load_config(const char *file) { } fclose(f); + update_active_bar_modifiers(); + return config_load_success; } |