21

I would like to control the screen brightness in i3, in Intel laptops that come with Fn keys for the purpose. These keys function with any other DE.

First making sure devices available are Intel:

$ ls -l /sys/class/backlight/
total 0
lrwxrwxrwx 1 root root 0 juin  24 18:26 intel_backlight -> ../../devices/pci0000:00/0000:00:02.0/drm/card0/card0-eDP-1/intel_backlight

In another forum the programme xbacklight is suggested as means to control brightness in i3. However it fails in the laptops I tried so far:

$ xbacklight -inc 10
No outputs have backlight property

Is there any other way to control brightness in i3?

1

11 Answers 11

30

brightnessctl can be used to set the actual device brightness.

2
  • This is by far the easiest and most straightforward way I found. I am using i3 on Fedora (RedHat kernel) if it helps anyone. Although I think you should include a working snippet for guys in hurry :D Oct 31, 2021 at 19:55
  • brightnessctl set 20%- down and brightnessctl set +20% up (position of the - and + matter)
    – Dolph
    Jan 30, 2022 at 14:30
24

To change your screen brightness, you can use xrandr.

In order to do this, you can do:

xrandr -q | grep ' connected' | head -n 1 | cut -d ' ' -f1

That will return all the connected monitors (like LVDS-1 or DVI-D-0 for instance).

Now, to change the screen brightness do the command (replace the DVI-D-0 by the precedent command output):

xrandr --output DVI-D-0 --brightness 0.7

For instance, this command sets the brightness to 70%.

I hope it will help !

2
  • 10
    Note that it will only emulate screen brightness. Nov 29, 2019 at 7:15
  • 1
    To elaborate, changing the "brightness" with xrandr doesn't actually adjust the backlight brightness, it just adjusts the colours sent to the pixels. This makes the colours look awful at lower "brightnesses". Dec 12, 2020 at 6:30
14

My solution. It is tested on Ubuntu 20.04.

  1. sudo apt install light

  2. sudo chmod +s /usr/bin/light

  3. Add to i3 config:

    bindsym XF86MonBrightnessUp exec --no-startup-id light -A 1 # increase screen brightness
    bindsym XF86MonBrightnessDown exec --no-startup-id light -U 1 # decrease screen brightness

3
  • This also works on Debian, though the chmod is unnecessary since light uses udev rules now (though I did have to reboot for the rules to take effect). Aug 23, 2021 at 16:38
  • 2
    The chmod command was necessary on Ubuntu 21.10 running i3 Mar 18, 2022 at 9:25
  • important to note that light is an orphaned project and the github repo is now archived. see: github.com/haikarainen/light
    – Sami Fouad
    Jul 15, 2023 at 7:28
5

Copying from an old answer of mine to a question: XF86MonBrightnessUp/XF86MonBrightnessDown special keys not working


Edit: As noted below, you must have acpi installed on your machine for these to work :)

Edit 2: This code increments/decrements the brightness values by 1, but some models will have values that range in the thousands, so modify the change accordingly.

This is an old question, but an answer may help out others. I ran into an issue upon a fresh installation of i3wm on my laptop where, for whatever reason, my XF86MonBrightnessUp/Down keys weren't being registered (I checked with xev). What I ended up doing is creating acpi actions and events which corresponded to the keys being pressed.

The following are the actions/events I defined in /etc/acpi/actions and /etc/acpi/events, respectively:

Actions

/etc/acpi/actions/bl-down.sh

#!/bin/sh

bl_device=/sys/class/backlight/acpi_video0/brightness
echo $(($(cat $bl_device)-1)) | sudo tee $bl_device

/etc/acpi/actions/bl-up.sh

#!/bin/sh

bl_device=/sys/class/backlight/acpi_video0/brightness
echo $(($(cat $bl_device)+1)) | sudo tee $bl_device

Events

/etc/acpi/events/bl-down

event=video/brightnessdown BRTDN 00000087 00000000
action=/etc/acpi/actions/bl-down.sh

/etc/acpi/events/bl-up

event=video/brightnessup BRTUP 00000086 00000000
action=/etc/acpi/actions/bl-up.sh

You can verify your brightnessup/down acpi event codes by using acpi_listen in your terminal and then pressing the relevant key combination (e.g., for me, it's Fn + Down Arrow for brightness down).

Finally, don't forget to restart acpid with sudo /etc/init.d/acpid reload

Note: Your backlight device may be defined in a different location than /sys/class/backlight/acpi_video0 - that's just where mine happened to be. Do some poking around.

2
  • 1
    This was the answer that helped me! It'd be nice to mention, that you need acpi installed at the top :) Mar 17, 2020 at 22:53
  • 1
    Range for brightness on my machine is 0-24000, so $(( old_value - 1 )) doesn't quite do the job. Perhaps something like $(( old_value < step ? 0 : old_value - step )) makes more sense with appropriate step. Besides modern acpid reloads config on SIGHUP.
    – R. Matveev
    Jun 30, 2021 at 18:28
3

Using brightnessctl from @leafmeal's answer, I've added these keybindings to my .config/i3/config:

bindsym XF86MonBrightnessDown exec brightnessctl s 5%-
bindsym XF86MonBrightnessUp exec brightnessctl s +5%

Note: when you install brightnessctl, you might need to restart in order for it to work without sudo.

1
  • 'brightnessctrl' also works perfectly well on Arch with Sway, if anyone is interested. Mar 5, 2023 at 18:46
2

There's 2 xbacklight. In Archlinux (might be same in your distro), one comes in the package xorg-xbacklight sourced from https://xorg.freedesktop.org/ and the other is in the package acpilight sourced from https://gitlab.com/wavexx/acpilight. If one doesn't work, perhaps the other will.

The description for xorg-xbacklight says:

RandR-based backlight control application

And from the acpilight link:

On some modern laptops "XRandR" might lack the ability to set the display brightness. This capability was moved/unified to the kernel's ACPI interface, via /sys/class/backlight/. "acpilight" provides a drop-in replacement for the xbacklight command that uses the ACPI interface instead of "XRandR"

So, that might be the reason why your xbacklight doesn't work.

1
  • 1
    This is what I needed :) When searching for acpilight I have found this in the Arch wiki: wiki.archlinux.org/index.php/Backlight "xbacklight returns : No outputs have backlight property. Depending on the video card installed, sometimes xbacklight from xorg-xbacklight returns the message "No outputs have backlight property". Installing acpilight provides an alternative xbacklight that may work as expected."
    – fu7zed
    May 21, 2020 at 15:08
