From fed824ae8bd8c511f8006c6858be5b63ef1fb8f9 Mon Sep 17 00:00:00 2001 From: Vladimir-csp <4061903+Vladimir-csp@users.noreply.github.com> Date: Thu, 21 Mar 2024 14:30:44 +0300 Subject: [PATCH] Pure shell script for lid. --- Home.md | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/Home.md b/Home.md index 26ee4e9..c2da7d0 100644 --- a/Home.md +++ b/Home.md @@ -93,18 +93,24 @@ bindswitch --reload --locked lid:on output $laptop disable bindswitch --reload --locked lid:off output $laptop enable ``` -However, when reloading sway while using clamshell mode, the displays may reset (i.e. both displays will be enabled). To stop this, save this bash script: +However, when reloading sway while using clamshell mode, the displays may reset (i.e. both displays will be enabled). To stop this, save this shell script: ```sh #!/bin/sh -if grep -q open /proc/acpi/button/lid/LID/state; then - swaymsg output enable -else - swaymsg output disable -fi + +LAPTOP_OUTPUT="" +LID_STATE_FILE="/proc/acpi/button/lid/LID0/state" + +read -r LS < "$LID_STATE_FILE" + +case "$LS" in +*open) swaymsg output "$LAPTOP_OUTPUT" enable ;; +*closed) swaymsg output "$LAPTOP_OUTPUT" disable ;; +*) echo "Could not get lid state" >&2 ; exit 1 ;; +esac ``` -Replace `` with the name of the display. +Replace `` with the name of the display, ensure lid state file path is correct for your system. To make sure this script runs whenever Sway is reloaded, add this line to your sway config: