From 77b965dc3373b071f0936928e6569f89ca245949 Mon Sep 17 00:00:00 2001 From: Ricardo Steijn Date: Sun, 4 Aug 2024 19:16:26 +0200 Subject: [PATCH] fix: don't mess with output timings when tearing is enabled --- include/sway/output.h | 2 +- sway/desktop/output.c | 42 ++++++++++++++++++++---------------------- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/include/sway/output.h b/include/sway/output.h index 26e4798c8..7e2d58927 100644 --- a/include/sway/output.h +++ b/include/sway/output.h @@ -73,7 +73,7 @@ struct sway_output { int max_render_time; // In milliseconds struct wl_event_source *repaint_timer; bool gamma_lut_changed; - bool allow_tearing, enable_tearing; + bool allow_tearing; }; struct sway_output_non_desktop { diff --git a/sway/desktop/output.c b/sway/desktop/output.c index e525459a3..f1e08eff8 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -232,6 +232,23 @@ static void output_configure_scene(struct sway_output *output, } } +static bool output_can_tear(struct sway_output *output) { + struct sway_workspace *workspace = output->current.active_workspace; + if (!workspace) { + return false; + } + + struct sway_container *fullscreen_con = root->fullscreen_global; + if (!fullscreen_con) { + fullscreen_con = workspace->current.fullscreen; + } + if (fullscreen_con && fullscreen_con->view) { + return (output->allow_tearing && view_can_tear(fullscreen_con->view)); + } + + return false; +} + static int output_repaint_timer_handler(void *data) { struct sway_output *output = data; @@ -276,7 +293,7 @@ static int output_repaint_timer_handler(void *data) { } } - if (output->enable_tearing) { + if (output_can_tear(output)) { pending.tearing_page_flip = true; if (!wlr_output_test_state(output->wlr_output, &pending)) { @@ -294,23 +311,6 @@ static int output_repaint_timer_handler(void *data) { return 0; } -static bool output_can_tear(struct sway_output *output) { - struct sway_workspace *workspace = output->current.active_workspace; - if (!workspace) { - return false; - } - - struct sway_container *fullscreen_con = root->fullscreen_global; - if (!fullscreen_con) { - fullscreen_con = workspace->current.fullscreen; - } - if (fullscreen_con && fullscreen_con->view) { - return (output->allow_tearing && view_can_tear(fullscreen_con->view)); - } - - return false; -} - static void handle_frame(struct wl_listener *listener, void *user_data) { struct sway_output *output = wl_container_of(listener, output, frame); @@ -358,11 +358,9 @@ static void handle_frame(struct wl_listener *listener, void *user_data) { int delay = msec_until_refresh - output->max_render_time; - output->enable_tearing = output_can_tear(output); - // If the delay is less than 1 millisecond (which is the least we can wait) - // or if the output is allowed to tear, then just render right away. - if (delay < 1 || output->enable_tearing) { + // then just render right away. + if (delay < 1) { output_repaint_timer_handler(output); } else { output->wlr_output->frame_pending = true;