Brightness control doesn’t work in i3wm. Due to xbacklight

I’m very pleased with i3wm, but day by day I need to adjust something. At this time, on my new laptop the brightness hardware keys don’t work as expected.

The issue on the Lenovo Thinkpad with Fedora 26 is the same on the Acer ES1-111 with Ubuntu 17.04. At the bottom of i3wm, we found respectively the GNOME and the Unity windows manager. On both GNOME3 and Unity7, the hardware brightness keys work fine.

So, the problem is with i3wm only.

Light. A GNU/Linux application to control backlights
Light. A GNU/Linux application to control backlights

 

Many solutions. Changing the brightness

Looking into the infinite knowledge of Google, I found a lot of solutions.

The issue is set by the xbacklight command, I tested it and it doesn’t work also from a terminal session. So, the following lines don’t work.


# Screen brightness controls
bindsym XF86MonBrightnessUp exec xbacklight -inc 20 # increase screen brightness
bindsym XF86MonBrightnessDown exec xbacklight -dec 20 # decrease screen brightness

The most part of the solutions that I found, planned to make some scripts, changing the brightness with some bash commands:


$ sudo echo VALUE > /sys/class/backlight/intel_backlight/brightness

And save the script in some place, maybe in user bin folder or something in your PATH. Then, call the script from your i3wm .config file. To run the script, it needs super user (sudo) privileges and so you must just give it to the root user to launch it from the configuration file.

Anyway, I preferred a different approach. I found an alternative to xbacklight command, a GNU/Linux application to control backlights called simply light. You can find light over GitHub.

light is packed only for Arch Linux and you can found only packages for this distribution. Luckily, light is really lightweight and easy-easy to compile on every other distribution.

So, just download or clone the source of light:


$ git clone https://github.com/haikarainen/light.git

Compile and install it:


$ sudo make

$ sudo make install

On Fedora 26 and Ubuntu 17.04 all went fine. You can check it:


$ light --help

And, finally, replace the lines of code in the i3wm .config file:


# Screen brightness controls
# bindsym XF86MonBrightnessUp exec xbacklight -inc 20 # increase screen brightness
# bindsym XF86MonBrightnessDown exec xbacklight -dec 20 # decrease screen brightness
bindsym XF86MonBrightnessUp exec light -A 5 # increase screen brightness
bindsym XF86MonBrightnessDown exec light -U 5 # decrease screen brightness

Thanks to a user request in comments, if you also want to add notifications for brightness changing, you can do this:


# Screen brightness controls with notification
bindsym XF86MonBrightnessUp exec "light -A 5; notify-send 'brightness up'" # increase screen brightness with notification
bindsym XF86MonBrightnessDown exec "light -U 5; notify-send 'brightness down'" # decrease screen brightness with notification
  • Pingback: Links 27/4/2017: Mesa 17.0.5 RC1, Git 2.13.0 RC1, and Linkerd 1.0 | Techrights()

  • Bob Hepple

    So your problem was with xbacklight not with i3wm.

    I think you should rename your title to reflect that fact, it’s nothing to do with i3wm and anyone using other window manager eg fluxbox could be affected in the same way.

    • Thanks for comment, Bob. The title was explaining the problem affected me, not the cause. Anyway, I updated the title making it definitely more clear.

  • Sohaib Mahmood

    Thanks, worked like a charm!

    • Happy that it helped you.

  • The Global Elite

    Thank you so much, ive been lookin for this!

    • You’re welcome!

  • Saqib

    Thansk, worked!!!

    • Perfect. Thanks for feedback.

  • FrostyX

    Thank you for the blog post!
    After reading this, I’ve packaged the `light` tool for Fedora, so guys, you might install it with DNF.
    See https://copr.fedorainfracloud.org/coprs/frostyx/light/ and there is also a pending package reivew, so you might be able to install it directly from Fedora repositories soon.

    Read my blog post on this topic if you want http://frostyx.cz/posts/light-when-xbacklight-doesnt-work

    • Wow! This is fantastic, really nice work. Why don’t you write a post on how you made the fedora package of light? Thank you so much for all.

      • FrostyX

        > Why don’t you write a post on how you made the fedora package of light?
        Well, the packaging process is properly documented and there are tons of videos and posts how to do it, so I saw no point in describing the technical details of fedora packaging. If you are interested in it, I can point you to some resources that I consider most helpful and which are surely better, than I could write by myself.

        Also if you want to point for instance to light.spec file so you can package it for ubuntu or some other distro by looking on it as an example and use same values, I can, …

        • > I can point you to some resources that I consider most helpful and which are surely better, than I could write by myself.

          I asked because I found the way you explain things really helpful, anyway resources you used are appreciated. Also, I’m going to study your repository.

  • scorpion2782

    thank’s. works!! there are any solution to send notify when change brigthness, like volume? thank you

    • You could use notify-send. For example:

      # Screen brightness controls

      # bindsym XF86MonBrightnessUp exec “xbacklight -inc 10; notify-send ‘brightness up'”

      # bindsym XF86MonBrightnessDown exec “xbacklight -dec 10; notify-send ‘brightness down'”