nixdots/home/programs/graphical/bars/eww/config/scripts/gammarelay

83 lines
2 KiB
Plaintext
Raw Permalink Normal View History

2024-06-20 12:53:31 +00:00
#!/usr/bin/env bash
if [ "$1" = "temperature" ]; then
2024-06-20 12:53:31 +00:00
watch_cmd="{t}"
update_cmd="UpdateTemperature"
update_signature="n"
set_cmd="Temperature"
set_signature="q"
default_val=6500
click_val=4500
scroll_change=100
cmp_op="<"
elif [ "$1" = "brightness" ]; then
2024-06-20 12:53:31 +00:00
watch_cmd="{bp}"
update_cmd="UpdateBrightness"
update_signature="d"
set_cmd="Brightness"
set_signature="d"
default_val=1
click_val=0.8
scroll_change=0.02
cmp_op="<"
elif [ "$1" = "gamma" ]; then
2024-06-20 12:53:31 +00:00
watch_cmd="{g}"
update_cmd="UpdateGamma"
update_signature="d"
set_cmd="Gamma"
set_signature="d"
default_val=1
click_val=1.1
scroll_change=0.02
cmp_op=">"
else
2024-06-20 12:53:31 +00:00
>&2 echo "Invalid option, first argument must be one of: temperature, brightness, gamma"
exit 1
fi
if [ "$2" = "watch" ]; then
2024-06-20 12:53:31 +00:00
exec wl-gammarelay-rs watch "$watch_cmd"
elif [ "$2" = "get" ]; then
2024-06-20 12:53:31 +00:00
exec busctl --user get-property rs.wl-gammarelay / rs.wl.gammarelay "$set_cmd" | cut -d' ' -f2
elif [ "$2" = "scroll" ]; then
2024-06-20 12:53:31 +00:00
if [ "$3" = "up" ]; then
sign="+"
elif [ "$3" = "down" ]; then
sign="-"
else
>&2 echo "Invalid sign, second argument must be one of: up, down"
exit 1
fi
2024-06-20 12:53:31 +00:00
exec busctl --user -- call rs.wl-gammarelay / rs.wl.gammarelay "$update_cmd" "$update_signature" ${sign}${scroll_change}
elif [ "$2" = "set" ]; then
2024-06-20 12:53:31 +00:00
mode="$3"
if [ "$mode" = "toggle" ]; then
cur_val="$(busctl --user get-property rs.wl-gammarelay / rs.wl.gammarelay "$set_cmd" | cut -d' ' -f2)"
if [ "$(echo "$cur_val $cmp_op $default_val" | bc -l)" = "1" ]; then
mode="off"
else
mode="on"
fi
fi
2024-06-20 12:53:31 +00:00
if [ "$mode" = "on" ]; then
exec busctl --user -- set-property rs.wl-gammarelay / rs.wl.gammarelay "$set_cmd" "$set_signature" "$click_val"
elif [ "$mode" = "off" ]; then
exec busctl --user -- set-property rs.wl-gammarelay / rs.wl.gammarelay "$set_cmd" "$set_signature" "$default_val"
else
>&2 echo "Invalid mode, third argument, must be one of: toggle, on, off"
exit 1
fi
else
2024-06-20 12:53:31 +00:00
>&2 echo "Invalid operation, second argument must be one of: watch, scroll, set"
exit 1
fi