diff --git a/home/.config/eww/css/modules/_gammarelay.scss b/home/.config/eww/css/modules/_gammarelay.scss new file mode 100644 index 0000000..f62dcc8 --- /dev/null +++ b/home/.config/eww/css/modules/_gammarelay.scss @@ -0,0 +1,7 @@ +.gammarelay { + .icon { + color: $peach; + margin-left: 2px; + margin-right: 2px; + } +} diff --git a/home/.config/eww/eww.scss b/home/.config/eww/eww.scss index 18be4bf..cea8523 100644 --- a/home/.config/eww/eww.scss +++ b/home/.config/eww/eww.scss @@ -26,6 +26,7 @@ @import "css/modules/kernel"; @import "css/modules/battery"; @import "css/modules/workspaces"; +@import "css/modules/gammarelay"; .bar { background-color: $bg-a; diff --git a/home/.config/eww/eww.yuck b/home/.config/eww/eww.yuck index bd8c37b..311bf8d 100644 --- a/home/.config/eww/eww.yuck +++ b/home/.config/eww/eww.yuck @@ -10,6 +10,7 @@ ; (include "./modules/battery.yuck") (include "./modules/window_name.yuck") (include "./modules/workspaces.yuck") +(include "./modules/gammarelay.yuck") (include "./windows/calendar.yuck") @@ -20,6 +21,8 @@ (box :space-evenly false :halign "start" + (gammarelay_module) + (sep) (window_name_module) )) diff --git a/home/.config/eww/modules/gammarelay.yuck b/home/.config/eww/modules/gammarelay.yuck new file mode 100644 index 0000000..02ab78f --- /dev/null +++ b/home/.config/eww/modules/gammarelay.yuck @@ -0,0 +1,45 @@ +(deflisten temperature `scripts/gammarelay temperature watch`) +(deflisten brightness `scripts/gammarelay brightness watch`) +; (deflisten gamma `scripts/gammarelay gamma watch`) + +(defwidget gammarelay_module [] + (box + :class "module gammarelay" + + (eventbox + :onscroll "scripts/gammarelay temperature scroll {}" + :onclick "scripts/gammarelay temperature set toggle" + :onrightclick "scripts/gammarelay temperature set off" + :tooltip "${temperature} K" + :class "temperature" + (box + (label + :class "icon" + :text "") + )) + + (eventbox + :onscroll "scripts/gammarelay brightness scroll {}" + :onclick "scripts/gammarelay brightness set toggle" + :onrightclick "scripts/gammarelay brightness set off" + :tooltip "${brightness}%" + :class "brightness" + (box + (label + :class "icon" + :text "") + )) + + ; (eventbox + ; :onscroll "scripts/gammarelay gamma scroll {}" + ; :onclick "scripts/gammarelay gamma set toggle" + ; :onrightclick "scripts/gammarelay gamma set off" + ; :tooltip "${gamma}%" + ; :class "gamma" + ; :valign "top" + ; (box + ; (label + ; :class "icon" + ; :text "γ") + ; )) + )) diff --git a/home/.config/eww/scripts/gammarelay b/home/.config/eww/scripts/gammarelay new file mode 100755 index 0000000..08f6f11 --- /dev/null +++ b/home/.config/eww/scripts/gammarelay @@ -0,0 +1,83 @@ +#!/bin/bash + +if [ "$1" = "temperature" ]; then + 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 + 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 + 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 + >&2 echo "Invalid option, first argument must be one of: temperature, brightness, gamma" + exit 1 +fi + + +if [ "$2" = "watch" ]; then + exec wl-gammarelay-rs watch "$watch_cmd" + +elif [ "$2" = "get" ]; then + exec busctl --user get-property rs.wl-gammarelay / rs.wl.gammarelay "$set_cmd" | cut -d' ' -f2 + +elif [ "$2" = "scroll" ]; then + 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 + + exec busctl --user -- call rs.wl-gammarelay / rs.wl.gammarelay "$update_cmd" "$update_signature" ${sign}${scroll_change} + +elif [ "$2" = "set" ]; then + 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 + + 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 + >&2 echo "Invalid operation, second argument must be one of: watch, scroll, set" + exit 1 +fi