Los botones del brillo no funcionan en Linux con una gráfica de Intel y i3 WM

Si estás usando i3 WM en Linux con una gráfica moderna de Intel, probablemente estés utilizando el driver de Mesa. En este caso el problema es que la orden «xbacklight«, que es la que utiliza el script por defecto, no te va a funcionar.

Yo estoy utilizando Endeavour OS con su configuración por defecto para i3 WM, y claro, me molestaba bastante no poder bajarle el brillo al portátil cuando no estaba conectado a la red eléctrica. La solución es cambiar la orden «xbacklight» por una llamada a «brightnessctl» equivalente.

Para ellos vamos a editar el archivos «~/.config/i3/scripts/volume_brightness.sh» y haremos los siguientes cambios:

--- volume_brightness-old.sh	2023-11-28 22:32:59.867716528 +0100
+++ volume_brightness.sh	2023-11-24 17:58:54.184428340 +0100
@@ -21,7 +21,10 @@
 
 # Uses regex to get brightness from xbacklight
 function get_brightness {
-    xbacklight | grep -Po '[0-9]{1,3}' | head -n 1
+    max=`brightnessctl m`
+    actual=`brightnessctl get`
+    echo $((actual*100/max))
 }
 
 # Returns a mute icon, a volume-low icon, or a volume-high icon, depending on the volume
@@ -84,13 +87,15 @@
 
     brightness_up)
     # Increases brightness and displays the notification
-    xbacklight -inc $brightness_step -time 0 
+    brightnessctl set +$brightness_step% 
     show_brightness_notif
     ;;
 
     brightness_down)
     # Decreases brightness and displays the notification
-    xbacklight -dec $brightness_step -time 0
+    brightnessctl set $brightness_step%- 
     show_brightness_notif
     ;;
 esac

Y lo tenemos. Ahora ya podemos subir y bajar el brillo sin problemas.