#!/usr/bin/env bash


   
unset id name horizontal vertical scale activeWorkspace

i=0

while read -r k n h v s t; do
	id[i]="$k"
    name[i]="$n"
	horizontal[i]="$h"
	vertical[i]="$v"
	scale[i]="$s"
    if [[ $((t%2)) == 1 ]]; then
        temp=${vertical[$i]}
        vertical[i]=${horizontal[$i]}
        horizontal[i]=$temp
    fi
    ((i=i+1))
done < <(hyprctl monitors -j | jq -r '.[]|"\(.id) \(.name) \(.width) \(.height) \(.scale) \(.transform)"')

eww close-all --config ../eww

sleep 2

for ((i = 0; i < ${#id[@]}; i++)); do
  	scale_value=$(echo "${scale[$i]}" | bc -l)

    new_width_float=$(echo "(${horizontal[$i]} / ${scale_value}) -10" | bc)

    new_width=$(echo "$new_width_float / 1" | bc)

    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=30 --config ../eww
    sleep 2
done
