From 2ff347955808a89b049204620d75e7dc440d4663 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Wed, 14 Sep 2022 11:56:01 +0200 Subject: [PATCH] output-management-v1: add wlr_output_configuration_v1_build_state() A convenience function to make it easier for compositors to implement the protocol. --- include/wlr/types/wlr_output_management_v1.h | 12 ++++++++++ types/wlr_output_management_v1.c | 23 ++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/include/wlr/types/wlr_output_management_v1.h b/include/wlr/types/wlr_output_management_v1.h index f1cd5ec5..57b880df 100644 --- a/include/wlr/types/wlr_output_management_v1.h +++ b/include/wlr/types/wlr_output_management_v1.h @@ -154,4 +154,16 @@ void wlr_output_head_v1_state_apply( const struct wlr_output_head_v1_state *head_state, struct wlr_output_state *output_state); +/** + * Build an array of struct wlr_output_state reflecting the new configuration. + * + * The states_len pointer will be populated with the number of elements in the + * array. The caller is responsible for freeing the array. + * + * The returned array can be passed to wlr_backend_test() and + * wlr_backend_commit(). + */ +struct wlr_backend_output_state *wlr_output_configuration_v1_build_state( + const struct wlr_output_configuration_v1 *config, size_t *states_len); + #endif diff --git a/types/wlr_output_management_v1.c b/types/wlr_output_management_v1.c index b90d227e..ecc32ded 100644 --- a/types/wlr_output_management_v1.c +++ b/types/wlr_output_management_v1.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include "wlr-output-management-unstable-v1-protocol.h" @@ -1027,3 +1028,25 @@ void wlr_output_head_v1_state_apply( wlr_output_state_set_adaptive_sync_enabled(output_state, head_state->adaptive_sync_enabled); } + +struct wlr_backend_output_state *wlr_output_configuration_v1_build_state( + const struct wlr_output_configuration_v1 *config, size_t *states_len) { + *states_len = wl_list_length(&config->heads); + struct wlr_backend_output_state *states = calloc(*states_len, sizeof(states[0])); + if (states == NULL) { + return NULL; + } + + size_t i = 0; + const struct wlr_output_configuration_head_v1 *config_head; + wl_list_for_each(config_head, &config->heads, link) { + struct wlr_backend_output_state *state = &states[i]; + i++; + + state->output = config_head->state.output; + wlr_output_state_init(&state->base); + wlr_output_head_v1_state_apply(&config_head->state, &state->base); + } + + return states; +}