2

my current solution:

  1. get the default display (ex DVI-0)

    xrandr -q | grep " connected " | cut -d' ' -f1 | head -n 1

  2. add the following to ~/.config/i3/config replacing DVI-0 with whatever your display is

bindsym XF86MonBrightnessUp exec --no-startup-id bash -c 'b=$(xrandr --verbose | grep -i brightness | head -n 1 | cut -d" " -f2) && b2=$(echo -e "import math\nf = lambda x: (1 - 1/(1+math.exp(4*x-2)))\nprint(\\\"%.2f\\\" % f(0.1+$b))" | python) && xrandr --output DVI-0 --brightness $b2'

bindsym XF86MonBrightnessDown exec --no-startup-id bash -c 'b=$(xrandr --verbose | grep -i brightness | head -n 1 | cut -d" " -f2) && b2=$(echo -e "import math\nf = lambda x: (1 - 1/(1+math.exp(4*x-2)))\nprint(\\\"%.2f\\\" % f(-0.1+$b))" | python) && xrandr --output DVI-0 --brightness $b2'
1
  • That works, my laptop's default fn keys to control brightness are now functional, however, I noticed that the lower bound using this is much lower than what I use to get in gnome and the upper bound seems to be lower than the maximum I use to get in gnome too probably. I use arch btw and have started using i3 for less than a week so don't know much about that. Thanks.. Feb 3, 2023 at 18:21
0

Here is bash script solution based on xrandr: First create a file to store the current brightness value using echo 1.o > brightness.txt. Now the following bash script can be used:

#!/bin/bash

BRIGHT=`cat brightness.txt`

if [ "$1" = '+' ]; then
    NEWBRIGHT=$(echo "$BRIGHT + 0.05" | bc)
    if [ "$(echo "$NEWBRIGHT > 1.0" | bc)" -eq 1 ]; then
        NEWBRIGHT='1.0'
    fi
elif [ "$1" = '-' ]; then
    NEWBRIGHT=$(echo "$BRIGHT - 0.05" | bc)
    if [ "$(echo "$NEWBRIGHT < 0.0" | bc)" -eq 1 ]; then
        NEWBRIGHT='0.0'
    fi
fi

Suppose the above script is called brightness.sh then it can be used as:

.\brightness.sh + #to increase brightness
.\brightness.sh - #to decrease brightness

And since you use i3 you can bind keys to these commands. For example you can add these lines to to your i3-config:

# change brightness of screen
mode "controls" {
        # These bindings trigger as soon as you enter the control mode
        bindsym j exec "~/Scripts/brightness.sh -"
        bindsym k exec "~/Scripts/brightness.sh +"
        # back to normal: Enter or Escape
        bindsym Return mode "default"
        bindsym space mode "default"
}

bindsym $mod+shift+semicolon mode "controls"

Further add these line to your i3-config to start at the last-used brightness value:

exec "~/Scripts/brightness.sh -"
exec "~/Scripts/brightness.sh +"
0

The inspired_Blue answer is a good answer for using xrandr but it's inclomplete, I suggest to add theese lines at the end of the bash script to make it work:

echo $NEWBRIGHT > brightness.txt
xrandr --output LVDS-1 --brightness $NEWBRIGHT

be careful to check your display name with

xrandr -q | grep ' connected' | head -n 1 | cut -d ' ' -f1

as shown by Jae Beojkkoch. In my case the name is LVDS-1.

The first line rewrites the txt file using the new value of brightness, the second one is used to set the brightness using xrandr.

0

Install ddcutil .You might need to install i2c-tools first and run

 sudo modprobe i2c-dev

And add your username to i2c group:

sudo usermod -G i2c -a your_user

You can run:

sudo ddcutil capabilities

to see what can be controlled

And to increase/decrease backlight you can do:

sudo ddcutil setvcp 10 + 10
sudo ddcutil setvcp 10 - 10

respectively.

For more info on ddcutil I suggest you check the documentation at: https://www.ddcutil.com/command_setvcp/

0

A much simpler way to do this in Arch/Ubuntu systems is by making /usr/share/X11/xorg.conf.d/20-intel.conf with contents as follows:

Section "Device"
        Identifier  "card0"
        Driver      "intel"
        Option      "Backlight"  "intel_backlight"
        BusID       "PCI:0:2:0"
EndSection

then add these lines in your i3/config

bindsym XF86MonBrightnessUp exec xbacklight -inc 10
bindsym XF86MonBrightnessDown exec xbacklight -dec 10

This will make i3 use your keyboard brightness keys to control the brightness of your screen and you can even turn it all the way to 0 to make your screen black, and the brightness this solution gives at 100% is also quite good which I was unable to get through some other solutions.

This solution is inspired from Wayne Werner's answer.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .