Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Remember screen brightness
View unanswered posts
View posts from last 24 hours
View posts from last 7 days

 
Reply to topic    Gentoo Forums Forum Index Desktop Environments
View previous topic :: View next topic  
Author Message
raindev
n00b
n00b


Joined: 26 Dec 2017
Posts: 11
Location: Europe

PostPosted: Tue Jan 16, 2018 9:48 pm    Post subject: Remember screen brightness Reply with quote

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
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6227
Location: Room 101

PostPosted: Tue Jan 16, 2018 10:24 pm    Post subject: Reply with quote

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
View user's profile Send private message
raindev
n00b
n00b


Joined: 26 Dec 2017
Posts: 11
Location: Europe

PostPosted: Wed Jan 17, 2018 7:13 pm    Post subject: Almost there Reply with quote

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
View user's profile Send private message
raindev
n00b
n00b


Joined: 26 Dec 2017
Posts: 11
Location: Europe

PostPosted: Wed Jan 17, 2018 7:29 pm    Post subject: Some more details Reply with quote

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
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6227
Location: Room 101

PostPosted: Wed Jan 17, 2018 8:16 pm    Post subject: Re: Almost there Reply with quote

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
View user's profile Send private message
raindev
n00b
n00b


Joined: 26 Dec 2017
Posts: 11
Location: Europe

PostPosted: Sun Feb 04, 2018 6:01 pm    Post subject: Re: Almost there Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Desktop Environments All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum