#!/bin/bash

declare -A id
declare -A horizontal
declare -A vertical
declare -A scale

generate() {
  
  	while read -r k h v s f; do
   		id[$k]="$k"
   		horizontal[$k]="$h"
   		vertical[$k]="$v"
   		scale[$k]="$s"
   	done < <(hyprctl monitors -j | jq -r '.[]|"\(.id) \(.width) \(.height) \(.scale)"')

  	echo -n '['

  	for ((i = 0; i < ${#id[@]}; i++)); do
    	echo -n ''$([ $i -eq 0 ] || echo ,)'{"id":"'$i'","width":"'${horizontal[$i]}'","height":"'${vertical[$i]}'",".scale":"'${scale[$i]}'"}'
  	done

  	echo ']'

}

generate

socat -u UNIX-CONNECT:/tmp/hypr/"$HYPRLAND_INSTANCE_SIGNATURE"/.socket2.sock - | while read -r line; do
  	if [[ ${line%>>*} == "monitor"* ]]; then
   		generate
   	fi
done

