/wluma

Automatic brightness adjustment based on screen contents and ALS

Primary LanguageRustISC LicenseISC

wluma

A tool for wlroots-based compositors that automatically adjusts screen brightness based on the screen contents and amount of ambient light around you.

Idea

The app will automatically brighten the screen when you are looking at a dark window (such as a fullscreen terminal) and darken the screen when you are looking at a bright window (such as web browser). The algorithm takes into consideration the amount of ambient light around you, so the same window can be brighter during the day than during the night.

With permission of Lumen's author (the project that inspired me to create this app), I'm reusing a demo GIF:

demo

Usage

Simply launch wluma and continue adjusting your screen brightness as you usually do - the app will learn your preferences.

Performance

The app has minimal impact on system resources and battery life even though it is able to monitor screen contents several times a second. This is achieved by using export-dmabuf Wayland protocol to get access to the screen contents and doing computations entirely on GPU using Vulkan API.

Installation

On Arch Linux you can use wluma or wluma-git packages.

Alternatively, download the release artifact (it is linked against latest available glibc and might not work on your machine) or build the app yourself, and then install it via sudo make install.

Build

CI

If you want to build the app yourself, make sure you use latest stable Rust, otherwise you might get compilation errors! Using rustup is perhaps the easiest.

Then simply run make build.

Permissions

In order to access backlight devices, wluma must either run as root, or preferrably instead you should add your user to video group (and possibly reboot thereafter).

Configuration

The config.toml in repository represents default config values. To change them, copy the file into $XDG_CONFIG_HOME/wluma/config.toml and adjust as desired.

ALS

Choose whether to use a real IIO-based ambient light sensor ([als.iio]), a time-based simulation ([als.time]) or disable it altogether ([als.none]).

[als.iio] contains a thresholds field, which comes with good default values. It is there to convert a generally exponential lux values into a linear scale to improve the prediction algorithm in wluma. A value of [100, 200] would mean that a raw lux value of 0..100 would get converted to 0, a value of 100..200 would get converted to 1, and 200+ would get converted to 2.

[als.time] contains a time_to_lux mapping, which allows you to express how bright or dark it gets as the day passes by. This mode is primarily meant to let people who don't have a real ALS to try the app and get some meaningful results. Use linear smooth lux values, not raw ones - a range of 0..5 is recommended. A mapping of { 3 = 1, 7 = 2, 21 = 0 } means that from 00:00 until 02:59 a value would be 0, from 03:00 until 06:59 the value would be 2, from 07:00 until 20:59 the value would be 2, and finally between 21:00 and 23:59 the value would again be 0.

Run

To run the app, simply launch wluma or use the provided systemd user service.

Known issues (help wanted!)

Help is wanted and much appreciated! If you want to implement some of these, feel free to open an issue and I'll provide more details and try to help you along the way.

  • Support for frames with custom DRM modifiers (e.g. multi-planar frames) is currently not implemented. This was recently implemented in mesa and can finally be added to wluma. Until then, a workaround is to export WLR_DRM_NO_MODIFIERS=1 before launching your wlroots-based compositor.
  • Changing screen resolution while wluma is running is not supported yet, and should crash the app. Workaround: restart wluma after changing resolution.
  • Selecting screen is not implemented yet, on start wluma will pick one screen at random and use it. If the screen disappears (e.g. you launch wluma on laptop, then connect a docking station and disable internal screen), it should crash the app. Workaround: restart wluma after changing screens.

Relevant projects

  • lumen: project that inspired me to create this app