output-management-v1: add viewport

This commit is contained in:
Simon Ser 2024-03-06 11:47:49 +01:00
parent 00962426e4
commit 03b0ad32b1
2 changed files with 38 additions and 5 deletions

View file

@ -53,7 +53,7 @@ struct wlr_output_head_v1_state {
int32_t width, height; int32_t width, height;
int32_t refresh; int32_t refresh;
} custom_mode; } custom_mode;
int32_t x, y; int32_t x, y, width, height;
enum wl_output_transform transform; enum wl_output_transform transform;
float scale; float scale;
bool adaptive_sync_enabled; bool adaptive_sync_enabled;

View file

@ -5,7 +5,7 @@
#include <wlr/util/log.h> #include <wlr/util/log.h>
#include "wlr-output-management-unstable-v1-protocol.h" #include "wlr-output-management-unstable-v1-protocol.h"
#define OUTPUT_MANAGER_VERSION 4 #define OUTPUT_MANAGER_VERSION 5
enum { enum {
HEAD_STATE_ENABLED = 1 << 0, HEAD_STATE_ENABLED = 1 << 0,
@ -14,11 +14,12 @@ enum {
HEAD_STATE_TRANSFORM = 1 << 3, HEAD_STATE_TRANSFORM = 1 << 3,
HEAD_STATE_SCALE = 1 << 4, HEAD_STATE_SCALE = 1 << 4,
HEAD_STATE_ADAPTIVE_SYNC = 1 << 5, HEAD_STATE_ADAPTIVE_SYNC = 1 << 5,
HEAD_STATE_VIEWPORT = 1 << 6,
}; };
static const uint32_t HEAD_STATE_ALL = HEAD_STATE_ENABLED | HEAD_STATE_MODE | static const uint32_t HEAD_STATE_ALL = HEAD_STATE_ENABLED | HEAD_STATE_MODE |
HEAD_STATE_POSITION | HEAD_STATE_TRANSFORM | HEAD_STATE_SCALE | HEAD_STATE_POSITION | HEAD_STATE_TRANSFORM | HEAD_STATE_SCALE |
HEAD_STATE_ADAPTIVE_SYNC; HEAD_STATE_ADAPTIVE_SYNC | HEAD_STATE_VIEWPORT;
static const struct zwlr_output_head_v1_interface head_impl; static const struct zwlr_output_head_v1_interface head_impl;
@ -161,6 +162,8 @@ struct wlr_output_configuration_head_v1 *
config_head->state.scale = output->scale; config_head->state.scale = output->scale;
config_head->state.adaptive_sync_enabled = config_head->state.adaptive_sync_enabled =
output->adaptive_sync_status == WLR_OUTPUT_ADAPTIVE_SYNC_ENABLED; output->adaptive_sync_status == WLR_OUTPUT_ADAPTIVE_SYNC_ENABLED;
config_head->state.width = output->width * output->scale;
config_head->state.height = output->height * output->scale;
return config_head; return config_head;
} }
@ -307,6 +310,26 @@ static void config_head_handle_set_adaptive_sync(struct wl_client *client,
} }
} }
static void config_head_handle_set_viewport(struct wl_client *client,
struct wl_resource *config_head_resource,
int32_t width, int32_t height) {
struct wlr_output_configuration_head_v1 *config_head =
config_head_from_resource(config_head_resource);
if (config_head == NULL) {
return;
}
if (width <= 0 || height <= 0) {
wl_resource_post_error(config_head_resource,
ZWLR_OUTPUT_CONFIGURATION_HEAD_V1_ERROR_INVALID_VIEWPORT,
"invalid viewport");
return;
}
config_head->state.width = width;
config_head->state.height = height;
}
static const struct zwlr_output_configuration_head_v1_interface config_head_impl = { static const struct zwlr_output_configuration_head_v1_interface config_head_impl = {
.set_mode = config_head_handle_set_mode, .set_mode = config_head_handle_set_mode,
.set_custom_mode = config_head_handle_set_custom_mode, .set_custom_mode = config_head_handle_set_custom_mode,
@ -314,6 +337,7 @@ static const struct zwlr_output_configuration_head_v1_interface config_head_impl
.set_transform = config_head_handle_set_transform, .set_transform = config_head_handle_set_transform,
.set_scale = config_head_handle_set_scale, .set_scale = config_head_handle_set_scale,
.set_adaptive_sync = config_head_handle_set_adaptive_sync, .set_adaptive_sync = config_head_handle_set_adaptive_sync,
.set_viewport = config_head_handle_set_viewport,
}; };
static void config_head_handle_resource_destroy(struct wl_resource *resource) { static void config_head_handle_resource_destroy(struct wl_resource *resource) {
@ -746,6 +770,7 @@ static struct wl_resource *head_send_mode(struct wlr_output_head_v1 *head,
static void head_send_state(struct wlr_output_head_v1 *head, static void head_send_state(struct wlr_output_head_v1 *head,
struct wl_resource *head_resource, uint32_t state) { struct wl_resource *head_resource, uint32_t state) {
struct wl_client *client = wl_resource_get_client(head_resource); struct wl_client *client = wl_resource_get_client(head_resource);
uint32_t version = wl_resource_get_version(head_resource);
if (state & HEAD_STATE_ENABLED) { if (state & HEAD_STATE_ENABLED) {
zwlr_output_head_v1_send_enabled(head_resource, head->state.enabled); zwlr_output_head_v1_send_enabled(head_resource, head->state.enabled);
@ -799,8 +824,7 @@ static void head_send_state(struct wlr_output_head_v1 *head,
} }
if ((state & HEAD_STATE_ADAPTIVE_SYNC) && if ((state & HEAD_STATE_ADAPTIVE_SYNC) &&
wl_resource_get_version(head_resource) >= version >= ZWLR_OUTPUT_HEAD_V1_ADAPTIVE_SYNC_SINCE_VERSION) {
ZWLR_OUTPUT_HEAD_V1_ADAPTIVE_SYNC_SINCE_VERSION) {
if (head->state.adaptive_sync_enabled) { if (head->state.adaptive_sync_enabled) {
zwlr_output_head_v1_send_adaptive_sync(head_resource, zwlr_output_head_v1_send_adaptive_sync(head_resource,
ZWLR_OUTPUT_HEAD_V1_ADAPTIVE_SYNC_STATE_ENABLED); ZWLR_OUTPUT_HEAD_V1_ADAPTIVE_SYNC_STATE_ENABLED);
@ -809,6 +833,12 @@ static void head_send_state(struct wlr_output_head_v1 *head,
ZWLR_OUTPUT_HEAD_V1_ADAPTIVE_SYNC_STATE_DISABLED); ZWLR_OUTPUT_HEAD_V1_ADAPTIVE_SYNC_STATE_DISABLED);
} }
} }
if ((state & HEAD_STATE_VIEWPORT) &&
version >= ZWLR_OUTPUT_HEAD_V1_VIEWPORT_SINCE_VERSION) {
zwlr_output_head_v1_send_viewport(head_resource,
head->state.width, head->state.height);
}
} }
static void head_handle_resource_destroy(struct wl_resource *resource) { static void head_handle_resource_destroy(struct wl_resource *resource) {
@ -905,6 +935,9 @@ static bool manager_update_head(struct wlr_output_manager_v1 *manager,
if (current->adaptive_sync_enabled != next->adaptive_sync_enabled) { if (current->adaptive_sync_enabled != next->adaptive_sync_enabled) {
state |= HEAD_STATE_ADAPTIVE_SYNC; state |= HEAD_STATE_ADAPTIVE_SYNC;
} }
if (current->width != next->width || current->height != next->height) {
state |= HEAD_STATE_VIEWPORT;
}
// If a mode was added to wlr_output.modes we need to add the new mode // If a mode was added to wlr_output.modes we need to add the new mode
// to the wlr_output_head // to the wlr_output_head