The problem is that Ubuntu always resets the brightness level to maximum after every reboot. I installed the xbacklight
utility, but commands like xbacklight -get
or xbacklight -set XX
don't work. I get nothing as the output.
Actually, I would like to make my Ubuntu remember the level of brightness that was used last. How exactly can I do that? Here's some information:
ls -l /sys/class/backlight/
total 0
lrwxrwxrwx 1 root root 0 Feb 27 09:43 radeon_bl0 -> ../../devices/pci0000:00/0000:00:01.0/drm/card0/card0-LVDS-1/radeon_bl0
ls -l /sys/class/backlight/radeon_bl0/
total 0
-r--r--r-- 1 root root 4096 Feb 27 09:54 actual_brightness
-rw-r--r-- 1 root root 4096 Feb 27 09:54 bl_power
-rw-r--r-- 1 root root 4096 Feb 27 09:47 brightness
lrwxrwxrwx 1 root root 0 Feb 27 09:54 device -> ../../card0-LVDS-1
-r--r--r-- 1 root root 4096 Feb 27 09:43 max_brightness
drwxr-xr-x 2 root root 0 Feb 27 09:54 power
lrwxrwxrwx 1 root root 0 Feb 27 09:54 subsystem -> ../../../../../../../class/backlight
-r--r--r-- 1 root root 4096 Feb 27 09:43 type
-rw-r--r-- 1 root root 4096 Feb 27 09:42 uevent
uname -r
4.2.0-30-generic
Best Answer
Introduction
The script below addresses OP's need to store and restore screen brightness that was used last. It works in conjunction with
the lightdm
greeter and is activated bylightdm
. There's no requirement to uselightdm
, so if you prefer to use a cron job, you can do so.Basic idea:
/etc/lightdm/lightdm.conf
using thesudo
privilege.[SeatDefaults]
,display-setup-script
, anddisplay-stopped script
. Look below for details. Script header also gives overview.Script Source
Getting and Setting up the Script
You can either copy the script directly or follow these steps from the command line ( to open command line , press CtrlAltT )
The script will be located in
/opt/sergrep/brightness.sh
, so we do a:to make it executable. Next, we need to set it up to work with lightdm. Create the
/etc/lightdm/lightdm.conf
file , either by opening it with command linenano
text editor (the command issudo nano /etc/lightdm/lightdm.conf
) or graphicalgedit
(pkexec gedit /etc/lightdm/lightdm.conf
)Write to that file the following lines:
Save and exit
Indepth Overview
You've already discovered that you can write to
/sys/class/backlight/*/brightness
file directly , and you can also read in those values as well. Problem is that/sys
is a virtual filesystem, so once you reboot, all the files in that filesystem disappear.So you could store value in
/sys/class/backlight/*/actual_brightness
into a permanent file on every reboot. The question is how - via cron job, via lightdm, or via other means. Personally, I chose thelightdm
route.Basically we take advantage of lightdm's feature - being able to run a script before the greeter starts and after the session exits. The brightness is recorded to
/opt/.last_brightness
file and read from each time the script starts. We're essentially performing two actions with the same script, just by passing different arguments.