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 $?
0And 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.
4 Answers
Following the instructions that I found on 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.confIn that file I put the following:
Section "Device" Identifier "card0" Driver "intel" Option "Backlight" "intel_backlight" BusID "PCI:0:2:0"
EndSectionAnd 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 10The 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.
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_deviceEvents
/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.shYou 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.)
1I found this, it might help :)
1The simplest solution github/particleofmass:
i3wm-backlight
Map your hot keys to increase or decrease the screen brightness in i3 wm. First install brightnessctl using:
sudo apt install brightnessctlPaste these lines in your i3 config file(
~/.config/i3/config):bindsym XF86MonBrightnessUp exec --no-startup-id brightnessctl set +5% bindsym XF86MonBrightnessDown exec --no-startup-id brightnessctl set 5%-
Note: I am the author of this code.
1