sway

i3-compatible Wayland compositor
git clone https://git.awy.one/sway
Log | Files | Refs | README | LICENSE

commit 5d692b05811f939024fbf92c2e6eb7e66e0790dc
parent 9d0aa0cb839624265c366281922a58708a9bcb9a
Author: Simon Ser <contact@emersion.fr>
Date:   Mon,  2 Mar 2020 15:30:50 +0100

Add an adaptive_sync output command

This enables/disables adaptive synchronization on the output.

For now, the default is disabled because it might cause flickering on
some hardware if clients don't submit frames at regular enough
intervals. In the future an "auto" option will only enable adaptive sync
if a fullscreen client opts-in via a Wayland protocol.

Diffstat:
Minclude/sway/commands.h | 1+
Minclude/sway/config.h | 1+
Msway/commands/output.c | 1+
Asway/commands/output/adaptive_sync.c | 22++++++++++++++++++++++
Msway/config/output.c | 8++++++++
Msway/meson.build | 1+
Msway/sway-output.5.scd | 9+++++++++
7 files changed, 43 insertions(+), 0 deletions(-)

diff --git a/include/sway/commands.h b/include/sway/commands.h @@ -266,6 +266,7 @@ sway_cmd input_cmd_xkb_rules; sway_cmd input_cmd_xkb_switch_layout; sway_cmd input_cmd_xkb_variant; +sway_cmd output_cmd_adaptive_sync; sway_cmd output_cmd_background; sway_cmd output_cmd_disable; sway_cmd output_cmd_dpms; diff --git a/include/sway/config.h b/include/sway/config.h @@ -238,6 +238,7 @@ struct output_config { int32_t transform; enum wl_output_subpixel subpixel; int max_render_time; // In milliseconds + int adaptive_sync; char *background; char *background_option; diff --git a/sway/commands/output.c b/sway/commands/output.c @@ -7,6 +7,7 @@ // must be in order for the bsearch static struct cmd_handler output_handlers[] = { + { "adaptive_sync", output_cmd_adaptive_sync }, { "background", output_cmd_background }, { "bg", output_cmd_background }, { "disable", output_cmd_disable }, diff --git a/sway/commands/output/adaptive_sync.c b/sway/commands/output/adaptive_sync.c @@ -0,0 +1,22 @@ +#include "sway/commands.h" +#include "sway/config.h" +#include "util.h" + +struct cmd_results *output_cmd_adaptive_sync(int argc, char **argv) { + 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 adaptive_sync argument"); + } + + if (parse_boolean(argv[0], true)) { + config->handler_context.output_config->adaptive_sync = 1; + } else { + config->handler_context.output_config->adaptive_sync = 0; + } + + config->handler_context.leftovers.argc = argc - 1; + config->handler_context.leftovers.argv = argv + 1; + return NULL; +} diff --git a/sway/config/output.c b/sway/config/output.c @@ -64,6 +64,7 @@ struct output_config *new_output_config(const char *name) { oc->transform = -1; oc->subpixel = WL_OUTPUT_SUBPIXEL_UNKNOWN; oc->max_render_time = -1; + oc->adaptive_sync = -1; return oc; } @@ -104,6 +105,9 @@ void merge_output_config(struct output_config *dst, struct output_config *src) { if (src->max_render_time != -1) { dst->max_render_time = src->max_render_time; } + if (src->adaptive_sync != -1) { + dst->adaptive_sync = src->adaptive_sync; + } if (src->background) { free(dst->background); dst->background = strdup(src->background); @@ -390,6 +394,10 @@ bool apply_output_config(struct output_config *oc, struct sway_output *output) { wlr_output_set_scale(wlr_output, scale); } + if (oc && oc->adaptive_sync != -1) { + wlr_output_enable_adaptive_sync(wlr_output, oc->adaptive_sync == 1); + } + sway_log(SWAY_DEBUG, "Committing output %s", wlr_output->name); if (!wlr_output_commit(wlr_output)) { // Failed to modeset, maybe the output is missing a CRTC. Leave the diff --git a/sway/meson.build b/sway/meson.build @@ -175,6 +175,7 @@ sway_sources = files( 'commands/input/xkb_switch_layout.c', 'commands/input/xkb_variant.c', + 'commands/output/adaptive_sync.c', 'commands/output/background.c', 'commands/output/disable.c', 'commands/output/dpms.c', diff --git a/sway/sway-output.5.scd b/sway/sway-output.5.scd @@ -148,6 +148,15 @@ must be separated by one space. For example: optimal max_render_time value may vary based on the parent compositor rendering timings. +*output* <name> adaptive_sync on|off + Enables or disables adaptive synchronization (often referred to as Variable + Refresh Rate, or by the vendor-specific names FreeSync/G-Sync). + + Adaptive sync allows clients to submit frames a little to late without + having to wait a whole refresh period to display it on screen. Enabling + adaptive sync can improve latency, but can cause flickering on some + hardware. + # SEE ALSO *sway*(5) *sway-input*(5)