From 2f1db190c65b8c495ac00db2593f6776635574e7 Mon Sep 17 00:00:00 2001 From: Kenny Levinsen Date: Tue, 3 Sep 2024 15:28:29 +0200 Subject: [PATCH] desktop/output: Do not use commit listener to arrange The reasoning for using a commit handler is to ensure that all paths for output changes are correctly handled. With the centralized modeset infrastructure in place, we can move the logic there. This allows us to be smarter and avoid extraneous arranges, output manager updates and transaction commits. The side-effect is a minor duplication for the special-case request_state, but the shared path will be relied upon further in future commits to justify this duplication. (cherry picked from commit b83e5aaa546792336ecc60d2e61708f3cd6b1f5d) --- include/sway/output.h | 2 ++ sway/config/output.c | 8 ++++++++ sway/desktop/output.c | 29 ++++++++++++++--------------- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/include/sway/output.h b/include/sway/output.h index 7e2d5892..a9e697d8 100644 --- a/include/sway/output.h +++ b/include/sway/output.h @@ -149,4 +149,6 @@ void handle_output_power_manager_set_mode(struct wl_listener *listener, struct sway_output_non_desktop *output_non_desktop_create(struct wlr_output *wlr_output); +void update_output_manager_config(struct sway_server *server); + #endif diff --git a/sway/config/output.c b/sway/config/output.c index 3e7d8ebd..230c2f5d 100644 --- a/sway/config/output.c +++ b/sway/config/output.c @@ -12,9 +12,12 @@ #include #include #include "sway/config.h" +#include "sway/desktop/transaction.h" #include "sway/input/cursor.h" +#include "sway/layers.h" #include "sway/output.h" #include "sway/server.h" +#include "sway/tree/arrange.h" #include "sway/tree/root.h" #include "log.h" #include "util.h" @@ -980,8 +983,13 @@ bool apply_output_configs(struct matched_output_config *configs, sway_log(SWAY_DEBUG, "Finalizing config for %s", cfg->output->wlr_output->name); finalize_output_config(cfg->config, cfg->output); + arrange_layers(cfg->output); } + arrange_root(); + update_output_manager_config(&server); + transaction_commit_dirty(); + out: wlr_output_swapchain_manager_finish(&swapchain_mgr); for (size_t idx = 0; idx < configs_len; idx++) { diff --git a/sway/desktop/output.c b/sway/desktop/output.c index c1aa4483..aaa8c087 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -374,7 +374,7 @@ static void handle_frame(struct wl_listener *listener, void *user_data) { wlr_scene_output_for_each_buffer(output->scene_output, send_frame_done_iterator, &data); } -static void update_output_manager_config(struct sway_server *server) { +void update_output_manager_config(struct sway_server *server) { struct wlr_output_configuration_v1 *config = wlr_output_configuration_v1_create(); @@ -405,9 +405,6 @@ static int timer_modeset_handle(void *data) { server->delayed_modeset = NULL; apply_all_output_configs(); - transaction_commit_dirty(); - update_output_manager_config(server); - return 0; } @@ -463,17 +460,6 @@ static void handle_commit(struct wl_listener *listener, void *data) { return; } - if (event->state->committed & ( - WLR_OUTPUT_STATE_MODE | - WLR_OUTPUT_STATE_TRANSFORM | - WLR_OUTPUT_STATE_SCALE)) { - arrange_layers(output); - arrange_output(output); - transaction_commit_dirty(); - - update_output_manager_config(output->server); - } - // Next time the output is enabled, try to re-apply the gamma LUT if ((event->state->committed & WLR_OUTPUT_STATE_ENABLED) && !output->wlr_output->enabled) { output->gamma_lut_changed = true; @@ -496,7 +482,20 @@ static void handle_request_state(struct wl_listener *listener, void *data) { struct sway_output *output = wl_container_of(listener, output, request_state); const struct wlr_output_event_request_state *event = data; + + uint32_t committed = event->state->committed; wlr_output_commit_state(output->wlr_output, event->state); + + if (committed & ( + WLR_OUTPUT_STATE_MODE | + WLR_OUTPUT_STATE_TRANSFORM | + WLR_OUTPUT_STATE_SCALE)) { + arrange_layers(output); + arrange_output(output); + transaction_commit_dirty(); + + update_output_manager_config(output->server); + } } static unsigned int last_headless_num = 0;