From 639162dad305a3313027854f4579c2e951b4b2c3 Mon Sep 17 00:00:00 2001 From: Kenny Levinsen Date: Thu, 5 Sep 2024 18:19:05 +0200 Subject: [PATCH] config/output: Support storing temporary output configs When an output configuration is stored, it is merged into existing configurations in ways that make the change impractical to undo. In order to let a caller test a configuration with the full handling of precedence, add support for temporarily stored configuration that can be removed after a test. --- include/sway/config.h | 8 ++++++++ sway/config/output.c | 13 +++++++++++++ 2 files changed, 21 insertions(+) diff --git a/include/sway/config.h b/include/sway/config.h index d9f561571..17b7a5735 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -710,6 +710,14 @@ void sort_output_configs_by_priority(struct matched_output_config *configs, */ void store_output_config(struct output_config *oc); +/** + * Store a temporary output config that will not be merged for testing + * purposes. This must be removed again after test, before any calls to + * store_output_config that could result in merge with the temporary config. + */ +void store_temp_output_config(struct output_config *oc); +void remove_temp_output_config(struct output_config *oc); + struct output_config *find_output_config(struct sway_output *output); void free_output_config(struct output_config *oc); diff --git a/sway/config/output.c b/sway/config/output.c index aa8504ed2..61148ab85 100644 --- a/sway/config/output.c +++ b/sway/config/output.c @@ -218,6 +218,19 @@ static void merge_output_config(struct output_config *dst, struct output_config } } +void remove_temp_output_config(struct output_config *oc) { + size_t idx = list_find(config->output_configs, oc); + if (idx) { + list_del(config->output_configs, idx); + } +} + +void store_temp_output_config(struct output_config *oc) { + // Add it directly so the config can be removed later + list_add(config->output_configs, oc); + return; +} + void store_output_config(struct output_config *oc) { bool merged = false; bool wildcard = strcmp(oc->name, "*") == 0;