From a108dda1be55febe3cabf2c2fb7c07826f28267c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Thu, 18 Dec 2025 14:04:23 +0100 Subject: [PATCH] led-multicolor: Scale to RGB colors to LEDs max brightness MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Otherwise we might exceed max brightness and get -EINVAL. Tested-by: Chris Vogel Reported-by: Chris Vogel Closes: https://gitlab.freedesktop.org/agx/feedbackd/-/issues/95 Signed-off-by: Guido Günther --- src/fbd-dev-led-multicolor.c | 13 +++++++++---- src/meson.build | 12 +++++++++++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/fbd-dev-led-multicolor.c b/src/fbd-dev-led-multicolor.c index 30d02c3..c9c4ee8 100644 --- a/src/fbd-dev-led-multicolor.c +++ b/src/fbd-dev-led-multicolor.c @@ -15,6 +15,8 @@ #include +#include + #define LED_MULTI_INDEX_ATTR "multi_index" #define LED_MULTI_INDEX_RED "red" #define LED_MULTI_INDEX_GREEN "green" @@ -132,11 +134,14 @@ fbd_dev_led_multicolor_set_color (FbdDevLed *led, colors[priv->green_index] = 0; colors[priv->blue_index] = max_brightness; break; - case FBD_FEEDBACK_LED_COLOR_RGB: - colors[priv->red_index] = rgb->r; - colors[priv->green_index] = rgb->g; - colors[priv->blue_index] = rgb->b; + case FBD_FEEDBACK_LED_COLOR_RGB: { + float scale = max_brightness / 255.0; + /* RGB colors are 0..255 so we need to scale to 0..max_brightness */ + colors[priv->red_index] = MIN (max_brightness, roundf (rgb->r * scale)); + colors[priv->green_index] = MIN (max_brightness, roundf (rgb->g * scale)); + colors[priv->blue_index] = MIN (max_brightness, roundf (rgb->b * scale)); break; + } default: g_warning("Unhandled color: %d\n", color); return FALSE; diff --git a/src/meson.build b/src/meson.build index 8459bee..fef2dc7 100644 --- a/src/meson.build +++ b/src/meson.build @@ -38,7 +38,17 @@ if get_option('daemon') 'fbd-udev.c', ] - fbd_deps = [gio, gio_unix, glib, gmobile, gobject, gsound, gudev, json_glib] + fbd_deps = [ + gio, + gio_unix, + glib, + gmobile, + gobject, + gsound, + gudev, + json_glib, + cc.find_library('m', required: false), + ] fbd_inc = [include_directories('.'), libfeedback_inc, dbus_inc]