How can I adjust the screen brightness in i3wm on Ubuntu 16.04?

10,714

Solution 1

Following the instructions that I found on https://itsfoss.com/fix-brightness-ubuntu-1310/ combined with what I already knew, that I had an Intel card, I did

sudo touch /usr/share/X11/xorg.conf.d/20-intel.conf
sudoedit /usr/share/X11/xorg.conf.d/20-intel.conf

In that file I put the following:

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

And now I can use xbacklight, as mreq mentions:

I added the following to my ~/.config/i3/config

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

The best part here is that I can actually turn my backlight all the way off, so if I wanted to use my computer as a dream journal like Adam Savage does, I totally could.

Solution 2

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.

I also wrote in a little function in my ~/.bashrc that let's me set the brightness from the terminal. My max brightness value is 24000, so I'm just multiplying a number from 0 to 10 by 2400. It's nice when I want to dim or brighten my screen instantly.

brs() {
    inp=$1
    echo $[inp * 2400] | sudo tee /sys/class/backlight/intel_backlight/brightness
}

(Also, out of curiosity, which System76 machine did you get, and how do you like it? I was considering buying one a while back.)

Solution 3

The simplest solution github/particleofmass:

i3wm-backlight

Map your hot keys to increase or decrease the screen brightness in i3 wm

sudo apt-get install brightnessctl

Paste these lines in your i3 config file(~/.config/i3/config)

bindsym XF86MonBrightnessUp exec brightnessctl -q set +5

bindsym XF86MonBrightnessDown exec brightnessctl -q set $(($(brightnessctl get)-5)) ```

Note: I am the author of this code.

Solution 4

I found this, it might help :)

https://itsfoss.com/fix-brightness-ubuntu-1310/

Share:
10,714

Related videos on Youtube

Wayne Werner
Author by

Wayne Werner

I'm a husband to my beautiful wife, father to our children, Computer Science graduate from University of Central Arkansas. I love my wife, our children, computers, playing guitar (especially singing/playing for my wife and/or kids), bicycling (including taking my kids for rides in my bike trailer), woodworking, airbrushing, digital and traditional artistry, playing games with my family (traditional and digital), my poor Chevette that I had to sell, throwing knives, firearms, knot tying, rope making, whip making, and really just learning new stuff in general. If I don't know about it I probably want to learn about it, if only so I can make informed decisions about it. My three favorite programming languages are Python, Lisp, and Assembly (though I'm not sure about the order of those last two languages...). I think the CANSPAM act is one of the dumbest pieces of legislation in the history of the universe I love Python and HTML+Javascript. I'm #SOreadytohelp (I really want a t-shirt, what can I say?)

Updated on September 18, 2022

Comments

  • Wayne Werner
    Wayne Werner over 1 year

    I'm running Ubuntu 16.04 on a System76 laptop. The brightness controls (i.e. Fn+F8 and Fn+F9) work great in Unity/Compiz/Gnome/whatever is default, but when I change to using i3wm instead I get... nothing.

    Under the default, xev reports something different. With i3 it reports XF86MonBrightnessUp and XF86MonBrightnessDown, which would be pretty cool if xbacklight worked, but it doesn't. It just has zero effect.

    wayne@waynego:~$ xbacklight -set 10
    wayne@waynego:~$ echo $?
    0
    

    And my monitor is still as bright/dark as it was before.

    The only thing that I've been able to get to work is this:

    sudo sh -c "cat /sys/class/backlight/intel_backlight/max_brightness > /sys/class/backlight/intel_backlight/brightness"
    

    Which you can probably agree is not ideal - cause I have to involve sudo, I mean I could gksudo or something but that's annoying, too. Clearly something works right with compiz/unity... I just don't know what it's doing.

    Is there some way to get xbacklight to work, or some alternative? I'd prefer not to have to run sudo to change my backlight settings.

  • Wayne Werner
    Wayne Werner over 5 years
    The Galaga pro. Only issues I had: battery life is garbage, some things didn't have the right scaling on the hidpi screen, and the touchpad didn't do palm rejection well/at all. Seriously it was like maybe 2h of battery life? Also I learned don't encrypt your home dir if you want to be able to hibernate.
  • Greenonline
    Greenonline about 3 years
    Please edit and expand upon your answer. At least describe what the solution does. If you are the author, as you indeed appear to be, then you need to disclose that fact, otherwise your post will come across as spam.
  • Random Person
    Random Person about 3 years
    Hey Samlinuxgeek! Links to external resources are encouraged, but please add context around the link so your fellow users will have some idea what it is and why it’s there. Always quote the most relevant part of an important link, in case the external resource is unreachable or goes permanently offline. Please go through this help center article: askubuntu.com/help/how-to-answer