The terminal app Lux allows you to set the screen brightness programmatically. You can use it from within XMonad as a workaround when FN function keys don’t work by default.

Install Lux on Linux

Run in a terminal

git clone https://github.com/Ventto/lux.git && \
cd lux && \
sudo make install && \
sudo lux

to install lux using git.

Afterwards run

lux

in your terminal to verify that lux is indeed installed. You should see a an output like this

/sys/class/backlight/intel_backlight 0;255;254

which gives you information about where your brightness settings are readable from.

Configure XMonad to use Lux

To actually use lux within XMonad, add these lines into the list of keymaps in your XMonad config file:

import Graphics.X11.ExtraTypes.XF86

myKeys = [
-- ...
  , ((0, xF86XK_MonBrightnessUp), spawn "lux -a 10%")
  , ((0, xF86XK_MonBrightnessDown), spawn "lux -s 10%")
-- ...
]

If you use the EZ keymap notation, use these lines:

myKeys = [
-- ...
  , ("<XF86MonBrightnessUp>", spawn "lux -a 10%")
  , ("<XF86MonBrightnessDown>", spawn "lux -s 10%")
-- ...
]
Explain the code
Code Note
import ... Make the functions and constants from a module available.
...XF86 Module that includes Haskell representations of multimedia keyboard keys.
xF86XK_MonBrightnessUp Haskell representation of the “Brightness up” multimedia keyboard key.
spawn ".." Run an app or script. You can run anything that you can run in a terminal.
"lux -a 10%" Increase/add brightness by 10%
"lux -s 10%" Decrease/substract brightness by 10%

You have to restart and recompile XMonad to take this new keyboard shortcut into account. You can do it by pressing Mod + q.
[How to configure XMonad?]
[How to modify XMonad keyboard shortcuts?]

Tags: xmonad lux ubuntu screen brightness haskell tutorial configuration

Malte Neuss

Java Software Engineer by day, Haskell enthusiast by night.

Other Posts In Series

Just Enough Haskell For XMonad

Configure a light-weight status bar for XMonad: Xmobar

The status bar Xmobar works out of the box on the top edge of your screen and shows useful system info. However, if you want to make it look nice and change what information to show, you can customize it with a tiny bit of Haskell.

Read More

Just Enough Haskell For XMonad

Control the audio volume in Ubuntu+XMonad with Alsa and PulseAudio

The terminal app Alsa allows you to audio volume programmatically. You can use it from within XMonad as a workaround when FN function keys don’t work by default.

Read More

Just Enough Haskell For XMonad

Replace XMonad's app launcher with a time-saving alternative: Yeganesh

The minimalistic app Yeganesh improves XMonad’s default app launcher with a small but time-saving feature: It shows your most frequently used apps first. So most of the time you will be able start an app by writing a single character.

Read More