Add gammarelay controls to eww bar

This commit is contained in:
ItsDrike 2023-01-26 01:31:19 +01:00
parent 0be14cd96a
commit 2d9a741ae0
No known key found for this signature in database
GPG key ID: B014E761034AF742
5 changed files with 139 additions and 0 deletions

View file

@ -0,0 +1,7 @@
.gammarelay {
.icon {
color: $peach;
margin-left: 2px;
margin-right: 2px;
}
}

View file

@ -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;

View file

@ -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)
))

View file

@ -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 "γ")
; ))
))

View file

@ -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