Skip to content

Instantly share code, notes, and snippets.

@rfht
Last active September 1, 2022 02:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rfht/475a53fb7552bb0de719d403677385a4 to your computer and use it in GitHub Desktop.
Save rfht/475a53fb7552bb0de719d403677385a4 to your computer and use it in GitHub Desktop.
check OpenBSD lid status and reconfigure display/WM accordingly, using autorandr and fvwm2
#!/bin/sh
# make sure the appropriate autorandr configurations exist
for a_status in docked docked_open; do
autorandr | egrep -q "^$a_status( .*)?$" || \
{ echo "Error: no autorandr for $a_status"; exit 1; }
done
lid_status=$(sysctl -n hw.sensors.acpibtn0.indicator0 | cut -f1 -d' ')
if [ $lid_status = "On" ]; then # "On" = lid open
autorandr -l docked_open 2>&1 | grep -q '^Config already loaded$' && exit
elif [ $lid_status = "Off" ]; then # "Off" = lid closed
autorandr -l docked 2>&1 | grep -q '^Config already loaded$' && exit
else
echo "ERROR: invalid lid status"; exit 1
fi
# Restart fvwm2 (needs Module FvwmCommandS in fvwm2)
/usr/local/bin/FvwmCommand Restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment