integrated monitors.sh into kanshi

This commit is contained in:
willifan 2024-04-08 20:35:53 +02:00
parent 59b1b362e2
commit 93598400a3

View file

@ -1,76 +1,39 @@
#!/bin/bash #!/bin/bash
delay() { unset id name horizontal vertical scale activeWorkspace
timeout 2 socat -u UNIX-CONNECT:/tmp/hypr/"$HYPRLAND_INSTANCE_SIGNATURE"/.socket2.sock - | while read -r line; do i=0
if [[ ${line%>>*} == "monitor"* ]]; then
return
fi
done
generate while read -r k n h v s t; do
id[i]="$k"
} name[i]="$n"
horizontal[i]="$h"
generate() { vertical[i]="$v"
scale[i]="$s"
unset id name horizontal vertical scale activeWorkspace if [[ $((t%2)) == 1 ]]; then
i=0
while read -r k n h v s a t; do
id[$i]="$k"
name[$i]="$n"
horizontal[$i]="$h"
vertical[$i]="$v"
scale[$i]="$s"
activeWorkspace[$i]="$a"
if [[ $(($t%2)) == 1 ]]; then
temp=${vertical[$i]} temp=${vertical[$i]}
vertical[$i]=${horizontal[$i]} vertical[i]=${horizontal[$i]}
horizontal[$i]=$temp horizontal[i]=$temp
fi fi
((i=i+1)) ((i=i+1))
done < <(hyprctl monitors -j | jq -r '.[]|"\(.id) \(.name) \(.width) \(.height) \(.scale) \(.activeWorkspace.id) \(.transform)"') done < <(hyprctl monitors -j | jq -r '.[]|"\(.id) \(.name) \(.width) \(.height) \(.scale) \(.transform)"')
# if [[ $i > 1 ]]; then echo -n "" > "$XDG_CONFIG_HOME"/eww/bar.yuck
# displayMonitorID=true
# else
# displayMonitorID=false
# fi
echo -n "" > $XDG_CONFIG_HOME/eww/bar.yuck eww close-all
eww close-all sleep 2
sleep 2 for ((i = 0; i < ${#id[@]}; i++)); do
for ((i = 0; i < ${#id[@]}; i++)); do
scale_value=$(echo "${scale[$i]}" | bc -l) scale_value=$(echo "${scale[$i]}" | bc -l)
new_width_float=$(echo "(${horizontal[$i]} / ${scale_value}) -10" | bc) new_width_float=$(echo "(${horizontal[$i]} / ${scale_value}) -10" | bc)
new_height_float=$(echo "${vertical[$i]} / ${scale_value} * 0.03" | bc)
new_width=$(echo "$new_width_float / 1" | bc) new_width=$(echo "$new_width_float / 1" | bc)
new_height=$(echo "$new_height_float / 1" | bc)
monitorID=$(xrandr --listactivemonitors | grep +${name[$i]} | awk '{sub(/.$/,"",$1); print $1}') monitorID=$(xrandr --listactivemonitors | grep +"${name[$i]}" | awk '{sub(/.$/,"",$1); print $1}')
eww open bar --id bar${monitorID} --arg monitor=${monitorID} --arg width=${new_width} --arg height=25 eww open bar --id bar"${monitorID}" --arg monitor="${monitorID}" --arg width="${new_width}" --arg height=25
sleep 2 sleep 2
done
}
generate
socat -u UNIX-CONNECT:/tmp/hypr/"$HYPRLAND_INSTANCE_SIGNATURE"/.socket2.sock - | while read -r line; do
if [[ ${line%>>*} == "monitor"* ]]; then
delay &
fi
done done