The terminal app Lux allows you to set the screen brightness programmatically. You can use it from within XMonad as a workaround when
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?]