Skip to main content

Yet Another Brightness Daemon

Project description

yabd

Yet another brightness daemon

This is a simple (~300 lines of python) daemon that sets the brightness of the screen depending on ambient brightness. It was developed for my framework laptop on wayland / sway, but it should work with any system that

  1. uses systemd/dbus (with systemd-logind)
  2. has an ambient light sensor compatible with iio-sensor-proxy

Features:

  • Set brightness depending on ambient brightness sensor
  • dim screen with a dbus command (for use with swayidle or similar)
  • optionally ramps brightness up and down smoothly
  • Uses dbus interfaces systemd-logind (8) (to set brightness) and iio-sensor-proxy. This means it should be compatible with any window system / wayland / tty (though I have only tested it on sway).

Installation

This needs python3.10 or newer. It also needs iio-sensor-proxy to be installed, as well as pygobject and dbus-python

Arch linux

There is a PKGBUILD in the etc folder. You can install it with makepkg -si.

You will first need python-sdbus-git from the AUR (installable with your favourite AUR manager).

$ pikaur -S --asdeps python-sdbus-git # or your favourite AUR manager
$ cd etc
$ makepkg -si

With Pip

First install python3.10 or newer and iio-sensor-proxy through your package manager.

Then use pip to install yabd and its python dependencies:

$ pip install yabd

it will get installed in $site-packages/yabd.py

Optionally also install the systemd service file from this repo:

$ cp etc/yabd-installed-with-pip.service  ~/.config/systemd/user/yabd.service

Usage

systemd

The easiest way to use this is to use the provided systemd service file. To start the service once

$ systemctl --user start yabd

To start the service on login

$ systemctl --user enable yabd

To modify the options, edit the service file using

$ systemctl --user edit yabd

and modify the command line options in the [Service] section. The command line options are described below.

Command line

Running the daemon

To run the daemon manually, use the yabd run command:

$ yabd run --help
usage: yabd [-h] [--max-brightness MAX_BRIGHTNESS] [--min-brightness MIN_BRIGHTNESS]
            [--max-ambient-brightness MAX_AMBIENT_BRIGHTNESS] [--device DEVICE]
            [--subsystem SUBSYSTEM]
            [--change-to-get-control-back CHANGE_TO_GET_CONTROL_BACK]
            [--ramp | --no-ramp] [-v]

options:
  -h, --help            show this help message and exit
  --max-brightness MAX_BRIGHTNESS
                        max selectable brightness in percent (default: 100.0)
  --min-brightness MIN_BRIGHTNESS
                        min selectable brightness in percent (default: 5.0)
  --max-ambient-brightness MAX_AMBIENT_BRIGHTNESS
                        ambient brightness (in lumen) corresponding to the max
                        (default: 500.0)
  --device DEVICE       device to control (default intel_backlight)
  --subsystem SUBSYSTEM
                        subsystem to control (default backlight)
  --change-to-get-control-back CHANGE_TO_GET_CONTROL_BACK
                        how much the ambient brightness has to change to get control
                        back (default 100.0 lumen). If the screen brightness is changed
                        by another application, this daemon stops controlling it
                        temporarily. but if the ambient brightness changes more than
                        this amount, it takes control back. set to 0 to disable this
                        behaviour
  --ramp, --no-ramp     ramp brightness changes (default True) (default: True)
  -v, --verbose         enable logging

Changing the brightness

By changing the brightness directly

If another program changes the brightness (for example brightnessctl), the daemon will temporarily stop controlling the brightness.

If the ambient light changes more than a threshold (default 100 lumen), the daemon will take back control of the brightness.

This behaviour is configurable and can be disabled (see --change-to-get-control-back and --no-yield-control) although

  • If yielding control it is disabled, changes to the brightness may be immediately rolled back by the daemon.
  • If yielding control is enabled and the threshold is disabled, the daemon will stop doing anything if the brightness is changed by another program.

Thus for user control of the brightness, it is recommended to use the brightness multiplier instead (see below), or to keep the threshold to a reasonable value.

By changing the brightness multiplier

Otherwise, the user can change the brightness multiplier. This is a value that is originally equal to 100%, and that is multiplied to every brightness value that is set by the daemon.

Hence, when the user adds 10% to the brightness multiplier, the brightness will be 10% higher than what the daemon would have otherwise set it to.

This can be done with the following commands:

$ yabd change_multiplier -h
usage: yabd change_multiplier [-h] change

positional arguments:
  change      change the brightness multiplier by this amount (in percent)

options:
  -h, --help  show this help message and exit
$ yabd set_multiplier -h
usage: yabd set_multiplier [-h] new_multiplier

positional arguments:
  new_multiplier  set the brightness multiplier to this value (in percent)

options:
  -h, --help      show this help message and exit

for example

$ yabd change_multiplier +10 # increase the brightness by 10%. prints the new multiplier
110.0 
$ yabd set_multiplier 100 # set the multiplier back to 100%. prints the new multiplier
100.0 
Example sway config
bindsym XF86MonBrightnessUp exec "yabd change_multiplier +10"
bindsym XF86MonBrightnessDown exec "yabd change_multiplier -10"

Dimming the screen

This daemon allows the user to dim the screen via a remote command (via dbus). This is useful to dim the screen when the computer is idle.

Dimming / undimming the screen can be done with the following commands

$ yabd dim
$ yabd undim

it could also be done by calling directly the re.bruge.yabd dbus interface (if you want to do it programmatically)

$ gdbus call --session -d re.bruge.yabd -o /re/bruge/yabd -m re.bruge.yabd.dim
$ gdbus call --session -d re.bruge.yabd -o /re/bruge/yabd -m re.bruge.yabd.undim

For example, here is a sample swayidle config:

timeout 200 'yabd dim' resume 'yabd undim'
timeout 300 'swaymsg "output * dpms off"' resume 'swaymsg "output * dpms on"'

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yabd-0.2.2.tar.gz (14.3 kB view details)

Uploaded Source

Built Distribution

yabd-0.2.2-py3-none-any.whl (15.4 kB view details)

Uploaded Python 3

File details

Details for the file yabd-0.2.2.tar.gz.

File metadata

  • Download URL: yabd-0.2.2.tar.gz
  • Upload date:
  • Size: 14.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for yabd-0.2.2.tar.gz
Algorithm Hash digest
SHA256 a0d7042720731e38f93531dfca2e4bd712ac789fba8053b5ee23671058dfca9d
MD5 5baa1d9caec91bb49e19023e7e9891cd
BLAKE2b-256 03b9bd530083640f01883422b960d88d1a44963809c87de832a4f6a93d31665c

See more details on using hashes here.

File details

Details for the file yabd-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: yabd-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 15.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for yabd-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7b09db5541761de092a22ae05e3def615299ae3b0120f299cc9381f9862e0b86
MD5 a8c627a5eb8b72d2f1f80a7ba0bef952
BLAKE2b-256 c3a6cd0c5644d9b6c79ba86a68f88b1fc2c43d1ea743dedbfbfc894685522daf

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page