#!/bin/bash
set -e

# Toggle the tiling layout between Hyprland's two built-in layouts, dwindle
# and master. (The old version read `.tiledLayout` off `hyprctl
# activeworkspace -j` and switched to "scrolling" — but that field doesn't
# exist, so the read was always null, and "scrolling" isn't a real layout
# (`hyprctl layouts` only lists dwindle/master), so the toggle silently
# did nothing.)

CURRENT_LAYOUT=$(hyprctl getoption general:layout -j | jq -r '.str')

case "$CURRENT_LAYOUT" in
  dwindle) NEW_LAYOUT=master ;;
  *) NEW_LAYOUT=dwindle ;;
esac

hyprctl keyword general:layout "$NEW_LAYOUT"
notify-send -u low "󱂬    Workspace layout set to $NEW_LAYOUT"
