#!/usr/bin/env bash
# ~/.config/hypr/2d-workspaces.sh
# Outputs current 2D position as Waybar JSON: "3" or "3.2"

current=$(hyprctl activeworkspace -j | jq -r '.name')

if [[ "$current" =~ ^([0-9]+)-([0-9]+)$ ]]; then
    cx="${BASH_REMATCH[1]}"
    cy="${BASH_REMATCH[2]}"
    label="${cx}.${cy}"
    class="sub"
elif [[ "$current" =~ ^([0-9]+)$ ]]; then
    cx="${BASH_REMATCH[1]}"
    label="${cx}"
    class="base"
else
    label="?"
    class="unknown"
fi

printf '{"text": "%s", "class": "%s"}\n' "$label" "$class"