~emersion/public-inbox

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch

[PATCH wlr-randr v3] Support output-management version 3 adaptive sync

Details
Message ID
<20220706160232.32456-1-mail@isaacfreund.com>
DKIM signature
pass
Download raw message
Patch: +53 -1
---
 main.c                                        | 35 ++++++++++++++++++-
 .../wlr-output-management-unstable-v1.xml     | 19 ++++++++++
 2 files changed, 53 insertions(+), 1 deletion(-)

diff --git a/main.c b/main.c
index 87f94af..2d3b234 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;
	bool adaptive_sync_enabled;
};

struct randr_state {
@@ -115,6 +116,11 @@ 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) >= 3) {
			printf("  Adaptive Sync: %s\n",
				head->adaptive_sync_enabled ? "enabled" : "disabled");
		}
	}

	state->running = false;
@@ -182,6 +188,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) >= 3) {
			zwlr_output_configuration_head_v1_set_adaptive_sync(config_head,
				head->adaptive_sync_enabled);
		}
	}

	if (dry_run) {
@@ -336,6 +347,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, int32_t enabled) {
	struct randr_head *head = data;
	head->adaptive_sync_enabled = enabled != 0;
}

static const struct zwlr_output_head_v1_listener head_listener = {
	.name = head_handle_name,
	.description = head_handle_description,
@@ -350,6 +367,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,
@@ -420,6 +438,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 +630,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) < 3) {
			fprintf(stderr, "setting adaptive sync not supported by the compositor\n");
			return false;
		}
		if (strcmp(value, "enabled") == 0) {
			head->adaptive_sync_enabled = true;
		} else if (strcmp(value, "disabed") == 0) {
			head->adaptive_sync_enabled = false;
		} else {
			fprintf(stderr, "invalid adaptive sync state: %s\n", value);
			return false;
		}
	} else {
		fprintf(stderr, "invalid option: %s\n", name);
		return false;
@@ -631,7 +663,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..aa5c8af 100644
--- a/protocol/wlr-output-management-unstable-v1.xml
+++ b/protocol/wlr-output-management-unstable-v1.xml
@@ -338,6 +338,15 @@
        object.
      </description>
    </request>

    <event name="adaptive_sync" since="3">
      <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="enabled" type="int" summary="zero if disabled, non-zero if enabled"/>
    </event>
  </interface>

  <interface name="zwlr_output_mode_v1" version="3">
@@ -569,5 +578,15 @@
      </description>
      <arg name="scale" type="fixed"/>
    </request>

    <!-- Version 3 additions -->

    <request name="set_adaptive_sync" since="3">
      <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="enabled" type="int" summary="zero to disable, non-zero to enable"/>
    </request>
  </interface>
</protocol>
-- 
2.36.1
Reply to thread Export thread (mbox)