From f3135754c157a28771319d80c6ab8f52e02d65a7 Mon Sep 17 00:00:00 2001 From: Armando Hernandez Date: Sun, 13 Mar 2022 18:58:00 +0100 Subject: [PATCH] Use xrandr to find number of monitors On some linux systems there exist no file such as '/sys/class/drm/*/status'. Instead of relying on the number of these files, we can use xrandr (plus some greping) to extract the number of monitors. --- mons.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/mons.sh b/mons.sh index b86ce5c..87d6b19 100755 --- a/mons.sh +++ b/mons.sh @@ -268,9 +268,13 @@ main() { if $aFlag ; then prev=0; i=0 while true; do - for status in /sys/class/drm/*/status; do - [ "$(<"$status")" = 'connected' ] && i=$((i+1)) - done + i=$($XRANDR | grep -Po '[^dis]connected' | wc -l) + if [ $i -gt 1 ]; then + MONITORS_LIST=$($XRANDR | grep -Po '.+[^dis]connected' | cut -sd' ' -f1) + for monitor in $MONITORS_LIST; do + [[ "LVDS-0" = $monitor && "closed" = $(cat /proc/acpi/button/lid/LID/state | grep -Po '(?<=state:).+$' | grep -Po '[^\s].+$') ]] && i=$((i-1)) + done + fi if [ "$i" != "$prev" ]; then if $xFlag; then