aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Simon Ser <contact@emersion.fr>2020-03-02 15:30:50 +0100
committerLibravatar Drew DeVault <sir@cmpwn.com>2020-03-07 00:32:04 +0100
commit5d692b05811f939024fbf92c2e6eb7e66e0790dc (patch)
treeadc2973635c6a189e10d444da6d42337131afcf9
parentUse wlr_client_buffer (diff)
downloadsway-5d692b05811f939024fbf92c2e6eb7e66e0790dc.tar.gz
sway-5d692b05811f939024fbf92c2e6eb7e66e0790dc.tar.zst
sway-5d692b05811f939024fbf92c2e6eb7e66e0790dc.zip
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.
-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;
266sway_cmd input_cmd_xkb_switch_layout; 266sway_cmd input_cmd_xkb_switch_layout;
267sway_cmd input_cmd_xkb_variant; 267sway_cmd input_cmd_xkb_variant;
268 268
269sway_cmd output_cmd_adaptive_sync;
269sway_cmd output_cmd_background; 270sway_cmd output_cmd_background;
270sway_cmd output_cmd_disable; 271sway_cmd output_cmd_disable;
271sway_cmd output_cmd_dpms; 272sway_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 {
238 int32_t transform; 238 int32_t transform;
239 enum wl_output_subpixel subpixel; 239 enum wl_output_subpixel subpixel;
240 int max_render_time; // In milliseconds 240 int max_render_time; // In milliseconds
241 int adaptive_sync;
241 242
242 char *background; 243 char *background;
243 char *background_option; 244 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 @@
7 7
8// must be in order for the bsearch 8// must be in order for the bsearch
9static struct cmd_handler output_handlers[] = { 9static struct cmd_handler output_handlers[] = {
10 { "adaptive_sync", output_cmd_adaptive_sync },
10 { "background", output_cmd_background }, 11 { "background", output_cmd_background },
11 { "bg", output_cmd_background }, 12 { "bg", output_cmd_background },
12 { "disable", output_cmd_disable }, 13 { "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 @@
1#include "sway/commands.h"
2#include "sway/config.h"
3#include "util.h"
4
5struct cmd_results *output_cmd_adaptive_sync(int argc, char **argv) {
6 if (!config->handler_context.output_config) {
7 return cmd_results_new(CMD_FAILURE, "Missing output config");
8 }
9 if (argc == 0) {
10 return cmd_results_new(CMD_INVALID, "Missing adaptive_sync argument");
11 }
12
13 if (parse_boolean(argv[0], true)) {
14 config->handler_context.output_config->adaptive_sync = 1;
15 } else {
16 config->handler_context.output_config->adaptive_sync = 0;
17 }
18
19 config->handler_context.leftovers.argc = argc - 1;
20 config->handler_context.leftovers.argv = argv + 1;
21 return NULL;
22}
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) {
64 oc->transform = -1; 64 oc->transform = -1;
65 oc->subpixel = WL_OUTPUT_SUBPIXEL_UNKNOWN; 65 oc->subpixel = WL_OUTPUT_SUBPIXEL_UNKNOWN;
66 oc->max_render_time = -1; 66 oc->max_render_time = -1;
67 oc->adaptive_sync = -1;
67 return oc; 68 return oc;
68} 69}
69 70
@@ -104,6 +105,9 @@ void merge_output_config(struct output_config *dst, struct output_config *src) {
104 if (src->max_render_time != -1) { 105 if (src->max_render_time != -1) {
105 dst->max_render_time = src->max_render_time; 106 dst->max_render_time = src->max_render_time;
106 } 107 }
108 if (src->adaptive_sync != -1) {
109 dst->adaptive_sync = src->adaptive_sync;
110 }
107 if (src->background) { 111 if (src->background) {
108 free(dst->background); 112 free(dst->background);
109 dst->background = strdup(src->background); 113 dst->background = strdup(src->background);
@@ -390,6 +394,10 @@ bool apply_output_config(struct output_config *oc, struct sway_output *output) {
390 wlr_output_set_scale(wlr_output, scale); 394 wlr_output_set_scale(wlr_output, scale);
391 } 395 }
392 396
397 if (oc && oc->adaptive_sync != -1) {
398 wlr_output_enable_adaptive_sync(wlr_output, oc->adaptive_sync == 1);
399 }
400
393 sway_log(SWAY_DEBUG, "Committing output %s", wlr_output->name); 401 sway_log(SWAY_DEBUG, "Committing output %s", wlr_output->name);
394 if (!wlr_output_commit(wlr_output)) { 402 if (!wlr_output_commit(wlr_output)) {
395 // Failed to modeset, maybe the output is missing a CRTC. Leave the 403 // 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(
175 'commands/input/xkb_switch_layout.c', 175 'commands/input/xkb_switch_layout.c',
176 'commands/input/xkb_variant.c', 176 'commands/input/xkb_variant.c',
177 177
178 'commands/output/adaptive_sync.c',
178 'commands/output/background.c', 179 'commands/output/background.c',
179 'commands/output/disable.c', 180 'commands/output/disable.c',
180 'commands/output/dpms.c', 181 '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:
148 optimal max_render_time value may vary based on the parent compositor 148 optimal max_render_time value may vary based on the parent compositor
149 rendering timings. 149 rendering timings.
150 150
151*output* <name> adaptive_sync on|off
152 Enables or disables adaptive synchronization (often referred to as Variable
153 Refresh Rate, or by the vendor-specific names FreeSync/G-Sync).
154
155 Adaptive sync allows clients to submit frames a little to late without
156 having to wait a whole refresh period to display it on screen. Enabling
157 adaptive sync can improve latency, but can cause flickering on some
158 hardware.
159
151# SEE ALSO 160# SEE ALSO
152 161
153*sway*(5) *sway-input*(5) 162*sway*(5) *sway-input*(5)