From ffe91246bdcb96bc8c07ec40226cb355f7c1da7e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Torjus=20H=C3=A5kestad?= <torjus@usit.uio.no>
Date: Wed, 12 Jun 2024 13:51:37 +0200
Subject: [PATCH] Fix lockhelper

---
 home/hyprland/hypridle_magicman.conf | 2 +-
 home/scripts/lockhelper.sh           | 9 ++++++++-
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/home/hyprland/hypridle_magicman.conf b/home/hyprland/hypridle_magicman.conf
index e9864fb..4fe54f6 100644
--- a/home/hyprland/hypridle_magicman.conf
+++ b/home/hyprland/hypridle_magicman.conf
@@ -2,7 +2,7 @@ general {
     lock_cmd = lockhelper # dbus/sysd lock command (loginctl lock-session)
     # unlock_cmd = notify-send "unlock!"      # same as above, but unlock
     before_sleep_cmd = lockhelper # command ran before sleep
-    # after_sleep_cmd =   # command ran after sleep
+    # after_sleep_cmd = lockhelper # command ran after sleep
     ignore_dbus_inhibit = false             # whether to ignore dbus-sent idle-inhibit requests (used by e.g. firefox or steam)
 }
 
diff --git a/home/scripts/lockhelper.sh b/home/scripts/lockhelper.sh
index 5d78521..dbb9370 100644
--- a/home/scripts/lockhelper.sh
+++ b/home/scripts/lockhelper.sh
@@ -8,4 +8,11 @@ monitors=$(hyprctl monitors -j | jq -r '.[] | select( .name | contains ("DP")) |
 while IFS= read -r m; do
     grim -o "$m" "/tmp/lockscreen/$m.png" || true
 done <<< "$monitors"
-hyprlock
+
+# Only lock if not already running
+if [ -z "$(pgrep hyprlock)" ] 
+then 
+    exec hyprlock
+else
+    echo "Already locked"
+fi