#!/usr/bin/env bash

ws=7
classes=("kitty1" "kitty2" "kitty3" "kitty4")

for cls in "${classes[@]}"; do
  hyprctl keyword windowrulev2 "workspace $ws silent, class:^$cls$"
done

kitty --class kitty1 &
pid1=$!
while :; do
  addr1=$(hyprctl clients -j | jq -r ".[] | select(.pid==$pid1) | .address")
  [[ -n "$addr1" ]] && break
  sleep 0.1
done

hyprctl dispatch focuswindow address:$addr1
hyprctl dispatch split r
kitty --class kitty2 &
pid2=$!
while :; do
  addr2=$(hyprctl clients -j | jq -r ".[] | select(.pid==$pid2) | .address")
  [[ -n "$addr2" ]] && break
  sleep 0.1
done

hyprctl dispatch focuswindow address:$addr1
hyprctl dispatch split b
kitty --class kitty3 &
pid3=$!
while :; do
  addr3=$(hyprctl clients -j | jq -r ".[] | select(.pid==$pid3) | .address")
  [[ -n "$addr3" ]] && break
  sleep 0.1
done

hyprctl dispatch focuswindow address:$addr2
hyprctl dispatch split b
kitty --class kitty4 &
pid4=$!
while :; do
  addr4=$(hyprctl clients -j | jq -r ".[] | select(.pid==$pid4) | .address")
  [[ -n "$addr4" ]] && break
  sleep 0.1
done

for cls in "${classes[@]}"; do
  hyprctl keyword windowrulev2 "unset, class:^$cls$"
done
