From f040004f469111bd9f9424149360673bc067cc72 Mon Sep 17 00:00:00 2001 From: Thierry Schork Date: Wed, 11 Feb 2026 00:54:20 +0100 Subject: [PATCH] suspending the laptop when no external screen is connected and lid is closed --- bin/lid_close.sh | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 bin/lid_close.sh diff --git a/bin/lid_close.sh b/bin/lid_close.sh new file mode 100755 index 0000000..2d64bdb --- /dev/null +++ b/bin/lid_close.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +set -euo pipefail + +INTERNAL="eDP-1" + +# Count non-internal monitors reported by Hyprland +external_count=$( + hyprctl monitors | awk -v internal="$INTERNAL" ' + $1 == "Monitor" { + name = $2 + sub(":", "", name) # strip trailing colon + if (name != internal) { + print name + } + } + ' | wc -l +) + +# Always turn off the laptop panel on lid close +hyprctl keyword monitor "$INTERNAL, disable" + +# Only lock if there is NO external monitor +if [ "$external_count" -eq 0 ]; then + hyprlock + systemctl suspend +fi