From 82d2cc7c234393beaea5d3cf30957e0dd4594b05 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Fri, 29 May 2026 16:55:37 +0200 Subject: [PATCH] output: add brightness state --- include/wlr/types/wlr_output.h | 8 ++++++++ types/output/output.c | 16 ++++++++++++++++ types/output/state.c | 5 +++++ 3 files changed, 29 insertions(+) diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h index c8e44b0e6..ca3ed90e3 100644 --- a/include/wlr/types/wlr_output.h +++ b/include/wlr/types/wlr_output.h @@ -78,6 +78,7 @@ enum wlr_output_state_field { WLR_OUTPUT_STATE_COLOR_TRANSFORM = 1 << 12, WLR_OUTPUT_STATE_IMAGE_DESCRIPTION = 1 << 13, WLR_OUTPUT_STATE_COLOR_REPRESENTATION = 1 << 14, + WLR_OUTPUT_STATE_BRIGHTNESS = 1 << 15, }; enum wlr_output_state_mode_type { @@ -165,6 +166,8 @@ struct wlr_output_state { struct wlr_color_transform *color_transform; struct wlr_output_image_description *image_description; + + float brightness; }; struct wlr_output_impl; @@ -213,11 +216,14 @@ struct wlr_output { enum wlr_color_encoding color_encoding; enum wlr_color_range color_range; const struct wlr_output_image_description *image_description; + float brightness; // Indicates whether making changes to adaptive sync status is supported. // If false, changes to adaptive sync status is guaranteed to fail. If // true, changes may either succeed or fail. bool adaptive_sync_supported; + // Indicates whether brightness changes are supported. + bool brightness_supported; bool needs_frame; // damage for cursors and fullscreen surface, in output-local coordinates @@ -632,6 +638,8 @@ void wlr_output_state_set_color_transform(struct wlr_output_state *state, bool wlr_output_state_set_image_description(struct wlr_output_state *state, const struct wlr_output_image_description *image_desc); +void wlr_output_state_set_brightness(struct wlr_output_state *state, float value); + /** * Set the color encoding and range of the primary scanout buffer. * diff --git a/types/output/output.c b/types/output/output.c index 46da1f425..273cbfed3 100644 --- a/types/output/output.c +++ b/types/output/output.c @@ -261,6 +261,10 @@ static void output_apply_state(struct wlr_output *output, } } + if (state->committed & WLR_OUTPUT_STATE_BRIGHTNESS) { + output->brightness = state->brightness; + } + bool geometry_updated = state->committed & (WLR_OUTPUT_STATE_MODE | WLR_OUTPUT_STATE_TRANSFORM | WLR_OUTPUT_STATE_SUBPIXEL); @@ -359,6 +363,7 @@ void wlr_output_init(struct wlr_output *output, struct wlr_backend *backend, .render_format = DRM_FORMAT_XRGB8888, .transform = WL_OUTPUT_TRANSFORM_NORMAL, .scale = 1, + .brightness = 1, .commit_seq = 0, }; @@ -590,6 +595,10 @@ static uint32_t output_compare_state(struct wlr_output *output, output->color_range == state->color_range) { fields |= WLR_OUTPUT_STATE_COLOR_REPRESENTATION; } + if ((state->committed & WLR_OUTPUT_STATE_BRIGHTNESS) && + output->brightness == state->brightness) { + fields |= WLR_OUTPUT_STATE_BRIGHTNESS; + } return fields; } @@ -687,6 +696,7 @@ static bool output_basic_test(struct wlr_output *output, { WLR_OUTPUT_STATE_SUBPIXEL, "subpixel" }, { WLR_OUTPUT_STATE_COLOR_TRANSFORM, "color transform" }, { WLR_OUTPUT_STATE_IMAGE_DESCRIPTION, "image description" }, + { WLR_OUTPUT_STATE_BRIGHTNESS, "brightness" }, }; if (!enabled) { for (size_t i = 0; i < sizeof(needs_enabled) / sizeof(needs_enabled[0]); i++) { @@ -726,6 +736,12 @@ static bool output_basic_test(struct wlr_output *output, } } + if ((state->committed & WLR_OUTPUT_STATE_BRIGHTNESS) && + !output->brightness_supported) { + wlr_log(WLR_DEBUG, "Brightness is not supported for this output"); + return false; + } + return true; } diff --git a/types/output/state.c b/types/output/state.c index 5f44c18e8..f62f3ab87 100644 --- a/types/output/state.c +++ b/types/output/state.c @@ -149,6 +149,11 @@ void wlr_output_state_set_color_encoding_and_range( state->color_range = range; } +void wlr_output_state_set_brightness(struct wlr_output_state *state, float value) { + state->committed |= WLR_OUTPUT_STATE_BRIGHTNESS; + state->brightness = value; +} + bool wlr_output_state_copy(struct wlr_output_state *dst, const struct wlr_output_state *src) { struct wlr_output_state copy = *src;