Daemon for automatic management of keyboard and display brightness using applesmc light sensor (for Mac on Linux.)
When using litd, you take full responsibility for setting too large brightness values in config file and possibly damaging your display or keyboard or both.
Tested on Arch Linux (kernel 5.5.2-arch1-1), MacBook Pro (Retina, 15-inch, Mid 2015) (MacBookPro11,4)
litd has to run as you (to get your idle time properly)
If your system is not systemd based, you need to figure the permissions and auto start sections by yourself.
To use litd your system has to fulfill all of these criteria:
- Linux on a Mac.
- Libraries:
libXss
andlibX11
(for getting user idle time.) - Files (permissions):
/sys/devices/platform/applesmc.768/light
(o=r)/sys/class/backlight/intel_backlight/brightness
(o=rw)/sys/class/backlight/intel_backlight/max_brightness
(o=r)/sys/devices/platform/applesmc.768/leds/smc::kbd_backlight/brightness
(o=rw)/sys/devices/platform/applesmc.768/leds/smc::kbd_backlight/max_brightness
(o=r)
- GCC compiler.
ii) and iv) need rw
permissions which have to be set on every boot. If you use systemd, you can use the included brightness-perm.service
(how to use it is explained later in this guide.)
If your system fulfills all of these criteria, you can continue in this guide and use litd.
Clone this repo where you want to have litd installed.
Make sure you have rw
permissions on keyboard brightness file /sys/devices/platform/applesmc.768/leds/smc::kbd_backlight/brightness
and display brightness file /sys/class/backlight/intel_backlight/brightness
.
Permissions for keyboard and display brightness files need to be set on every boot. For this use units/brightness-perm.service
. Put it in /etc/systemd/system/
and enable it.
$ systemctl daemon-reload
$ systemctl enable --now brightness-perm.service
Compile litd
(probably into bin/
directory) like this:
$ mkdir bin
$ g++ litd.c xidle.c daemonize.c control.c config.c -O3 -lXss -lX11 -o bin/litd
To generate default config file, simply run ./litd
(where is config file located?)
Next you need to edit display_max
, display_min
, keyboard_max
and keyboard_min
values in config file.
See litd.conf for determining values of these settings.
Next edit units/litd.service
to point at your compiled executable, put it in $HOME/.config/systemd/user/
and enable it as user unit.
$ systemctl --user daemon-reload
$ systemctl --user enable --now litd.service
Make sure you keep the -d
option in your path (to start litd in daemon mode.)
Check that everything works.
litd has to run as you (to get your idle time properly)
-d
to run in daemon mode (litd.pid
file is located at the same location as config file)
$ ./litd -d
-v
to run in verbose mode (not allowed in daemon mode)
$ ./litd -v
litd creates its config file (and .pid file in daemon mode) in a directory named litd/
whose location is determined based on $XDG_HOME_DIRS
. If this variable does not exist or is empty, then default path $HOME/.config/
is used.
See litd.conf file for more info.
Sending signals to litd works only in daemon mode (litd -d
)
litd ignores sensor value for reset seconds if you adjust brightness manually. It does this seperately for keyboard and display. You can reset this by sending SIGUSR1
to litd.
$ kill -SIGUSR1 litd_pid
You can reload config by sending SIGHUP
to litd.
$ kill -SIGHUP litd_pid