From 6688a3d9ea40aaf345945a2df8b67e0ca1fad00f Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Tue, 7 Jun 2022 18:54:42 +0200 Subject: [PATCH] output: add output state setters This ensures compositors don't forget to set the committed flag or the mode_type when setting a field. --- include/wlr/types/wlr_output.h | 17 +++++++++++ types/meson.build | 1 + types/output/state.c | 52 ++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 types/output/state.c diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h index d3d44132..4f8bff0d 100644 --- a/include/wlr/types/wlr_output.h +++ b/include/wlr/types/wlr_output.h @@ -501,6 +501,23 @@ bool wlr_output_cursor_move(struct wlr_output_cursor *cursor, void wlr_output_cursor_destroy(struct wlr_output_cursor *cursor); +void wlr_output_state_set_enabled(struct wlr_output_state *state, + bool enabled); +void wlr_output_state_set_mode(struct wlr_output_state *state, + struct wlr_output_mode *mode); +void wlr_output_state_set_custom_mode(struct wlr_output_state *state, + int32_t width, int32_t height, int32_t refresh); +void wlr_output_state_set_scale(struct wlr_output_state *state, float scale); +void wlr_output_state_set_transform(struct wlr_output_state *state, + enum wl_output_transform transform); +void wlr_output_state_set_adaptive_sync_enabled(struct wlr_output_state *state, + bool enabled); +void wlr_output_state_set_render_format(struct wlr_output_state *state, + uint32_t format); +void wlr_output_state_set_subpixel(struct wlr_output_state *state, + enum wl_output_subpixel subpixel); + + /** * Returns the transform that, when composed with `tr`, gives * `WL_OUTPUT_TRANSFORM_NORMAL`. diff --git a/types/meson.build b/types/meson.build index 2900561e..16870b83 100644 --- a/types/meson.build +++ b/types/meson.build @@ -6,6 +6,7 @@ wlr_files += files( 'output/cursor.c', 'output/output.c', 'output/render.c', + 'output/state.c', 'output/transform.c', 'scene/subsurface_tree.c', 'scene/surface.c', diff --git a/types/output/state.c b/types/output/state.c new file mode 100644 index 00000000..abfe5a64 --- /dev/null +++ b/types/output/state.c @@ -0,0 +1,52 @@ +#include "types/wlr_output.h" + +void wlr_output_state_set_enabled(struct wlr_output_state *state, + bool enabled) { + state->committed |= WLR_OUTPUT_STATE_ENABLED; + state->enabled = enabled; +} + +void wlr_output_state_set_mode(struct wlr_output_state *state, + struct wlr_output_mode *mode) { + state->committed |= WLR_OUTPUT_STATE_MODE; + state->mode_type = WLR_OUTPUT_STATE_MODE_FIXED; + state->mode = mode; +} + +void wlr_output_state_set_custom_mode(struct wlr_output_state *state, + int32_t width, int32_t height, int32_t refresh) { + state->committed |= WLR_OUTPUT_STATE_MODE; + state->mode_type = WLR_OUTPUT_STATE_MODE_CUSTOM; + state->custom_mode.width = width; + state->custom_mode.height = height; + state->custom_mode.refresh = refresh; +} + +void wlr_output_state_set_scale(struct wlr_output_state *state, float scale) { + state->committed |= WLR_OUTPUT_STATE_SCALE; + state->scale = scale; +} + +void wlr_output_state_set_transform(struct wlr_output_state *state, + enum wl_output_transform transform) { + state->committed |= WLR_OUTPUT_STATE_TRANSFORM; + state->transform = transform; +} + +void wlr_output_state_set_adaptive_sync_enabled(struct wlr_output_state *state, + bool enabled) { + state->committed |= WLR_OUTPUT_STATE_ADAPTIVE_SYNC_ENABLED; + state->adaptive_sync_enabled = enabled; +} + +void wlr_output_state_set_render_format(struct wlr_output_state *state, + uint32_t format) { + state->committed |= WLR_OUTPUT_STATE_RENDER_FORMAT; + state->render_format = format; +} + +void wlr_output_state_set_subpixel(struct wlr_output_state *state, + enum wl_output_subpixel subpixel) { + state->committed |= WLR_OUTPUT_STATE_SUBPIXEL; + state->subpixel = subpixel; +}