mirror of
https://github.com/swaywm/sway.git
synced 2024-11-25 09:21:28 +00:00
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.
This commit is contained in:
parent
9d0aa0cb83
commit
5d692b0581
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 },
|
||||
|
|
22
sway/commands/output/adaptive_sync.c
Normal file
22
sway/commands/output/adaptive_sync.c
Normal file
|
@ -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;
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue