Setting the brightness in Awesome
Being able to change the luminosity of a screen is always something useful, to adjust it when there's more or less light, or even switching it off to keep a laptop processing. This usually works on it's own when we use an environment like KDE or Gnome, but it may not be like this if we don't use certain drivers or if we prefer more configurable environments (like awesome).
If we prefer to do it manually, we can do it through the command line in
/sys/class/backlight/
. In each devices directory there's a brightness
file that sets the current brightness (and that accepts changes), and
max_brightness
that shows the maximum accepted value, for example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
With this, we can set a script up to do it automatically, it should...
List the devices:
1 2 |
|
Show the current and max brightness:
1 2 3 4 5 6 7 |
|
Change the brightness:
1 2 3 |
|
Now we can program a couple of functions to make it more and less bright:
1 2 3 4 5 6 7 8 9 10 11 12 |
|
We add a help function, a main and ...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
And the script is ready [ brightness.py ],
but there's a problem... to change the brightness we need root privileges.
We can run the script with sudo
, but it's not needed if we use
setuid.
The trick about using setuid
with python is that scripts using a #!
interpreter are a security issue
and it's disabled on modern systems. The solution is to compile the script,
for example with cython
.
1 2 3 4 5 6 7 8 |
|
Notice that gcc doesn't require too many parameters because this program is simple, but it may not be like that. There's more complete Makefiles around.
Once compiled we can setuid
it as root:
1 2 3 4 5 |
|
And this should be done:
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Now we can modify it which any user from the console!
But, what if we have an Awesome windows environment and we want the brightness
keys to work? That is pretty easy now, in the rc.lua
file there's a
clientkeys
section, where we can configure it:
1 2 3 4 5 |
|
We're ready and able to set the brightness without any (more :P) extras.
PS: the code, to run make
and execute it it's available in GitLab.