From: Yu Watanabe Date: Tue, 2 Jan 2024 19:22:27 +0000 (+0900) Subject: backlight: supprt ID_LEDS_CLAMP udev property for leds subsystem devices X-Git-Tag: v256-rc1~1340 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=778823fd524c53a83d9a94eef1d7c1bd99293d31;p=thirdparty%2Fsystemd.git backlight: supprt ID_LEDS_CLAMP udev property for leds subsystem devices Closes #30507. --- diff --git a/man/systemd-backlight@.service.xml b/man/systemd-backlight@.service.xml index 59e01815f48..bb7f2b6b3e7 100644 --- a/man/systemd-backlight@.service.xml +++ b/man/systemd-backlight@.service.xml @@ -31,13 +31,22 @@ Description - systemd-backlight@.service is a service that restores the display backlight - brightness at early boot and saves it at shutdown. On disk, the backlight brightness is stored in - /var/lib/systemd/backlight/. During loading, if the udev property - is not set to false, the brightness is clamped to a value of at least - 1 or 5% of maximum brightness, whichever is greater. The percentage can be adjusted by specifying a - percentage (needs to be suffixed with %, e.g. 30%) to the property - . + systemd-backlight@.service is a service that restores the brightness of + a display backlight or LED (e.g. keyboard backlight) device at early boot, and saves it at shutdown. + The brightness is stored in /var/lib/systemd/backlight/. + + On restoring brightness of a display backlight device, systemd-backlight reads + ID_BACKLIGHT_CLAMP udev property, that takes a boolean value or a percentage (needs to + be suffixed with %, e.g. 30%). When a percentage is specified, the + saved brightness is clamped to a value of at least 1 or the specified percentage of the maximum + brightness, whichever is greater. When unset or set to true, the brightness is clamped in the same way + with percentage 5%. When false, the saved brightness will not be clamped, and loaded as is. + + On restoring brightness of a LED device, systemd-backlight reads + ID_LEDS_CLAMP udev property, that also takes a boolean value or a percentage. When a + percentage is specified, the saved brightness is clamped to the specified percentage of the maximum + brightness. When set to true, the brightness is clamped in the same way with percentage 5%. When unset or + set to false, the saved brightness will not be clamped, and loaded as is. diff --git a/src/backlight/backlight.c b/src/backlight/backlight.c index 5aa3e332b66..6a2ad17fbf6 100644 --- a/src/backlight/backlight.c +++ b/src/backlight/backlight.c @@ -338,10 +338,9 @@ static int clamp_brightness( * avoids preserving an unreadably dim screen, which would otherwise force the user to disable * state restoration. */ + min_brightness = (unsigned) ((double) max_brightness * percent / 100); if (device_in_subsystem(device, "backlight")) - min_brightness = MAX(1U, (unsigned) ((double) max_brightness * percent / 100)); - else - min_brightness = 0; + min_brightness = MAX(1U, min_brightness); new_brightness = CLAMP(*brightness, min_brightness, max_brightness); if (new_brightness != *brightness) @@ -356,19 +355,28 @@ static int clamp_brightness( return 0; } -static bool shall_clamp(sd_device *d, unsigned *ret) { - const char *s; +static bool shall_clamp(sd_device *device, unsigned *ret) { + const char *property, *s; + unsigned default_percent; int r; - assert(d); + assert(device); assert(ret); - r = sd_device_get_property_value(d, "ID_BACKLIGHT_CLAMP", &s); + if (device_in_subsystem(device, "backlight")) { + property = "ID_BACKLIGHT_CLAMP"; + default_percent = 5; + } else { + property = "ID_LEDS_CLAMP"; + default_percent = 0; + } + + r = sd_device_get_property_value(device, property, &s); if (r < 0) { if (r != -ENOENT) - log_device_debug_errno(d, r, "Failed to get ID_BACKLIGHT_CLAMP property, ignoring: %m"); - *ret = 5; /* defaults to 5% */ - return true; + log_device_debug_errno(device, r, "Failed to get %s property, ignoring: %m", property); + *ret = default_percent; + return default_percent > 0; } r = parse_boolean(s); @@ -379,9 +387,9 @@ static bool shall_clamp(sd_device *d, unsigned *ret) { r = parse_percent(s); if (r < 0) { - log_device_debug_errno(d, r, "Failed to parse ID_BACKLIGHT_CLAMP property, ignoring: %m"); - *ret = 5; - return true; + log_device_debug_errno(device, r, "Failed to parse %s property, ignoring: %m", property); + *ret = default_percent; + return default_percent > 0; } *ret = r;