aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/sway/commands.h1
-rw-r--r--include/sway/config.h1
-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
7 files changed, 43 insertions, 0 deletions
diff --git a/include/sway/commands.h b/include/sway/commands.h
index f992b441..bbbdfc80 100644
--- 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
index aef6694d..0a2661dd 100644
--- 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
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)