mirror of
https://github.com/freebsd/freebsd-src.git
synced 2026-10-28 11:25:21 +01:00
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 Differential Revision: https://reviews.freebsd.org/D59296
This commit is contained in:
1 parent
9930150214
commit
c45bdb39fe
6 files changed
+108
-2
No files matched your search
@@ -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.
|
||||
|
||||
@@ -11,6 +11,7 @@ CONFS= DAEMON \
|
||||
NETWORKING \
|
||||
SERVERS \
|
||||
adjkerntz \
|
||||
backlight \
|
||||
bgfsck \
|
||||
bridge \
|
||||
cfumass \
|
||||
|
||||
Executable
+88
@@ -0,0 +1,88 @@
|
||||
#!/bin/sh -
|
||||
#
|
||||
# Copyright (c) 2026 Kyle Evans <[email protected]>
|
||||
#
|
||||
# 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"
|
||||
Reference in new issue
Block a user