We disable the default ACPI handler script logic for LID events. We _only_ disable that in the script - the default handler script will still fire for LID events, just not do anything in its routine. That is so that in the future it is easy to rectify with any upstream changes. If, over time we add more custom event and action chain to our ACPI settings, we can think about spinning out all event types into our own rules and completely disabling the deafult handler script. Our custom LID action only fires for LID open close events, and only logs that the lid has been opened for open events. For close events, it adds one extra step before suspending: Checking if any DP screens are connected - and inhibiting suspend then. That way we still automatically suspend when closing the screen lid if we are in portable mode (no external screens connected) but do nothing if they are.
36 lines
799 B
Bash
36 lines
799 B
Bash
#!/bin/sh
|
|
# Specifically handling LID events
|
|
# Can take the form:
|
|
# button/lid LID close
|
|
# button/lid LID open
|
|
# We are only interested in value $3.
|
|
|
|
# Do not turn off machine if external screens are connected.
|
|
|
|
case "$3" in
|
|
|
|
close)
|
|
should_sleep=true
|
|
screens=$(find /sys/devices -type f -wholename '*drm/*card*-DP-*/status')
|
|
while IFS= read -r screen; do
|
|
if [ "$(cat "$screen")" = connected ]; then
|
|
should_sleep=false
|
|
fi
|
|
done <<EOF
|
|
$screens
|
|
EOF
|
|
|
|
if [ "$should_sleep" = true ]; then
|
|
suspend-to-ram
|
|
logger "LID closed, no external screens, suspending..."
|
|
zzz
|
|
else
|
|
logger "LID closed, external screens, not suspending."
|
|
fi
|
|
;;
|
|
|
|
open) logger "LID opened" ;;
|
|
|
|
*) logger "ACPI action undefined (LID): $*" ;;
|
|
|
|
esac
|