#!/usr/bin/env bash

## Copyright (C) 2024
##
## Script to toggle gaps in Hyprland

# Path to store the gap state
STATE_FILE="$HOME/.cache/hypr_gaps_state"

# Default gaps values (matching your hyprtheme.conf)
DEFAULT_GAPS_IN=5
DEFAULT_GAPS_OUT=10
DEFAULT_GAPS_WS=-10

# Check if state file exists, create if not
if [ ! -f "$STATE_FILE" ]; then
    echo "enabled" > "$STATE_FILE"
fi

# Read current state
CURRENT_STATE=$(cat "$STATE_FILE")

if [ "$CURRENT_STATE" = "enabled" ]; then
    # Disable gaps
    hyprctl --batch "keyword general:gaps_in 0; keyword general:gaps_out 0; keyword general:gaps_workspaces 0"
    echo "disabled" > "$STATE_FILE"
    notify-send -h string:x-canonical-private-synchronous:sys-notify -u low "Gaps Disabled"
else
    # Enable gaps
    hyprctl --batch "keyword general:gaps_in $DEFAULT_GAPS_IN; keyword general:gaps_out $DEFAULT_GAPS_OUT; keyword general:gaps_workspaces $DEFAULT_GAPS_WS"
    echo "enabled" > "$STATE_FILE"
    notify-send -h string:x-canonical-private-synchronous:sys-notify -u low "Gaps Enabled"
fi