brightness script
This commit is contained in:
parent
95158c40ab
commit
9a2053ff3d
modules/profiles/desktop
46
modules/profiles/desktop/brightness
Executable file
46
modules/profiles/desktop/brightness
Executable file
@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# This is a shell "application", but doesn't have to be one, so
|
||||
# leaving the shebang in place.
|
||||
set -euo pipefail
|
||||
|
||||
dir=$(find /sys/devices/ -name intel_backlight | head -1)
|
||||
if [[ -z "$dir" ]]; then
|
||||
echo "intel_backlight not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
max=$(cat "$dir/max_brightness")
|
||||
now=$(cat "$dir/brightness")
|
||||
step=$((max * 3 / 100))
|
||||
min=100
|
||||
|
||||
clamp() {
|
||||
if [[ $1 -gt $max ]]; then
|
||||
echo "$max"
|
||||
elif [[ $1 -lt $min ]]; then
|
||||
echo "$min"
|
||||
else
|
||||
echo "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
info() {
|
||||
perc="$(echo "$1*100/$max" | bc -l)"
|
||||
printf "%s of %s (%.2f%%)\n" "$1" "$max" "$perc"
|
||||
}
|
||||
|
||||
new=
|
||||
case "${1:-}" in
|
||||
up)
|
||||
new=$(clamp $((now + step)) ) ;;
|
||||
down)
|
||||
new=$(clamp $((now - step)) ) ;;
|
||||
esac
|
||||
|
||||
if [[ -n "$new" ]]; then
|
||||
echo "$new" | sudo tee "$dir/brightness" > /dev/null
|
||||
info "$new"
|
||||
else
|
||||
info "$now"
|
||||
fi
|
@ -8,6 +8,10 @@ let
|
||||
inherit (config.mj) username;
|
||||
firefox =
|
||||
if (pkgs.stdenv.hostPlatform.system == "x86_64-linux") then pkgs.firefox-bin else pkgs.firefox;
|
||||
brightness = pkgs.writeShellApplication {
|
||||
name = "brightness";
|
||||
text = builtins.readFile ./brightness;
|
||||
};
|
||||
in
|
||||
{
|
||||
imports = [ ../dev ];
|
||||
@ -134,6 +138,7 @@ in
|
||||
# packages defined here
|
||||
nicer
|
||||
tmuxbash
|
||||
brightness
|
||||
|
||||
f3 # flight-flash-fraud
|
||||
iw
|
||||
|
@ -278,6 +278,16 @@ globalkeys = gears.table.join(
|
||||
xclip -selection clipboard -target image/png -i $f'
|
||||
]])
|
||||
end),
|
||||
awful.key({}, "XF86MonBrightnessDown", function()
|
||||
awful.spawn.easy_async_with_shell("brightness down", function(stdout)
|
||||
naughty.notify({text = stdout, timeout = 1})
|
||||
end)
|
||||
end),
|
||||
awful.key({}, "XF86MonBrightnessUp", function()
|
||||
awful.spawn.easy_async_with_shell("brightness up", function(stdout)
|
||||
naughty.notify({text = stdout, timeout = 1})
|
||||
end)
|
||||
end),
|
||||
awful.key({ modkey, }, "Left", awful.tag.viewprev,
|
||||
{description = "view previous", group = "tag"}),
|
||||
awful.key({ modkey, }, "Right", awful.tag.viewnext,
|
||||
|
Loading…
Reference in New Issue
Block a user