From 00962426e424bd0e6cc9b5015df6ec0e2b5d2b26 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Wed, 6 Mar 2024 11:47:23 +0100 Subject: [PATCH 1/2] protocol: update wlr-output-management-unstable-v1 to minor version 5 --- .../wlr-output-management-unstable-v1.xml | 47 ++++++++++++++++--- 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/protocol/wlr-output-management-unstable-v1.xml b/protocol/wlr-output-management-unstable-v1.xml index 411e2f049..d42ceaef8 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. - + This interface is a manager that allows reading and writing the current output device configuration. @@ -125,7 +125,7 @@ - + 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 @@ -140,6 +140,11 @@ Properties sent via this interface are applied atomically via the wlr_output_manager.done event. No guarantees are made regarding the order in which properties are sent. + + The viewport indicates the logical size taken by the output in the global + compositor space. If the viewport aspect ratio doesn't match the current + mode aspect ratio, the compositor should letter-box the output with black + borders. @@ -225,7 +230,7 @@ - This events describes the position of the head in the global compositor + This event describes the position of the head in the global compositor space. It is only sent if the output is enabled. This events describes the scale of the head in the global compositor space. It is only sent if the output is enabled. + + Starting from version 5, this event is deprecated: the viewport event + should be used instead. @@ -354,9 +362,20 @@ + + + + + + This event describes the size of the head in the global compositor + space. It is only sent if the output is enabled. + + + + - + This object describes an output mode. @@ -411,7 +430,7 @@ - + This object is used by the client to describe a full output configuration. @@ -529,7 +548,7 @@ - + This object is used by the client to update a single head's configuration. @@ -544,6 +563,7 @@ + @@ -584,6 +604,9 @@ This request sets the head's scale. + + Starting from version 5, this request is deprecated: clients should use + set_viewport instead. @@ -597,5 +620,17 @@ + + + + + + This request sets the head's viewport. + + This overrides the set_scale request, if any was sent. + + + + From 03b0ad32b1f59d6f997fc23a0f8a53a967d6673b Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Wed, 6 Mar 2024 11:47:49 +0100 Subject: [PATCH 2/2] output-management-v1: add viewport --- include/wlr/types/wlr_output_management_v1.h | 2 +- types/wlr_output_management_v1.c | 41 ++++++++++++++++++-- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/include/wlr/types/wlr_output_management_v1.h b/include/wlr/types/wlr_output_management_v1.h index f1cd5ec54..54dd3a863 100644 --- a/include/wlr/types/wlr_output_management_v1.h +++ b/include/wlr/types/wlr_output_management_v1.h @@ -53,7 +53,7 @@ struct wlr_output_head_v1_state { int32_t width, height; int32_t refresh; } custom_mode; - int32_t x, y; + int32_t x, y, width, height; enum wl_output_transform transform; float scale; bool adaptive_sync_enabled; diff --git a/types/wlr_output_management_v1.c b/types/wlr_output_management_v1.c index b90d227e5..c5fce0659 100644 --- a/types/wlr_output_management_v1.c +++ b/types/wlr_output_management_v1.c @@ -5,7 +5,7 @@ #include #include "wlr-output-management-unstable-v1-protocol.h" -#define OUTPUT_MANAGER_VERSION 4 +#define OUTPUT_MANAGER_VERSION 5 enum { HEAD_STATE_ENABLED = 1 << 0, @@ -14,11 +14,12 @@ enum { HEAD_STATE_TRANSFORM = 1 << 3, HEAD_STATE_SCALE = 1 << 4, HEAD_STATE_ADAPTIVE_SYNC = 1 << 5, + HEAD_STATE_VIEWPORT = 1 << 6, }; static const uint32_t HEAD_STATE_ALL = HEAD_STATE_ENABLED | HEAD_STATE_MODE | 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; @@ -161,6 +162,8 @@ struct wlr_output_configuration_head_v1 * config_head->state.scale = output->scale; config_head->state.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; } @@ -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 = { .set_mode = config_head_handle_set_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_scale = config_head_handle_set_scale, .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) { @@ -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, struct wl_resource *head_resource, uint32_t state) { struct wl_client *client = wl_resource_get_client(head_resource); + uint32_t version = wl_resource_get_version(head_resource); if (state & 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) && - wl_resource_get_version(head_resource) >= - ZWLR_OUTPUT_HEAD_V1_ADAPTIVE_SYNC_SINCE_VERSION) { + version >= ZWLR_OUTPUT_HEAD_V1_ADAPTIVE_SYNC_SINCE_VERSION) { if (head->state.adaptive_sync_enabled) { zwlr_output_head_v1_send_adaptive_sync(head_resource, 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); } } + + 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) { @@ -905,6 +935,9 @@ static bool manager_update_head(struct wlr_output_manager_v1 *manager, if (current->adaptive_sync_enabled != next->adaptive_sync_enabled) { 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 // to the wlr_output_head