aboutsummaryrefslogtreecommitdiff
path: root/sway
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2020-03-02 15:30:50 +0100
committerDrew DeVault <sir@cmpwn.com>2020-03-07 00:32:04 +0100
commit5d692b05811f939024fbf92c2e6eb7e66e0790dc (patch)
treeadc2973635c6a189e10d444da6d42337131afcf9 /sway
parent9d0aa0cb839624265c366281922a58708a9bcb9a (diff)
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 (limited to 'sway')
-rw-r--r--sway/commands/output.c1
-rw-r--r--sway/commands/output/adaptive_sync.c22
-rw-r--r--sway/config/output.c8
-rw-r--r--sway/meson.build1
-rw-r--r--sway/sway-output.5.scd9
5 files changed, 41 insertions, 0 deletions
diff --git a/sway/commands/output.c b/sway/commands/output.c
index 013f17b2..5186a2ba 100644
--- 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
new file mode 100644
index 00000000..7382e2ee
--- /dev/null
+++ 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
index 40f86b6e..cbcf713b 100644
--- 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
index 20fe02fb..6fdc4a7d 100644
--- 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
index 0f9fe208..b71e5744 100644
--- 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)