From a6485979d043413dcf0801fe386aad9bc6163f0e Mon Sep 17 00:00:00 2001 From: Thierry Schork Date: Mon, 9 Feb 2026 17:11:00 +0100 Subject: [PATCH] - only locking session if no external monitors are connected - using env to find bash location --- bin/lid_close.sh | 27 +++++++++++++++++++++++++-- bin/lid_open.sh | 4 ++-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/bin/lid_close.sh b/bin/lid_close.sh index 69446cb..43f0c72 100755 --- a/bin/lid_close.sh +++ b/bin/lid_close.sh @@ -1,2 +1,25 @@ -#!/bin/bash -hyprctl keyword monitor "eDP-1, disable" +#!/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 +fi diff --git a/bin/lid_open.sh b/bin/lid_open.sh index 1a7a756..bae6a74 100755 --- a/bin/lid_open.sh +++ b/bin/lid_open.sh @@ -1,5 +1,5 @@ -#!/bin/bash +#!/usr/bin/env bash hyprctl keyword monitor "eDP-1, preferred, 0x0, 1" -hyprlock +