script to change brightness

auto-flake-update
Yorick van Pelt 2012-11-14 19:47:42 +01:00
parent f0e3e75bac
commit d824da840c
2 changed files with 106 additions and 1 deletions

View File

@ -278,7 +278,10 @@ globalkeys = awful.util.table.join(
-- Menubar
awful.key({ modkey }, "p", function() menubar.show() end),
-- locking
awful.key({ modkey, "Control" }, "l", function () awful.util.spawn("xscreensaver-command -lock") end)
awful.key({ modkey, "Control" }, "l", function () awful.util.spawn("xscreensaver-command -lock") end),
-- brightness adjustment
awful.key({ }, "XF86MonBrightnessDown", function() awful.util.spawn("/home/yorick/dotfiles/bin/brightne.sh down") end),
awful.key({ }, "XF86MonBrightnessUp", function() awful.util.spawn("/home/yorick/dotfiles/bin/brightne.sh up") end)
)
clientkeys = awful.util.table.join(

102
bin/brightne.sh Executable file
View File

@ -0,0 +1,102 @@
#!/bin/bash
# brightne.sh
# changes my backlight brightness, for use with nvidiabl
# possibly the ugliest bash script ever
# Requires /sys/class/backlight/nvidia_backlight/
E_NOARGS=75
backlight_path=/sys/class/backlight/nvidia_backlight
usage() {
echo "Usage: brightne.sh [set|fix|up|down] arg between 0 and 1024"
}
get_raw_maximum() {
return `cat $backlight_path/max_brightness`
}
get_raw_current() {
return `cat $backlight_path/brightness`
}
set_raw() {
echo $1 > $backlight_path/brightness
}
# from 0-1024 to 0-max
scale_to_bl() {
get_raw_maximum
max=$?
echo "$max * $1 / 1024" | bc
}
# from 0-max to 0-1024
scale_from_bl() {
get_raw_maximum
max=$?
echo "1024 * $1 / $max" | bc
}
off() {
set_raw 0;
}
max() {
get_raw_maximum
raw_current=$?
set_raw $raw_current
}
set_bl() {
set_raw $(scale_to_bl $1)
}
get() {
get_raw_current
echo $(scale_from_bl $?)
}
fix() {
get_raw_current
set_raw $?
}
up() {
local addvalue=$1
if [ -z $1 ]
then
addvalue=10
fi
set_bl $(echo "$(get) + $addvalue" | bc)
}
down() {
local addvalue=$1
if [ -z $1 ]
then
addvalue=10
fi
set_bl $(echo "$(get) - $addvalue" | bc)
}
if [ -z "$1" ]
then
usage
exit $E_NOARGS
fi
case $1 in
"up" ) up $2;;
"set" ) set_bl $2;;
"down" ) down $2;;
"fix" ) fix;;
"get" ) get;;
"off" ) off ;;
"max" ) max ;;
* ) usage;;
esac
exit 0