opened 07:08AM - 09 Apr 22 UTC
invalid
Hello. Keyboard backlight is not working out of the box.
I modified Giorgos Ker… amidas's script (https://keramida.wordpress.com/2013/03/28/controlling-the-keyboard-backlight-from-cli/) to handle a stepwise increase/decrease of the backlight.
Here the code:
```
#!/bin/sh
# backlight_get
# Print current keyboard brightness from UPower to stdout.
backlight_get()
{
dbus-send --type=method_call --print-reply=literal --system \
--dest='org.freedesktop.UPower' \
'/org/freedesktop/UPower/KbdBacklight' \
'org.freedesktop.UPower.KbdBacklight.GetBrightness' \
| awk '{print $2}'
}
# backlight_get_max
# Print the maximum keyboard brightness from UPower to stdout.
backlight_get_max()
{
dbus-send --type=method_call --print-reply=literal --system \
--dest='org.freedesktop.UPower' \
'/org/freedesktop/UPower/KbdBacklight' \
'org.freedesktop.UPower.KbdBacklight.GetMaxBrightness' \
| awk '{print $2}'
}
# backlight_set NUMBER
# Set the current backlight brighness to NUMBER, through UPower
backlight_set()
{
value="$1"
if test -z "${value}" ; then
echo "Invalid backlight value ${value}"
fi
dbus-send --type=method_call --print-reply=literal --system \
--dest='org.freedesktop.UPower' \
'/org/freedesktop/UPower/KbdBacklight' \
'org.freedesktop.UPower.KbdBacklight.SetBrightness' \
"int32:${value}}"
}
# backlight_change [ UP | DOWN | NUMBER ]
# Change the current backlight value upwards or downwards, or
# set it to a specific numeric value.
backlight_change()
{
change="$1"
if test -z "${change}" ; then
echo "Invalid backlight change ${change}." \
"Should be 'up' or 'down'." >&2
return 1
fi
case ${change} in
# AMST - manage increase and decrease
[+-][1234567890]|[[+-][[1234567890][[1234567890]|[[+-][[1234567890][[1234567890][[1234567890])
current=$( backlight_get )
max=$( backlight_get_max )
value=$( expr $((change)) + 0 )
current_and_value=$( expr ${current} + ${value})
if test ${current_and_value} -lt 0 ; then
current_and_value=0
elif test ${current_and_value} -gt ${max} ; then
current_and_value=${max}
fi
backlight_set "${current_and_value}"
notify-send -t 800 "Keyboard brightness set to ${current_and_value}"
;;
# AMST - manage max 3 digits input instead of only 2
# [1234567890]|[[1234567890][[1234567890])
[1234567890]|[[1234567890][[1234567890]|[[1234567890][[1234567890][[1234567890])
current=$( backlight_get )
max=$( backlight_get_max )
value=$( expr ${change} + 0 )
if test ${value} -lt 0 || test ${value} -gt ${max} ; then
echo "Invalid backlight value ${value}." \
"Should be a number between 0 .. ${max}" >&2
return 1
else
backlight_set "${value}"
notify-send -t 800 "Keyboard brightness set to ${value}"
fi
;;
[uU][pP])
current=$( backlight_get )
max=$( backlight_get_max )
if test "${current}" -lt "${max}" ; then
value=$(( ${current} + 1 ))
backlight_set "${value}"
notify-send -t 800 "Keyboard brightness set to ${value}"
fi
;;
[dD][oO][wW][nN])
current=$( backlight_get )
if test "${current}" -gt 0 ; then
value=$(( ${current} - 1 ))
backlight_set "${value}"
notify-send -t 800 "Keyboard brightness set to ${value}"
fi
;;
*)
echo "Invalid backlight change ${change}." >&2
echo "Should be 'up' or 'down' or a number between" \
"1 .. $( backlight_get_max )" >&2
return 1
;;
esac
}
if test $# -eq 0 ; then
current_brightness=$( backlight_get )
notify-send -t 800 "Keyboard brightness is ${current_brightness}"
else
# Handle multiple backlight changes, e.g.:
# backlight.sh up up down down up
for change in "$@" ; do
backlight_change "${change}"
done
fi
```
and here the config edited
```
# increase/decrease keyboard brightness
bindsym XF86KbdBrightnessUp exec backlight +25
bindsym XF86KbdBrightnessDown exec backlight down -25
```
Is this working?
And the more interesting question… is the default implementation not working for you?
Can’t say that I’ve tested it extensively, but I also did not notice it not working. Used it both on a MS Surface Book 1 (with the custom kernel) and a Dell XPS13.
1 Like
The default EnOS i3 config. Can’t recall touching the config regarding the keyboard backlight part .
2 Likes
Thanks for helping me with your info!
Never had any issues on the thinkpads, but I guess those are hardware controlled since i can change the brightness setting even during POST
1 Like
yes same as here only thinkpads… with hardware sided brightness controls…
1 Like
The problem here might be related to the fact that xorg-xbacklight
only works with Intel . Other drivers (e.g. Radeon ) did not add support for the RandR backlight property. I had discussed about this issue with @joekamprad about 2 months ago with my different account. See https://wiki.archlinux.org/title/backlight#xbacklight . I also recently did a fresh manjaro xfce install and faced some issues with it which were solved after making /etc/X11/xorg.conf.d/20-intel.conf
:
Section "Device"
Identifier "Intel Graphics"
Driver "intel"
Option "Backlight" "intel_backlight"
EndSection
The script provided by the github OP is unnecessarily complex. We can switch to brtightnessctl
as it works on both intel and amd:
1 Like
will need testers here as i can not test it on my hardware