#!/usr/bin/env bash
set -eo pipefail

mkdir -p /tmp/lockscreen || true

monitors=$(hyprctl monitors -j | jq -r '.[] | select( .name | contains ("DP")) | .name')

while IFS= read -r m; do
    grim -o "$m" "/tmp/lockscreen/$m.png" || true
done <<< "$monitors"

# Only lock if not already running
if [ -z "$(pgrep hyprlock)" ] 
then 
    exec hyprlock
else
    echo "Already locked"
fi