#!/bin/bash

set_frozen() {
    PID=$(pgrep -f swww-daemon)
    if [ $? -ne 0 ]; then
        return 1
    fi

    if [ $1 -eq 1 ]; then
        kill -STOP $PID
    elif [ $1 -eq 0 ]; then
        kill -CONT $PID
    else
        echo "Error: $1 is not a valid freeze state"
        return 1
    fi

    return $?
}

get_frozen() {
    if pid=$(pgrep -f swww-daemon); then
        if ps -o state= $pid | grep -q 'T'; then
            echo "true"
        else
            echo "false"
        fi
    else
        echo "false"
        return 1
    fi
}

if [ "$1" == "g" ]; then
    get_frozen
    exit $?
else
    if [ "$(get_frozen)" == "true" ]; then
        set_frozen 0  # Unfreeze
    else
        set_frozen 1  # Freeze
    fi
fi
