From 3e8f548d1d0acb3aba384842615e6528b3027283 Mon Sep 17 00:00:00 2001 From: Brian Ashworth Date: Thu, 27 Dec 2018 00:46:55 -0500 Subject: Revamp seat configs This makes seat configs work like output and input configs do. This also adds support for wildcard seat configs. A seat config is still created in the main seat command handler, but instead of creating a new one in the subcommands and destroying the main seat command's instance, the seat subcommands modify the main one. The seat config is then stored, where it is merged appropriately. The seat config returned from `store_seat_config` is then applied. When attempting to apply a wildcard seat config, a seat specific config is queried for and if found, that is used. Otherwise, the wildcard config is applied directly. Additionally, instead of adding input devices to the default seat directly when there is no seat configs, a seat config for the default seat is created with only fallback set to true, which is more explicit. It also fixes an issue where running a seat command at runtime (with no seat config in the sway config), would result in all input devices being removed from the default seat and leaving sway in an unusable state. Also, instead of checking for any seat config, the search is for a seat config with a fallback option seat. This makes it so if there are only seat configs with fallback set to -1, the default seat is still created since there is no explicit notion on what to do regarding fallbacks. However, if there is even a single fallback 0, then the default seat is not used as a fallback. This will be needed for seat subcommands like hide_cursor where the user may only want to set that property without effecting anything else. --- sway/config/seat.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 6 deletions(-) (limited to 'sway/config') diff --git a/sway/config/seat.c b/sway/config/seat.c index 1cb4c363..c248990a 100644 --- a/sway/config/seat.c +++ b/sway/config/seat.c @@ -11,7 +11,6 @@ struct seat_config *new_seat_config(const char* name) { return NULL; } - wlr_log(WLR_DEBUG, "new_seat_config(%s)", name); seat->name = strdup(name); if (!sway_assert(seat->name, "could not allocate name for seat")) { free(seat); @@ -30,6 +29,52 @@ struct seat_config *new_seat_config(const char* name) { return seat; } +static void merge_wildcard_on_all(struct seat_config *wildcard) { + for (int i = 0; i < config->seat_configs->length; i++) { + struct seat_config *sc = config->seat_configs->items[i]; + if (strcmp(wildcard->name, sc->name) != 0) { + wlr_log(WLR_DEBUG, "Merging seat * config on %s", sc->name); + merge_seat_config(sc, wildcard); + } + } +} + +struct seat_config *store_seat_config(struct seat_config *sc) { + bool wildcard = strcmp(sc->name, "*") == 0; + if (wildcard) { + merge_wildcard_on_all(sc); + } + + int i = list_seq_find(config->seat_configs, seat_name_cmp, sc->name); + if (i >= 0) { + wlr_log(WLR_DEBUG, "Merging on top of existing seat config"); + struct seat_config *current = config->seat_configs->items[i]; + merge_seat_config(current, sc); + free_seat_config(sc); + sc = current; + } else if (!wildcard) { + wlr_log(WLR_DEBUG, "Adding non-wildcard seat config"); + i = list_seq_find(config->seat_configs, seat_name_cmp, "*"); + if (i >= 0) { + wlr_log(WLR_DEBUG, "Merging on top of seat * config"); + struct seat_config *current = new_seat_config(sc->name); + merge_seat_config(current, config->seat_configs->items[i]); + merge_seat_config(current, sc); + free_seat_config(sc); + sc = current; + } + list_add(config->seat_configs, sc); + } else { + // New wildcard config. Just add it + wlr_log(WLR_DEBUG, "Adding seat * config"); + list_add(config->seat_configs, sc); + } + + wlr_log(WLR_DEBUG, "Config stored for seat %s", sc->name); + + return sc; +} + struct seat_attachment_config *seat_attachment_config_new(void) { struct seat_attachment_config *attachment = calloc(1, sizeof(struct seat_attachment_config)); @@ -65,11 +110,6 @@ static void merge_seat_attachment_config(struct seat_attachment_config *dest, } void merge_seat_config(struct seat_config *dest, struct seat_config *source) { - if (source->name) { - free(dest->name); - dest->name = strdup(source->name); - } - if (source->fallback != -1) { dest->fallback = source->fallback; } -- cgit v1.2.3-54-g00ecf