View previous topic :: View next topic |
Author |
Message |
raindev n00b
Joined: 26 Dec 2017 Posts: 11 Location: Europe
|
Posted: Tue Jan 16, 2018 9:48 pm Post subject: Remember screen brightness |
|
|
What is the way to remember screen brightness across reboots when using OpenRC? I'm looking for something like systemd-backlight@.service (I don't expect it to be a part of OpenRC ) that would save the brightness value to disk and restore it during the boot.
I'm using Plasma desktop on a mid 2014 MacBook Pro with an integrated Intel i965 (Haswell) GPU. |
|
Back to top |
|
|
khayyam Watchman
Joined: 07 Jun 2012 Posts: 6227 Location: Room 101
|
Posted: Tue Jan 16, 2018 10:24 pm Post subject: |
|
|
raindev ...
something like:
/etc/local.d/backlight.stop: | #!/bin/sh
backlight_sys_dir="/sys/class/backlight/intel_backlight"
if [ ! -d /var/lib/backlight ] ; then
mkdir -p /var/lib/backlight
fi
cat ${backlight_sys_dir}/brightness > /var/lib/backlight/brightness |
/etc/local.d/backlight.start: | #!/bin/sh
backlight_sys_dir="/sys/class/backlight/intel_backlight"
if [ -f /var/lib/backlight/brightness ] ; then
cat /var/lib/backlight/brightness > ${backlight_sys_dir}/brightness
fi |
Code: | # chmod u+x /etc/local.d/backlight.* |
HTH & best ... khay |
|
Back to top |
|
|
raindev n00b
Joined: 26 Dec 2017 Posts: 11 Location: Europe
|
Posted: Wed Jan 17, 2018 7:13 pm Post subject: Almost there |
|
|
khayyam,
Thanks for your reply, I didn't know about /etc/local.d, it works great. Well, almost. While the brightness level is saved and restored properly (I debugged the values that get saved and restored) my brightness keys work as if the brightness was on maximum after booting. The media key to increase brightness doesn't work right after a reboot until I use the key to decrease brightness. But the key to decrease the brightness starts from the top so the brightness jumps from the saved value to the maximum first. Any ideas what might be going on? Is it Plasma trying to manage brightness not very successfully? |
|
Back to top |
|
|
raindev n00b
Joined: 26 Dec 2017 Posts: 11 Location: Europe
|
Posted: Wed Jan 17, 2018 7:29 pm Post subject: Some more details |
|
|
I have noticed that if I boot with remembered brightness and don't touch the brightness controls for couple of minutes it jumps to the maximum for some reason. On the other hand if in Energy Saving settings I enable a specific brightness level (e.g. for battery) that level will be applied when I boot into Plasma and override the value set in /etc/local.d (which makes sense). I guess I'll have to configure fixed brightness levels through Plasma settings to not have them jumping. |
|
Back to top |
|
|
khayyam Watchman
Joined: 07 Jun 2012 Posts: 6227 Location: Room 101
|
Posted: Wed Jan 17, 2018 8:16 pm Post subject: Re: Almost there |
|
|
raindev wrote: | Thanks for your reply, I didn't know about /etc/local.d, it works great. Well, almost. While the brightness level is saved and restored properly (I debugged the values that get saved and restored) my brightness keys work as if the brightness was on maximum after booting. The media key to increase brightness doesn't work right after a reboot until I use the key to decrease brightness. But the key to decrease the brightness starts from the top so the brightness jumps from the saved value to the maximum first. Any ideas what might be going on? Is it Plasma trying to manage brightness not very successfully? |
raindev ... you're welcome. If you're using plasma then all bets are off, I would expect it (or some component of the DE) to take full control of setting/restoring backlighting. Perhaps this only happens in relation to power (ie, diming the laptop display when on battery), I can't say, but you're probably only going to get whatever settings it provides via the control pannel (or whatever plasma calls it).
Anyhow, in terms of what seems to be happening I would suspect that this is the effect of where in the boot process /etc/local.d/backlight.start is run, 'local' (the service) is last in the default runlevel, and it's possible that your login manager starts before that. You could try having local start before xdm (or whatever it is you're using), eg:
/etc/rc.conf: | rc_xdm_after="local" |
If that isn't the cause then I can't think of anything else, other than perhaps disabling plasma from handling backlight, and relying on x11/acpid, to do so, eg:
/etc/acpid/default.sh: | case "$group" in
[...]
video)
case "$action" in
brightnessup) /etc/acpi/actions/backlight.sh up ;;
brightnessdown) /etc/acpi/actions/backlight.sh down ;; |
/etc/acpi/actions/backlight.sh: | #!/bin/sh
backlight_sys_dir="/sys/class/backlight/intel_backlight"
read -r max_brightness < "${backlight_sys_dir}/max_brightness"
read -r curr_brightness < "${backlight_sys_dir}/brightness"
case "$1" in
up) increment="+ 10" ;;
down) increment="- 10" ;;
*) exit 1 ;;
esac
new_brightness=$(($curr_brightness $increment))
if $((new_brightness < 1)) || $((new_brightness > $max_brightness)); then
exit 1
else
echo "$new_brightness" > ${backlight_sys_dir}/brightness
fi |
HTH & best ... khay |
|
Back to top |
|
|
raindev n00b
Joined: 26 Dec 2017 Posts: 11 Location: Europe
|
Posted: Sun Feb 04, 2018 6:01 pm Post subject: Re: Almost there |
|
|
khayyam wrote: | Anyhow, in terms of what seems to be happening I would suspect that this is the effect of where in the boot process /etc/local.d/backlight.start is run, 'local' (the service) is last in the default runlevel, and it's possible that your login manager starts before that. |
Here's my default runlevel (I'm not using parallel OpenRC service startup):
Code: | $ rc-status default
Runlevel: default
dbus [ started ]
sysklogd [ started ]
consolekit [ started ]
xdm [ started ]
cronie [ started ]
lvmetad [ started ]
net.wlp3s0 [ started ]
local [ started ]
|
So the scripts to modify brightness are run after Plasma is started (also the effect is possible to see when booting into the desktop).
I have discovered that when I modify brightness through /sys/class/backlight/intel_backlight/brightness Plasma brightness controls do not pick up the brightness levels properly. But when I use /sys/class/backlight/acpi_video0/brightness instead Plasma's brightness levels stay in sync. I have modified the local.d/ scripts to use acpi_video0 (and disabled setting of brightness level in Plasma Energy Saving settings). Now the brightness is saved and restored correctly and it doesn't mess up the Plasma brightness controls.
Thanks for all the help. |
|
Back to top |
|
|
|