From 62a25da57562b37cfec25994c1c87d1567379163 Mon Sep 17 00:00:00 2001 From: John Lindgren Date: Sat, 19 Oct 2024 20:12:10 -0400 Subject: [PATCH] output: factor out configure_new_output() from new_output_notify() ... to make it possible in future to *not* immediately auto-configure new outputs when connected. No functional change intended at this time. --- src/output.c | 121 +++++++++++++++++++++++++++------------------------ 1 file changed, 64 insertions(+), 57 deletions(-) diff --git a/src/output.c b/src/output.c index 4386a1b9..20e29458 100644 --- a/src/output.c +++ b/src/output.c @@ -287,6 +287,69 @@ add_output_to_layout(struct server *server, struct output *output) } } +static void +configure_new_output(struct server *server, struct output *output) +{ + struct wlr_output *wlr_output = output->wlr_output; + + wlr_log(WLR_DEBUG, "enable output"); + wlr_output_state_set_enabled(&output->pending, true); + + /* + * Try to re-use the existing mode if configured to do so. + * Failing that, try to set the preferred mode. + */ + struct wlr_output_mode *preferred_mode = NULL; + if (!rc.reuse_output_mode || !can_reuse_mode(output)) { + wlr_log(WLR_DEBUG, "set preferred mode"); + /* The mode is a tuple of (width, height, refresh rate). */ + preferred_mode = wlr_output_preferred_mode(wlr_output); + if (preferred_mode) { + wlr_output_state_set_mode(&output->pending, + preferred_mode); + } + } + + /* + * Sometimes the preferred mode is not available due to hardware + * constraints (e.g. GPU or cable bandwidth limitations). In these + * cases it's better to fallback to lower modes than to end up with + * a black screen. See sway@4cdc4ac6 + */ + if (!wlr_output_test_state(wlr_output, &output->pending)) { + wlr_log(WLR_DEBUG, + "preferred mode rejected, falling back to another mode"); + struct wlr_output_mode *mode; + wl_list_for_each(mode, &wlr_output->modes, link) { + if (mode == preferred_mode) { + continue; + } + wlr_output_state_set_mode(&output->pending, mode); + if (wlr_output_test_state(wlr_output, &output->pending)) { + break; + } + } + } + + if (rc.adaptive_sync == LAB_ADAPTIVE_SYNC_ENABLED) { + output_enable_adaptive_sync(output, true); + } + + output_state_commit(output); + + wlr_output_effective_resolution(wlr_output, + &output->usable_area.width, &output->usable_area.height); + + /* + * Wait until wlr_output_layout_add_auto() returns before + * calling do_output_layout_change(); this ensures that the + * wlr_output_cursor is created for the new output. + */ + server->pending_output_layout_change++; + add_output_to_layout(server, output); + server->pending_output_layout_change--; +} + static void new_output_notify(struct wl_listener *listener, void *data) { @@ -353,53 +416,6 @@ new_output_notify(struct wl_listener *listener, void *data) output->server = server; output_state_init(output); - wlr_log(WLR_DEBUG, "enable output"); - wlr_output_state_set_enabled(&output->pending, true); - - /* - * Try to re-use the existing mode if configured to do so. - * Failing that, try to set the preferred mode. - */ - struct wlr_output_mode *preferred_mode = NULL; - if (!rc.reuse_output_mode || !can_reuse_mode(output)) { - wlr_log(WLR_DEBUG, "set preferred mode"); - /* The mode is a tuple of (width, height, refresh rate). */ - preferred_mode = wlr_output_preferred_mode(wlr_output); - if (preferred_mode) { - wlr_output_state_set_mode(&output->pending, - preferred_mode); - } - } - - /* - * Sometimes the preferred mode is not available due to hardware - * constraints (e.g. GPU or cable bandwidth limitations). In these - * cases it's better to fallback to lower modes than to end up with - * a black screen. See sway@4cdc4ac6 - */ - if (!wlr_output_test_state(wlr_output, &output->pending)) { - wlr_log(WLR_DEBUG, - "preferred mode rejected, falling back to another mode"); - struct wlr_output_mode *mode; - wl_list_for_each(mode, &wlr_output->modes, link) { - if (mode == preferred_mode) { - continue; - } - wlr_output_state_set_mode(&output->pending, mode); - if (wlr_output_test_state(wlr_output, &output->pending)) { - break; - } - } - } - - if (rc.adaptive_sync == LAB_ADAPTIVE_SYNC_ENABLED) { - output_enable_adaptive_sync(output, true); - } - - output_state_commit(output); - - wlr_output_effective_resolution(wlr_output, - &output->usable_area.width, &output->usable_area.height); wl_list_insert(&server->outputs, &output->link); output->destroy.notify = output_destroy_notify; @@ -450,16 +466,7 @@ new_output_notify(struct wl_listener *listener, void *data) wlr_scene_node_raise_to_top(&output->layer_popup_tree->node); wlr_scene_node_raise_to_top(&output->session_lock_tree->node); - /* - * Wait until wlr_output_layout_add_auto() returns before - * calling do_output_layout_change(); this ensures that the - * wlr_output_cursor is created for the new output. - */ - server->pending_output_layout_change++; - - add_output_to_layout(server, output); - - server->pending_output_layout_change--; + configure_new_output(server, output); do_output_layout_change(server); } -- 2.52.0