From a9ba46971540e643feeb64e6e62f99c6666698ae Mon Sep 17 00:00:00 2001 From: Ricardo Steijn Date: Sat, 13 Jul 2024 19:30:59 +0200 Subject: [PATCH] fix: review comments --- include/sway/output.h | 2 +- sway/commands/allow_tearing.c | 21 ++++++++++----------- sway/commands/output/allow_tearing.c | 18 +++++++++--------- sway/desktop/output.c | 13 ++++--------- sway/sway-output.5.scd | 14 ++++++++------ sway/sway.5.scd | 2 +- sway/tree/view.c | 2 +- 7 files changed, 34 insertions(+), 38 deletions(-) diff --git a/include/sway/output.h b/include/sway/output.h index 8ded00f43..26e4798c8 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, can_tear; + bool allow_tearing, enable_tearing; }; struct sway_output_non_desktop { diff --git a/sway/commands/allow_tearing.c b/sway/commands/allow_tearing.c index f70f78954..ee5941381 100644 --- a/sway/commands/allow_tearing.c +++ b/sway/commands/allow_tearing.c @@ -4,22 +4,21 @@ #include "util.h" struct cmd_results *cmd_allow_tearing(int argc, char **argv) { - struct cmd_results *error = NULL; + struct cmd_results *error = NULL; if ((error = checkarg(argc, "allow_tearing", EXPECTED_AT_LEAST, 1))) { return error; } - struct sway_container *container = config->handler_context.container; - if (!container || !container->view) { - return cmd_results_new(CMD_INVALID, - "Tearing can only be allowed on views"); - } + struct sway_container *container = config->handler_context.container; + if (!container || !container->view) { + return cmd_results_new(CMD_INVALID, "Tearing can only be allowed on views"); + } - bool wants_tearing = parse_boolean(argv[0], true); + bool wants_tearing = parse_boolean(argv[0], true); - struct sway_view *view = container->view; - view->tearing_mode = wants_tearing ? TEARING_OVERRIDE_TRUE : - TEARING_OVERRIDE_FALSE; + struct sway_view *view = container->view; + view->tearing_mode = wants_tearing ? TEARING_OVERRIDE_TRUE : + TEARING_OVERRIDE_FALSE; - return cmd_results_new(CMD_SUCCESS, NULL); + return cmd_results_new(CMD_SUCCESS, NULL); } diff --git a/sway/commands/output/allow_tearing.c b/sway/commands/output/allow_tearing.c index 18247c9df..268f9d633 100644 --- a/sway/commands/output/allow_tearing.c +++ b/sway/commands/output/allow_tearing.c @@ -3,20 +3,20 @@ #include "util.h" struct cmd_results *output_cmd_allow_tearing(int argc, char **argv) { - if (!config->handler_context.output_config) { + if (!config->handler_context.output_config) { return cmd_results_new(CMD_FAILURE, "Missing output config"); } if (argc == 0) { return cmd_results_new(CMD_INVALID, "Missing allow_tearing argument"); } - if (parse_boolean(argv[0], true)) { - config->handler_context.output_config->allow_tearing = 1; - } else { - config->handler_context.output_config->allow_tearing = 0; - } + if (parse_boolean(argv[0], true)) { + config->handler_context.output_config->allow_tearing = 1; + } else { + config->handler_context.output_config->allow_tearing = 0; + } - config->handler_context.leftovers.argc = argc - 1; - config->handler_context.leftovers.argv = argv + 1; - return NULL; + config->handler_context.leftovers.argc = argc - 1; + config->handler_context.leftovers.argv = argv + 1; + return NULL; } diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 9a2b0e264..f4dd09d31 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -299,19 +299,14 @@ static int output_repaint_timer_handler(void *data) { } } - if (output->can_tear) { + if (output->enable_tearing) { pending.tearing_page_flip = true; if (!wlr_output_test_state(output->wlr_output, &pending)) { - sway_log(SWAY_ERROR, "Output test failed on '%s', retrying without tearing page-flip", + sway_log(SWAY_DEBUG, "Output test failed on '%s', retrying without tearing page-flip", output->wlr_output->name); pending.tearing_page_flip = false; - - if (!wlr_output_test_state(output->wlr_output, &pending)) { - wlr_output_state_finish(&pending); - return 0; - } } } @@ -388,11 +383,11 @@ static void handle_frame(struct wl_listener *listener, void *user_data) { int delay = msec_until_refresh - output->max_render_time; struct sway_view *fullscreen_view = output_get_fullscreen_view(output); - output->can_tear = output_can_tear_fullscreen_view(output, fullscreen_view); + output->enable_tearing = output_can_tear_fullscreen_view(output, fullscreen_view); // 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->can_tear) { + if (delay < 1 || output->enable_tearing) { output_repaint_timer_handler(output); } else { output->wlr_output->frame_pending = true; diff --git a/sway/sway-output.5.scd b/sway/sway-output.5.scd index 523566775..42d8685db 100644 --- a/sway/sway-output.5.scd +++ b/sway/sway-output.5.scd @@ -191,17 +191,19 @@ must be separated by one space. For example: HDR support features. *output* allow_tearing yes|no - Allows or disallows screen tearing as a result of asynchronous page flips, - and an immediate presentation mode from a client. + Allows or disallows screen tearing as a result of immediate page flips, + and an immediate presentation mode from a client. The default is that no + screen tearing is allowed. - With asynchronous page flips, frames from the client are presented as soon + With immediate page flips, frames from the client are presented as soon as possible instead of synchronizing with the monitor's vblank interval - (VSync). This prevents stutter and reduces latency in games. + (VSync). To adjust whether tearing is allowed for specific applications, see - *allow_tearing* in *sway*(5). + *allow_tearing* in *sway*(5). Note that tearing will only be enabled + when it's allowed for both the output and the application. - This setting only has effect on fullscreen windows. + This setting only has effect when a window is fullscreen on the output. # SEE ALSO diff --git a/sway/sway.5.scd b/sway/sway.5.scd index db480fd9b..0b36a7572 100644 --- a/sway/sway.5.scd +++ b/sway/sway.5.scd @@ -216,7 +216,7 @@ set|plus|minus|toggle further details. *allow_tearing* yes|no - Allows or disallows screen tearing as a result of asynchronous page flips + Allows or disallows screen tearing as a result of immediate page flips for a fullscreen application. When this option is not set, the tearing hints provided by the application diff --git a/sway/tree/view.c b/sway/tree/view.c index 6c1242baa..423473879 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -1262,7 +1262,7 @@ bool view_is_transient_for(struct sway_view *child, } bool view_can_tear(struct sway_view *view) { - switch(view->tearing_mode) { + switch (view->tearing_mode) { case TEARING_OVERRIDE_FALSE: return false; case TEARING_OVERRIDE_TRUE: