Created
January 27, 2024 10:45
-
-
Save Geofferey/00f915716bfda5a38e68085f5537f286 to your computer and use it in GitHub Desktop.
acpi-lid-switch.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
## This script is intended to be ran by ACPID daemon on lid switch events with the goal of disabling/re-enabling | |
# local tochpad on Chromebook trogdor + display on lid close/open. There is an issue with the touchpad that causes | |
# spurious input while the lid is closed and not suspeded + XFCE/upowers method of screen blanking causes issues | |
# with resuming session after opening the keyboard flap. | |
LOGFILE=/dev/null | |
## This is all being done so root can get display # and session cookie of the foreground users console | |
FG_USER=$(stat -c%U /dev/tty$(fgconsole)) | |
FG_UID=$(id -u ${FG_USER}) | |
FG_TTY="tty$(fgconsole)" | |
FG_XORG_PID=$(pgrep -xt ${FG_TTY} Xorg) | |
FG_XDISPLAY=:$(lsof -aUp "${FG_XORG_PID}" | sed '\|.*X11-unix/X\([0-9]\{1,\}\) .*|!d;s//\1/;q') | |
echo "$1" >> ${LOGFILE} | |
echo $(whoami) >> ${LOGFILE} | |
echo FG_USER=${FG_USER} >> ${LOGFILE} | |
echo FG_UID=${FG_UID} >> ${LOGFILE} | |
echo FG_TTY=${FG_TTY} >> ${LOGFILE} | |
echo FG_XORG_PID=${FG_XORG_PID} >> ${LOGFILE} | |
echo FG_XDISPLAY=${FG_XDISPLAY} >> ${LOGFILE} | |
export DISPLAY=$FG_XDISPLAY | |
## Just guessing some possible display managers to locate Xorg session cookie, not tested with other DMs | |
DMS="gdm lightdm" | |
for DM in ${DMS}; do | |
if [ -e /run/user/${FG_UID}/${DM}/Xauthority ]; then | |
export XAUTHORITY=/run/user/${FG_UID}/${DM}/Xauthority | |
echo DISPLAY_MANAGER=${DM} >> ${LOGFILE} | |
fi | |
done | |
state=$(echo "$1" | cut -d " " -f 3) | |
case "$state" in | |
close) | |
# Disable touchpads/screen on lid close to prevent phantom touches | |
echo "Disabing touch devices..." >> ${LOGFILE} | |
/usr/bin/synclient touchpadoff=1 >> ${LOGFILE} | |
/usr/bin/xinput disable "pointer:Google Inc. Hammer" >> ${LOGFILE} 2>&1 | |
#/usr/bin/xinput disable "pointer:gt7375p 27C6:0E51" >> ${LOGFILE} 2>&1 | |
/usr/bin/brightnessctl --save | |
/usr/bin/brightnessctl s 0 | |
;; | |
open) | |
# Re-enable the touch devices after opening the lid | |
echo "Enabling touch devices..." >> ${LOGFILE} | |
/usr/bin/xinput enable "pointer:Google Inc. Hammer" >> ${LOGFILE} 2>&1 | |
#/usr/bin/xinput enable "pointer:gt7375p 27C6:0E51" >> ${LOGFILE} 2>&1 | |
/usr/bin/synclient touchpadoff=0 >> ${LOGFILE} | |
/usr/bin/brightnessctl --restore | |
;; | |
*) | |
# panic: not a state I know about! | |
echo "PANIC STATE" >> ${LOGFILE} | |
esac | |
echo "" >> ${LOGFILE} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment