diff options
| author | Kyle Evans <kevans@FreeBSD.org> | 2026-09-02 03:51:41 +0000 |
|---|---|---|
| committer | Kyle Evans <kevans@FreeBSD.org> | 2026-10-24 01:17:41 +0000 |
| commit | 5245187af22b934ad10b82151f7f5a970140f283 (patch) | |
| tree | 98fe9f642f056cf4b189b146f29de21a6a67bd39 | |
| parent | 77f8982b5ecd8275a7ad577feae93ba9d5bc466f (diff) | |
rc: add a backlight service to save/restore backlight levels
The default on my laptop is annoyingly bright, and this is a useful
feature to mitigate that. The backlight script is largely a copy of the
mixer service which provides the same value for mixers, but this one is
specifically dependant on kld to allow DRM drivers a chance to attach.
Note that it's off by default to avoid interference with DEs, and
document the capability in backlight(8). Set backlight_enable=YES in
rc.conf(5) to enable save/restore.
Relnotes: maybe
Reviewed by: bapt, ivy, manu, ziaee
(cherry picked from commit c45bdb39fe985b43afc63b7cbd989fe7a61673b7)
| -rw-r--r-- | etc/mtree/BSD.var.dist | 2 | ||||
| -rw-r--r-- | libexec/rc/rc.conf | 1 | ||||
| -rw-r--r-- | libexec/rc/rc.d/Makefile | 1 | ||||
| -rwxr-xr-x | libexec/rc/rc.d/backlight | 88 | ||||
| -rw-r--r-- | share/man/man5/rc.conf.5 | 7 | ||||
| -rw-r--r-- | usr.bin/backlight/backlight.8 | 11 |
6 files changed, 108 insertions, 2 deletions
diff --git a/etc/mtree/BSD.var.dist b/etc/mtree/BSD.var.dist index b55c0150848e..2594067d1b4e 100644 --- a/etc/mtree/BSD.var.dist +++ b/etc/mtree/BSD.var.dist @@ -37,6 +37,8 @@ .. /set mode=0755 db + backlight tags=package=rc + .. entropy uname=operator gname=operator mode=0700 .. freebsd-update mode=0700 diff --git a/libexec/rc/rc.conf b/libexec/rc/rc.conf index d84922beb17d..fd8f315e12d8 100644 --- a/libexec/rc/rc.conf +++ b/libexec/rc/rc.conf @@ -42,6 +42,7 @@ always_force_depends="NO" # Set to check that indicated dependencies are apm_enable="NO" # Set to YES to enable APM BIOS functions (or NO). apmd_enable="NO" # Run apmd to handle APM event from userland. apmd_flags="" # Flags to apmd (if enabled). +backlight_enable="NO" # Save/restore backlight levels ddb_enable="NO" # Set to YES to load ddb scripts at boot. ddb_config="/etc/ddb.conf" # ddb(8) config file. devd_enable="YES" # Run devd, to trigger programs on device tree changes. diff --git a/libexec/rc/rc.d/Makefile b/libexec/rc/rc.d/Makefile index f6646208dc03..a84f3e04381e 100644 --- a/libexec/rc/rc.d/Makefile +++ b/libexec/rc/rc.d/Makefile @@ -11,6 +11,7 @@ CONFS= DAEMON \ NETWORKING \ SERVERS \ adjkerntz \ + backlight \ bgfsck \ bridge \ cfumass \ diff --git a/libexec/rc/rc.d/backlight b/libexec/rc/rc.d/backlight new file mode 100755 index 000000000000..6833f7b92aff --- /dev/null +++ b/libexec/rc/rc.d/backlight @@ -0,0 +1,88 @@ +#!/bin/sh - +# +# Copyright (c) 2026 Kyle Evans <kevans@FreeBSD.org> +# +# SPDX-License-Identifier: BSD-2-Clause +# + +# PROVIDE: backlight +# REQUIRE: FILESYSTEMS kld +# KEYWORD: nojail shutdown + +. /etc/rc.subr + +name="backlight" +desc="Save and restore backlight values" +rcvar="backlight_enable" +stop_cmd="backlight_stop" +start_cmd="backlight_start" +reload_cmd="backlight_start" +extra_commands="reload" + +backlightdb="/var/db/backlight" + +# +# List current backlight devices to stdout. +# +list_backlights() +{ + ( cd /dev/backlight ; ls backlight* 2>/dev/null ) +} + +# +# Save state of an individual backlight specified as $1 +# +backlight_save() +{ + local dev + + dev="/dev/backlight/$1" + if [ -r "$dev" ]; then + /usr/bin/backlight -f "$dev" -q > "$backlightdb/$1-state" 2>/dev/null + fi +} + +# +# Restore the state of an individual backlight specified as $1 +# +backlight_restore() +{ + local file dev + + dev="/dev/backlight/$1" + file="$backlightdb/$1-state" + if [ -r "$dev" -a -r "$file" ]; then + /usr/bin/backlight -f "$dev" $(cat "$file") > /dev/null + fi +} + +# +# Restore state of all backlights +# +backlight_start() +{ + local backlight + + for backlight in $(list_backlights); do + backlight_restore "$backlight" + done +} + +# +# Save the state of all backlights +# +backlight_stop() +{ + local backlight + + for backlight in $(list_backlights); do + backlight_save "$backlight" + done +} + +load_rc_config $name + +# doesn't make sense to run in a svcj: config setting +backlight_svcj="NO" + +run_rc_command "$1" diff --git a/share/man/man5/rc.conf.5 b/share/man/man5/rc.conf.5 index 8553984d5f21..bf8c1a1eed4b 100644 --- a/share/man/man5/rc.conf.5 +++ b/share/man/man5/rc.conf.5 @@ -25,7 +25,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd September 11, 2026 +.Dd October 22, 2026 .Dt RC.CONF 5 .Os .Sh NAME @@ -4438,6 +4438,11 @@ For example: autobridge_interfaces="bridge0" autobridge_bridge0="tap* dc0 vlan[345]" .Ed +.It Va backlight_enable +.Pq Vt bool +If set to +.Dq Li YES , +enable saving and restoring backlight levels at shutdown and boot time. .It Va mixer_enable .Pq Vt bool If set to diff --git a/usr.bin/backlight/backlight.8 b/usr.bin/backlight/backlight.8 index 25fa91c0060c..9021e05e5578 100644 --- a/usr.bin/backlight/backlight.8 +++ b/usr.bin/backlight/backlight.8 @@ -20,7 +20,7 @@ .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.Dd July 19, 2022 +.Dd September 1, 2026 .Dt BACKLIGHT 8 .Os .Sh NAME @@ -79,6 +79,15 @@ If no value is specified a default of 10 percent is used. Increment the backlight level. If no value is specified a default of 10 percent is used. .El +.Pp +Brightness levels may not be preserved across a reboot unless +.Va backlight_enable +is set to +.Dq Li YES +in +.Xr rc.conf 5 . +This is disabled by default to avoid intefering with desktop environments that +do their own backlight management. .Sh EXAMPLES Show the current brightness level: .Bd -literal -offset indent |
