Isaac Freund: 1 Support output-management version 4 adaptive sync 2 files changed, 71 insertions(+), 6 deletions(-)
Copy & paste the following snippet into your terminal to import this patchset into git:
curl -s https://lists.sr.ht/~emersion/public-inbox/patches/35073/mbox | git am -3Learn more about email & git
--- main.c | 43 ++++++++++++++++++- .../wlr-output-management-unstable-v1.xml | 34 +++++++++++++-- 2 files changed, 71 insertions(+), 6 deletions(-) diff --git a/main.c b/main.c index 87f94af..6741c5e 100644 --- a/main.c +++ b/main.c @@ -42,6 +42,7 @@ struct randr_head { int32_t x, y; enum wl_output_transform transform; double scale; + enum zwlr_output_head_v1_adaptive_sync_state adaptive_sync_state; }; struct randr_state { @@ -115,6 +116,17 @@ static void print_state(struct randr_state *state) { printf(" Position: %d,%d\n", head->x, head->y); printf(" Transform: %s\n", output_transform_map[head->transform]); printf(" Scale: %f\n", head->scale); + + if (zwlr_output_manager_v1_get_version(state->output_manager) >= 4) { + switch (head->adaptive_sync_state) { + case ZWLR_OUTPUT_HEAD_V1_ADAPTIVE_SYNC_STATE_ENABLED: + printf(" Adaptive Sync: enabled\n"); + break; + case ZWLR_OUTPUT_HEAD_V1_ADAPTIVE_SYNC_STATE_DISABLED: + printf(" Adaptive Sync: disabled\n"); + break; + } + } } state->running = false; @@ -182,6 +194,11 @@ static void apply_state(struct randr_state *state, bool dry_run) { head->transform); zwlr_output_configuration_head_v1_set_scale(config_head, wl_fixed_from_double(head->scale)); + + if (zwlr_output_manager_v1_get_version(state->output_manager) >= 4) { + zwlr_output_configuration_head_v1_set_adaptive_sync(config_head, + head->adaptive_sync_state); + } } if (dry_run) { @@ -336,6 +353,12 @@ static void head_handle_serial_number(void *data, head->serial_number = strdup(serial_number); } +static void head_handle_adaptive_sync(void *data, + struct zwlr_output_head_v1 *wlr_head, uint32_t state) { + struct randr_head *head = data; + head->adaptive_sync_state = state; +} + static const struct zwlr_output_head_v1_listener head_listener = { .name = head_handle_name, .description = head_handle_description, @@ -350,6 +373,7 @@ static const struct zwlr_output_head_v1_listener head_listener = { .make = head_handle_make, .model = head_handle_model, .serial_number = head_handle_serial_number, + .adaptive_sync = head_handle_adaptive_sync, }; static void output_manager_handle_head(void *data, @@ -389,7 +413,7 @@ static void registry_handle_global(void *data, struct wl_registry *registry, struct randr_state *state = data; if (strcmp(interface, zwlr_output_manager_v1_interface.name) == 0) { - uint32_t version_to_bind = version <= 3 ? version : 3; + uint32_t version_to_bind = version <= 4 ? version : 4; state->output_manager = wl_registry_bind(registry, name, &zwlr_output_manager_v1_interface, version_to_bind); zwlr_output_manager_v1_add_listener(state->output_manager, @@ -420,6 +444,7 @@ static const struct option long_options[] = { {"pos", required_argument, 0, 0}, {"transform", required_argument, 0, 0}, {"scale", required_argument, 0, 0}, + {"adaptive-sync", required_argument, 0, 0}, {0}, }; @@ -611,6 +636,19 @@ static bool parse_output_arg(struct randr_head *head, } head->scale = scale; + } else if (strcmp(name, "adaptive-sync") == 0) { + if (zwlr_output_head_v1_get_version(head->wlr_head) < 4) { + fprintf(stderr, "setting adaptive sync not supported by the compositor\n"); + return false; + } + if (strcmp(value, "enabled") == 0) { + head->adaptive_sync_state = ZWLR_OUTPUT_HEAD_V1_ADAPTIVE_SYNC_STATE_ENABLED; + } else if (strcmp(value, "disabed") == 0) { + head->adaptive_sync_state = ZWLR_OUTPUT_HEAD_V1_ADAPTIVE_SYNC_STATE_DISABLED; + } else { + fprintf(stderr, "invalid adaptive sync state: %s\n", value); + return false; + } } else { fprintf(stderr, "invalid option: %s\n", name); return false; @@ -631,7 +669,8 @@ static const char usage[] = " --preferred\n" " --pos <x>,<y>\n" " --transform normal|90|180|270|flipped|flipped-90|flipped-180|flipped-270\n" - " --scale <factor>\n"; + " --scale <factor>\n" + " --adaptive-sync enabled|disabled\n"; int main(int argc, char *argv[]) { struct randr_state state = { .running = true }; diff --git a/protocol/wlr-output-management-unstable-v1.xml b/protocol/wlr-output-management-unstable-v1.xml index 3568e04..06f0a81 100644 --- a/protocol/wlr-output-management-unstable-v1.xml +++ b/protocol/wlr-output-management-unstable-v1.xml @@ -39,7 +39,7 @@ interface version number is reset. </description> - <interface name="zwlr_output_manager_v1" version="3"> + <interface name="zwlr_output_manager_v1" version="4"> <description summary="output device configuration manager"> This interface is a manager that allows reading and writing the current output device configuration. @@ -125,7 +125,7 @@ </event> </interface> - <interface name="zwlr_output_head_v1" version="3"> + <interface name="zwlr_output_head_v1" version="4"> <description summary="output device"> A head is an output device. The difference between a wl_output object and a head is that heads are advertised even if they are turned off. A head @@ -338,6 +338,22 @@ object. </description> </request> + + <!-- Version 4 additions --> + + <enum name="adaptive_sync_state" since="4"> + <entry name="enabled" value="0" summary="adaptive sync is enabled"/> + <entry name="disabled" value="1" summary="adaptive sync is disabled"/> + </enum> + + <event name="adaptive_sync" since="4"> + <description summary="current adaptive sync state"> + This event describes whether adaptive sync is currently enabled for + the head or not. Adaptive sync is also known as Variable Refresh + Rate or VRR. + </description> + <arg name="state" type="uint" enum="adaptive_sync_state"/> + </event> </interface> <interface name="zwlr_output_mode_v1" version="3"> @@ -395,7 +411,7 @@ </request> </interface> - <interface name="zwlr_output_configuration_v1" version="3"> + <interface name="zwlr_output_configuration_v1" version="4"> <description summary="output configuration"> This object is used by the client to describe a full output configuration. @@ -513,7 +529,7 @@ </request> </interface> - <interface name="zwlr_output_configuration_head_v1" version="3"> + <interface name="zwlr_output_configuration_head_v1" version="4"> <description summary="head configuration"> This object is used by the client to update a single head's configuration. @@ -569,5 +585,15 @@ </description> <arg name="scale" type="fixed"/> </request> + + <!-- Version 4 additions --> + + <request name="set_adaptive_sync" since="4"> + <description summary="enable/disable adaptive sync"> + This request enables/disables adaptive sync. Adaptive sync is also + known as Variable Refresh Rate or VRR. + </description> + <arg name="state" type="uint" enum="zwlr_output_head_v1.adaptive_sync_state"/> + </request> </interface> </protocol> -- 2.37.2