From 125c74338ac8bf8c15323a49730352b82d6d51bd Mon Sep 17 00:00:00 2001 From: Ferdinand Bachmann Date: Sun, 24 Mar 2024 12:20:05 +0100 Subject: [PATCH 01/12] man: document supported modifier names --- sway/sway.5.scd | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sway/sway.5.scd b/sway/sway.5.scd index 7e58b528..f73db3ba 100644 --- a/sway/sway.5.scd +++ b/sway/sway.5.scd @@ -400,6 +400,12 @@ runtime. only be available for that group. By default, if you overwrite a binding, swaynag will give you a warning. To silence this, use the _--no-warn_ flag. + For specifying modifier keys, you can use the XKB modifier names _Shift_, + _Lock_ (for Caps Lock), _Control_, _Mod1_ (for Alt), _Mod2_ (for Num Lock), + _Mod3_ (for XKB modifier Mod3), _Mod4_ (for the Logo key), and _Mod5_ (for + AltGr). In addition, you can use the aliases _Ctrl_ (for Control) and _Alt_ + (for Alt). + Unless the flag _--locked_ is set, the command will not be run when a screen locking program is active. If there is a matching binding with and without _--locked_, the one with will be preferred when locked and the From e2f3ebad8c1943800dd5f017d547d9d98bfb8bb1 Mon Sep 17 00:00:00 2001 From: Kenny Levinsen Date: Sat, 16 Mar 2024 00:37:06 +0100 Subject: [PATCH 02/12] config/output: Split apply_output_config Applying an output config has two stages: Atomic application of wlr_output_state, and applicaiton of non-atomic state like output layout. Split the latter out into finalize_output_config for use in a later commit. --- sway/config/output.c | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/sway/config/output.c b/sway/config/output.c index 1b2332e9..fd1d6e3c 100644 --- a/sway/config/output.c +++ b/sway/config/output.c @@ -503,25 +503,12 @@ static void queue_output_config(struct output_config *oc, } } -bool apply_output_config(struct output_config *oc, struct sway_output *output) { +static bool finalize_output_config(struct output_config *oc, struct sway_output *output) { if (output == root->fallback_output) { return false; } struct wlr_output *wlr_output = output->wlr_output; - - struct wlr_output_state pending = {0}; - queue_output_config(oc, output, &pending); - - sway_log(SWAY_DEBUG, "Committing output %s", wlr_output->name); - if (!wlr_output_commit_state(wlr_output, &pending)) { - // Failed to commit output changes, maybe the output is missing a CRTC. - // Leave the output disabled for now and try again when the output gets - // the mode we asked for. - sway_log(SWAY_ERROR, "Failed to commit output %s", wlr_output->name); - return false; - } - if (oc && !oc->enabled) { sway_log(SWAY_DEBUG, "Disabling output %s", oc->name); if (output->enabled) { @@ -577,6 +564,30 @@ bool apply_output_config(struct output_config *oc, struct sway_output *output) { output->max_render_time = oc->max_render_time; } + return true; +} + +bool apply_output_config(struct output_config *oc, struct sway_output *output) { + if (output == root->fallback_output) { + return false; + } + + struct wlr_output_state pending = {0}; + queue_output_config(oc, output, &pending); + + sway_log(SWAY_DEBUG, "Committing output %s", output->wlr_output->name); + if (!wlr_output_commit_state(output->wlr_output, &pending)) { + // Failed to commit output changes, maybe the output is missing a CRTC. + // Leave the output disabled for now and try again when the output gets + // the mode we asked for. + sway_log(SWAY_ERROR, "Failed to commit output %s", output->wlr_output->name); + return false; + } + + if (!finalize_output_config(oc, output)) { + return false; + } + // Reconfigure all devices, since input config may have been applied before // this output came online, and some config items (like map_to_output) are // dependent on an output being present. From 3e03eb3a017d144137dbe6591891f3a51a61dea0 Mon Sep 17 00:00:00 2001 From: Kenny Levinsen Date: Sat, 16 Mar 2024 00:48:56 +0100 Subject: [PATCH 03/12] config/output: Introduce apply_output_configs Introduce apply_output_configs, which applies the specified matched output configs as a single backend commit. Reimplement apply_output_config_to_outputs using apply_output_configs. --- include/sway/config.h | 11 ++++ sway/config/output.c | 148 +++++++++++++++++++++++++++++++++++------- 2 files changed, 135 insertions(+), 24 deletions(-) diff --git a/include/sway/config.h b/include/sway/config.h index f9da1967..d23fe578 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -291,6 +291,14 @@ struct output_config { char *background_fallback; }; +/** + * An output config pre-matched to an output + */ +struct matched_output_config { + struct sway_output *output; + struct output_config *config; +}; + /** * Stores size of gaps for each side */ @@ -684,6 +692,9 @@ void merge_output_config(struct output_config *dst, struct output_config *src); bool apply_output_config(struct output_config *oc, struct sway_output *output); +bool apply_output_configs(struct matched_output_config *configs, + size_t configs_len, bool test_only); + bool test_output_config(struct output_config *oc, struct sway_output *output); struct output_config *store_output_config(struct output_config *oc); diff --git a/sway/config/output.c b/sway/config/output.c index fd1d6e3c..de9515e2 100644 --- a/sway/config/output.c +++ b/sway/config/output.c @@ -9,6 +9,7 @@ #include #include #include +#include #include "sway/config.h" #include "sway/input/cursor.h" #include "sway/output.h" @@ -716,39 +717,138 @@ struct output_config *find_output_config(struct sway_output *output) { return get_output_config(id, output); } -void apply_output_config_to_outputs(struct output_config *oc) { - // Try to find the output container and apply configuration now. If - // this is during startup then there will be no container and config - // will be applied during normal "new output" event from wlroots. - bool wildcard = strcmp(oc->name, "*") == 0; - struct sway_output *sway_output, *tmp; - wl_list_for_each_safe(sway_output, tmp, &root->all_outputs, link) { - if (output_match_name_or_id(sway_output, oc->name)) { - char id[128]; - output_get_identifier(id, sizeof(id), sway_output); - struct output_config *current = get_output_config(id, sway_output); - if (!current) { - // No stored output config matched, apply oc directly - sway_log(SWAY_DEBUG, "Applying oc directly"); - current = new_output_config(oc->name); - merge_output_config(current, oc); - } - apply_output_config(current, sway_output); - free_output_config(current); +bool apply_output_configs(struct matched_output_config *configs, + size_t configs_len, bool test_only) { + struct wlr_backend_output_state *states = calloc(configs_len, sizeof(*states)); + if (!states) { + return false; + } - if (!wildcard) { - // Stop looking if the output config isn't applicable to all - // outputs - break; - } + sway_log(SWAY_DEBUG, "Committing %zd outputs", configs_len); + for (size_t idx = 0; idx < configs_len; idx++) { + struct matched_output_config *cfg = &configs[idx]; + struct wlr_backend_output_state *backend_state = &states[idx]; + + backend_state->output = cfg->output->wlr_output; + wlr_output_state_init(&backend_state->base); + + sway_log(SWAY_DEBUG, "Preparing config for %s", + cfg->output->wlr_output->name); + queue_output_config(cfg->config, cfg->output, &backend_state->base); + } + + struct wlr_output_swapchain_manager swapchain_mgr; + wlr_output_swapchain_manager_init(&swapchain_mgr, server.backend); + + bool ok = wlr_output_swapchain_manager_prepare(&swapchain_mgr, states, configs_len); + if (!ok) { + sway_log(SWAY_ERROR, "Swapchain prepare failed"); + goto out; + } + + if (test_only) { + // The swapchain manager already did a test for us + goto out; + } + + for (size_t idx = 0; idx < configs_len; idx++) { + struct matched_output_config *cfg = &configs[idx]; + struct wlr_backend_output_state *backend_state = &states[idx]; + + struct wlr_scene_output_state_options opts = { + .swapchain = wlr_output_swapchain_manager_get_swapchain( + &swapchain_mgr, backend_state->output), + }; + struct wlr_scene_output *scene_output = cfg->output->scene_output; + struct wlr_output_state *state = &backend_state->base; + if (!wlr_scene_output_build_state(scene_output, state, &opts)) { + sway_log(SWAY_ERROR, "Building output state for '%s' failed", + backend_state->output->name); + goto out; } } + ok = wlr_backend_commit(server.backend, states, configs_len); + if (!ok) { + sway_log(SWAY_ERROR, "Backend commit failed"); + goto out; + } + + sway_log(SWAY_DEBUG, "Commit of %zd outputs succeeded", configs_len); + + wlr_output_swapchain_manager_apply(&swapchain_mgr); + + for (size_t idx = 0; idx < configs_len; idx++) { + struct matched_output_config *cfg = &configs[idx]; + sway_log(SWAY_DEBUG, "Finalizing config for %s", + cfg->output->wlr_output->name); + finalize_output_config(cfg->config, cfg->output); + } + +out: + wlr_output_swapchain_manager_finish(&swapchain_mgr); + for (size_t idx = 0; idx < configs_len; idx++) { + struct wlr_backend_output_state *backend_state = &states[idx]; + wlr_output_state_finish(&backend_state->base); + } + free(states); + + // Reconfigure all devices, since input config may have been applied before + // this output came online, and some config items (like map_to_output) are + // dependent on an output being present. + input_manager_configure_all_input_mappings(); + // Reconfigure the cursor images, since the scale may have changed. + input_manager_configure_xcursor(); + struct sway_seat *seat; wl_list_for_each(seat, &server.input->seats, link) { wlr_seat_pointer_notify_clear_focus(seat->wlr_seat); cursor_rebase(seat->cursor); } + + return ok; +} + +void apply_output_config_to_outputs(struct output_config *oc) { + size_t configs_len = wl_list_length(&root->all_outputs); + struct matched_output_config *configs = calloc(configs_len, sizeof(*configs)); + if (!configs) { + return; + } + + // Try to find the output container and apply configuration now. If + // this is during startup then there will be no container and config + // will be applied during normal "new output" event from wlroots. + int config_idx = 0; + struct sway_output *sway_output; + wl_list_for_each(sway_output, &root->all_outputs, link) { + if (sway_output == root->fallback_output) { + configs_len--; + continue; + } + + struct matched_output_config *config = &configs[config_idx++]; + config->output = sway_output; + config->config = find_output_config(sway_output); + + if (!output_match_name_or_id(sway_output, oc->name)) { + continue; + } + + if (!config->config && oc) { + // No stored output config matched, apply oc directly + sway_log(SWAY_DEBUG, "Applying oc directly"); + config->config = new_output_config(oc->name); + merge_output_config(config->config, oc); + } + } + + apply_output_configs(configs, configs_len, false); + for (size_t idx = 0; idx < configs_len; idx++) { + struct matched_output_config *cfg = &configs[idx]; + free_output_config(cfg->config); + } + free(configs); } void reset_outputs(void) { From 923f642b704022442cc3245a2fa13278341c14e0 Mon Sep 17 00:00:00 2001 From: Kenny Levinsen Date: Sat, 16 Mar 2024 00:57:11 +0100 Subject: [PATCH 04/12] output/config: Add apply_all_output_configs Apply all output configs as they are. This differs from apply_output_config_to_outputs, which tries to apply a specific output config. --- include/sway/config.h | 2 ++ sway/config/output.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/include/sway/config.h b/include/sway/config.h index d23fe578..eff7cfbb 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -695,6 +695,8 @@ bool apply_output_config(struct output_config *oc, struct sway_output *output); bool apply_output_configs(struct matched_output_config *configs, size_t configs_len, bool test_only); +void apply_all_output_configs(void); + bool test_output_config(struct output_config *oc, struct sway_output *output); struct output_config *store_output_config(struct output_config *oc); diff --git a/sway/config/output.c b/sway/config/output.c index de9515e2..5bf5bed5 100644 --- a/sway/config/output.c +++ b/sway/config/output.c @@ -809,6 +809,34 @@ out: return ok; } +void apply_all_output_configs(void) { + size_t configs_len = wl_list_length(&root->all_outputs); + struct matched_output_config *configs = calloc(configs_len, sizeof(*configs)); + if (!configs) { + return; + } + + int config_idx = 0; + struct sway_output *sway_output; + wl_list_for_each(sway_output, &root->all_outputs, link) { + if (sway_output == root->fallback_output) { + configs_len--; + continue; + } + + struct matched_output_config *config = &configs[config_idx++]; + config->output = sway_output; + config->config = find_output_config(sway_output); + } + + apply_output_configs(configs, configs_len, false); + for (size_t idx = 0; idx < configs_len; idx++) { + struct matched_output_config *cfg = &configs[idx]; + free_output_config(cfg->config); + } + free(configs); +} + void apply_output_config_to_outputs(struct output_config *oc) { size_t configs_len = wl_list_length(&root->all_outputs); struct matched_output_config *configs = calloc(configs_len, sizeof(*configs)); From 98be797356876153e74405dbef36e3e71875ca2e Mon Sep 17 00:00:00 2001 From: Kenny Levinsen Date: Sat, 16 Mar 2024 01:00:46 +0100 Subject: [PATCH 05/12] Use apply_all_output_configs to light up outputs This allows us to test and if necessary degrade the entire backend configuration to light everything up. --- sway/commands/output.c | 4 ++-- sway/desktop/output.c | 8 +++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/sway/commands/output.c b/sway/commands/output.c index 462dffd2..5e5d31b3 100644 --- a/sway/commands/output.c +++ b/sway/commands/output.c @@ -103,13 +103,13 @@ struct cmd_results *cmd_output(int argc, char **argv) { bool background = output->background; - output = store_output_config(output); + store_output_config(output); // If reloading, the output configs will be applied after reading the // entire config and before the deferred commands so that an auto generated // workspace name is not given to re-enabled outputs. if (!config->reloading && !config->validating) { - apply_output_config_to_outputs(output); + apply_all_output_configs(); if (background) { if (!spawn_swaybg()) { return cmd_results_new(CMD_FAILURE, diff --git a/sway/desktop/output.c b/sway/desktop/output.c index b8f2d32d..b2647219 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -521,9 +521,7 @@ void handle_new_output(struct wl_listener *listener, void *data) { sway_session_lock_add_output(server->session_lock.lock, output); } - struct output_config *oc = find_output_config(output); - apply_output_config(oc, output); - free_output_config(oc); + apply_all_output_configs(); transaction_commit_dirty(); @@ -652,6 +650,6 @@ void handle_output_power_manager_set_mode(struct wl_listener *listener, oc->power = 1; break; } - oc = store_output_config(oc); - apply_output_config(oc, output); + store_output_config(oc); + apply_all_output_configs(); } From 3b419020a32f4f8385e49d2137ceb4d9b8262176 Mon Sep 17 00:00:00 2001 From: Kenny Levinsen Date: Sat, 16 Mar 2024 01:01:56 +0100 Subject: [PATCH 06/12] desktop/output: Use apply_output_configs for output mgmt --- sway/desktop/output.c | 113 ++++++++++++++++++++++++++---------------- 1 file changed, 69 insertions(+), 44 deletions(-) diff --git a/sway/desktop/output.c b/sway/desktop/output.c index b2647219..bd3de3fe 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -550,63 +550,88 @@ void handle_gamma_control_set_gamma(struct wl_listener *listener, void *data) { wlr_output_schedule_frame(output->wlr_output); } +static struct output_config *output_config_for_config_head( + struct wlr_output_configuration_head_v1 *config_head, + struct sway_output *output) { + struct output_config *oc = new_output_config(output->wlr_output->name); + oc->enabled = config_head->state.enabled; + if (!oc->enabled) { + return oc; + } + + if (config_head->state.mode != NULL) { + struct wlr_output_mode *mode = config_head->state.mode; + oc->width = mode->width; + oc->height = mode->height; + oc->refresh_rate = mode->refresh / 1000.f; + } else { + oc->width = config_head->state.custom_mode.width; + oc->height = config_head->state.custom_mode.height; + oc->refresh_rate = + config_head->state.custom_mode.refresh / 1000.f; + } + oc->x = config_head->state.x; + oc->y = config_head->state.y; + oc->transform = config_head->state.transform; + oc->scale = config_head->state.scale; + oc->adaptive_sync = config_head->state.adaptive_sync_enabled; + return oc; +} + static void output_manager_apply(struct sway_server *server, struct wlr_output_configuration_v1 *config, bool test_only) { - // TODO: perform atomic tests on the whole backend atomically + size_t configs_len = wl_list_length(&root->all_outputs); + struct matched_output_config *configs = calloc(configs_len, sizeof(*configs)); + if (!configs) { + return; + } - struct wlr_output_configuration_head_v1 *config_head; - // First disable outputs we need to disable - bool ok = true; - wl_list_for_each(config_head, &config->heads, link) { - struct wlr_output *wlr_output = config_head->state.output; - struct sway_output *output = wlr_output->data; - if (!output->enabled || config_head->state.enabled) { + int config_idx = 0; + struct sway_output *sway_output; + wl_list_for_each(sway_output, &root->all_outputs, link) { + if (sway_output == root->fallback_output) { + configs_len--; continue; } - struct output_config *oc = new_output_config(output->wlr_output->name); - oc->enabled = false; - if (test_only) { - ok &= test_output_config(oc, output); - } else { - oc = store_output_config(oc); - ok &= apply_output_config(oc, output); + struct matched_output_config *cfg = &configs[config_idx++]; + cfg->output = sway_output; + + struct wlr_output_configuration_head_v1 *config_head; + wl_list_for_each(config_head, &config->heads, link) { + if (config_head->state.output == sway_output->wlr_output) { + cfg->config = output_config_for_config_head(config_head, sway_output); + break; + } + } + if (!cfg->config) { + cfg->config = find_output_config(sway_output); } } - // Then enable outputs that need to - wl_list_for_each(config_head, &config->heads, link) { - struct wlr_output *wlr_output = config_head->state.output; - struct sway_output *output = wlr_output->data; - if (!config_head->state.enabled) { - continue; - } - struct output_config *oc = new_output_config(output->wlr_output->name); - oc->enabled = true; - if (config_head->state.mode != NULL) { - struct wlr_output_mode *mode = config_head->state.mode; - oc->width = mode->width; - oc->height = mode->height; - oc->refresh_rate = mode->refresh / 1000.f; - } else { - oc->width = config_head->state.custom_mode.width; - oc->height = config_head->state.custom_mode.height; - oc->refresh_rate = - config_head->state.custom_mode.refresh / 1000.f; - } - oc->x = config_head->state.x; - oc->y = config_head->state.y; - oc->transform = config_head->state.transform; - oc->scale = config_head->state.scale; - oc->adaptive_sync = config_head->state.adaptive_sync_enabled; + bool ok = apply_output_configs(configs, configs_len, test_only); + for (size_t idx = 0; idx < configs_len; idx++) { + struct matched_output_config *cfg = &configs[idx]; - if (test_only) { - ok &= test_output_config(oc, output); + // Only store new configs for successful non-test commits. Old configs, + // test-only and failed commits just get freed. + bool store_config = false; + if (!test_only && ok) { + struct wlr_output_configuration_head_v1 *config_head; + wl_list_for_each(config_head, &config->heads, link) { + if (config_head->state.output == sway_output->wlr_output) { + store_config = true; + break; + } + } + } + if (store_config) { + store_output_config(cfg->config); } else { - oc = store_output_config(oc); - ok &= apply_output_config(oc, output); + free_output_config(cfg->config); } } + free(configs); if (ok) { wlr_output_configuration_v1_send_succeeded(config); From 56e97b7d60e3723f79fd972061191117bf544f08 Mon Sep 17 00:00:00 2001 From: Kenny Levinsen Date: Sat, 16 Mar 2024 01:03:37 +0100 Subject: [PATCH 07/12] config/output: Remove apply_output_config --- include/sway/config.h | 2 -- sway/config/output.c | 30 ------------------------------ 2 files changed, 32 deletions(-) diff --git a/include/sway/config.h b/include/sway/config.h index eff7cfbb..69b14446 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -690,8 +690,6 @@ struct output_config *new_output_config(const char *name); void merge_output_config(struct output_config *dst, struct output_config *src); -bool apply_output_config(struct output_config *oc, struct sway_output *output); - bool apply_output_configs(struct matched_output_config *configs, size_t configs_len, bool test_only); diff --git a/sway/config/output.c b/sway/config/output.c index 5bf5bed5..cb12683d 100644 --- a/sway/config/output.c +++ b/sway/config/output.c @@ -568,36 +568,6 @@ static bool finalize_output_config(struct output_config *oc, struct sway_output return true; } -bool apply_output_config(struct output_config *oc, struct sway_output *output) { - if (output == root->fallback_output) { - return false; - } - - struct wlr_output_state pending = {0}; - queue_output_config(oc, output, &pending); - - sway_log(SWAY_DEBUG, "Committing output %s", output->wlr_output->name); - if (!wlr_output_commit_state(output->wlr_output, &pending)) { - // Failed to commit output changes, maybe the output is missing a CRTC. - // Leave the output disabled for now and try again when the output gets - // the mode we asked for. - sway_log(SWAY_ERROR, "Failed to commit output %s", output->wlr_output->name); - return false; - } - - if (!finalize_output_config(oc, output)) { - return false; - } - - // Reconfigure all devices, since input config may have been applied before - // this output came online, and some config items (like map_to_output) are - // dependent on an output being present. - input_manager_configure_all_input_mappings(); - // Reconfigure the cursor images, since the scale may have changed. - input_manager_configure_xcursor(); - return true; -} - bool test_output_config(struct output_config *oc, struct sway_output *output) { if (output == root->fallback_output) { return false; From 9becff0ba56ac7da8b1235aa5740fb04414636a2 Mon Sep 17 00:00:00 2001 From: Kenny Levinsen Date: Sat, 16 Mar 2024 01:11:35 +0100 Subject: [PATCH 08/12] output/config: Remove reset_outputs and co. apply_output_config_to_outputs uses the specified output config to check which outputs to apply to, and to use as backup when no config is found. If any config matches the output, the specified config will be disregarded. The only remaining user of apply_output_config_to_outputs is reset_outputs, which called apply_output_config_to_outputs with either the first stored wildcard config, or a new empty wildcard config. Providing a stored or empty wildcard config is practically the same as calling `apply_all_output_configs`. Replace uses of `reset_outputs` with `apply_all_output_configs` and remove the now unused functions. --- include/sway/config.h | 4 ---- sway/config.c | 2 +- sway/config/output.c | 53 ------------------------------------------- 3 files changed, 1 insertion(+), 58 deletions(-) diff --git a/include/sway/config.h b/include/sway/config.h index 69b14446..7e67ba21 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -701,10 +701,6 @@ struct output_config *store_output_config(struct output_config *oc); struct output_config *find_output_config(struct sway_output *output); -void apply_output_config_to_outputs(struct output_config *oc); - -void reset_outputs(void); - void free_output_config(struct output_config *oc); bool spawn_swaybg(void); diff --git a/sway/config.c b/sway/config.c index 72fc41e7..f9131e0f 100644 --- a/sway/config.c +++ b/sway/config.c @@ -532,7 +532,7 @@ bool load_main_config(const char *file, bool is_active, bool validating) { } sway_switch_retrigger_bindings_for_all(); - reset_outputs(); + apply_all_output_configs(); spawn_swaybg(); config->reloading = false; diff --git a/sway/config/output.c b/sway/config/output.c index cb12683d..a7c2f9b8 100644 --- a/sway/config/output.c +++ b/sway/config/output.c @@ -807,59 +807,6 @@ void apply_all_output_configs(void) { free(configs); } -void apply_output_config_to_outputs(struct output_config *oc) { - size_t configs_len = wl_list_length(&root->all_outputs); - struct matched_output_config *configs = calloc(configs_len, sizeof(*configs)); - if (!configs) { - return; - } - - // Try to find the output container and apply configuration now. If - // this is during startup then there will be no container and config - // will be applied during normal "new output" event from wlroots. - int config_idx = 0; - struct sway_output *sway_output; - wl_list_for_each(sway_output, &root->all_outputs, link) { - if (sway_output == root->fallback_output) { - configs_len--; - continue; - } - - struct matched_output_config *config = &configs[config_idx++]; - config->output = sway_output; - config->config = find_output_config(sway_output); - - if (!output_match_name_or_id(sway_output, oc->name)) { - continue; - } - - if (!config->config && oc) { - // No stored output config matched, apply oc directly - sway_log(SWAY_DEBUG, "Applying oc directly"); - config->config = new_output_config(oc->name); - merge_output_config(config->config, oc); - } - } - - apply_output_configs(configs, configs_len, false); - for (size_t idx = 0; idx < configs_len; idx++) { - struct matched_output_config *cfg = &configs[idx]; - free_output_config(cfg->config); - } - free(configs); -} - -void reset_outputs(void) { - struct output_config *oc = NULL; - int i = list_seq_find(config->output_configs, output_name_cmp, "*"); - if (i >= 0) { - oc = config->output_configs->items[i]; - } else { - oc = store_output_config(new_output_config("*")); - } - apply_output_config_to_outputs(oc); -} - void free_output_config(struct output_config *oc) { if (!oc) { return; From c3fca26d303617614bee67ad766fd3cb95609245 Mon Sep 17 00:00:00 2001 From: Kenny Levinsen Date: Sat, 16 Mar 2024 13:25:23 +0100 Subject: [PATCH 09/12] config/output: Make merge_output_config static --- include/sway/config.h | 2 -- sway/config/output.c | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/include/sway/config.h b/include/sway/config.h index 7e67ba21..5a303d9f 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -688,8 +688,6 @@ const char *sway_output_scale_filter_to_string(enum scale_filter_mode scale_filt struct output_config *new_output_config(const char *name); -void merge_output_config(struct output_config *dst, struct output_config *src); - bool apply_output_configs(struct matched_output_config *configs, size_t configs_len, bool test_only); diff --git a/sway/config/output.c b/sway/config/output.c index a7c2f9b8..72cbf261 100644 --- a/sway/config/output.c +++ b/sway/config/output.c @@ -79,7 +79,7 @@ struct output_config *new_output_config(const char *name) { return oc; } -void merge_output_config(struct output_config *dst, struct output_config *src) { +static void merge_output_config(struct output_config *dst, struct output_config *src) { if (src->enabled != -1) { dst->enabled = src->enabled; } From 26a9a6b4792a1b2b00406ae6c20ea88325e7c7aa Mon Sep 17 00:00:00 2001 From: Kenny Levinsen Date: Sat, 16 Mar 2024 13:25:45 +0100 Subject: [PATCH 10/12] output/config: Remove unused test_output_config --- include/sway/config.h | 2 -- sway/config/output.c | 10 ---------- 2 files changed, 12 deletions(-) diff --git a/include/sway/config.h b/include/sway/config.h index 5a303d9f..40710199 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -693,8 +693,6 @@ bool apply_output_configs(struct matched_output_config *configs, void apply_all_output_configs(void); -bool test_output_config(struct output_config *oc, struct sway_output *output); - struct output_config *store_output_config(struct output_config *oc); struct output_config *find_output_config(struct sway_output *output); diff --git a/sway/config/output.c b/sway/config/output.c index 72cbf261..3f1c3126 100644 --- a/sway/config/output.c +++ b/sway/config/output.c @@ -568,16 +568,6 @@ static bool finalize_output_config(struct output_config *oc, struct sway_output return true; } -bool test_output_config(struct output_config *oc, struct sway_output *output) { - if (output == root->fallback_output) { - return false; - } - - struct wlr_output_state pending = {0}; - queue_output_config(oc, output, &pending); - return wlr_output_test_state(output->wlr_output, &pending); -} - static void default_output_config(struct output_config *oc, struct wlr_output *wlr_output) { oc->enabled = 1; From a4ef37752fd6ae9e84d60cbe4eaead07f71f9435 Mon Sep 17 00:00:00 2001 From: Kenny Levinsen Date: Sat, 16 Mar 2024 17:55:07 +0100 Subject: [PATCH 11/12] commands/output/toggle: Use free_output_config --- sway/commands/output/toggle.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sway/commands/output/toggle.c b/sway/commands/output/toggle.c index 6342d526..c6b72845 100644 --- a/sway/commands/output/toggle.c +++ b/sway/commands/output/toggle.c @@ -29,7 +29,7 @@ struct cmd_results *output_cmd_toggle(int argc, char **argv) { config->handler_context.output_config->enabled = 1; } - free(oc); + free_output_config(oc); config->handler_context.leftovers.argc = argc; config->handler_context.leftovers.argv = argv; return NULL; From 9e1465107788af2c8ce93e2a288e9d32bc09711c Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Thu, 28 Mar 2024 11:45:46 +0100 Subject: [PATCH 12/12] input: pass wlr_seat_client to wlr_seat_touch_notify_cancel() References: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/4613 --- sway/input/seatop_down.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sway/input/seatop_down.c b/sway/input/seatop_down.c index 35fd3bcb..340e334b 100644 --- a/sway/input/seatop_down.c +++ b/sway/input/seatop_down.c @@ -117,7 +117,11 @@ static void handle_touch_cancel(struct sway_seat *seat, } if (e->surface) { - wlr_seat_touch_notify_cancel(seat->wlr_seat, e->surface); + struct wl_client *client = wl_resource_get_client(e->surface->resource); + struct wlr_seat_client *seat_client = wlr_seat_client_for_wl_client(seat->wlr_seat, client); + if (seat_client != NULL) { + wlr_seat_touch_notify_cancel(seat->wlr_seat, seat_client); + } } if (wl_list_empty(&e->point_events)) {