Detect X1 Yoga Tablet Mode on Arch Linux
Mon, Dec 9, 2019 11:51 CET
Tags: Automation, X1 Yoga 4th Gen, Tablet Mode, systemd
Inspired from this ruby script.
Add
%wheel ALL = (ALL) NOPASSWD: /usr/bin/stdbuf -oL -eL libinput debug-events --device /dev/input/by-path/platform-thinkpad_acpi-event
to /etc/sudoers.d/nopasswd
to allow detecting those event without password.
Run this script as a daemon to enable/disable a tablet
target..
#!/usr/bin/env sh
sudo /usr/bin/stdbuf -oL -eL \
libinput debug-events --device /dev/input/by-path/platform-thinkpad_acpi-event |
grep -oP --line-buffered 'switch tablet-mode state \K\d+' |
while read state; do
if [ "$state" -eq 0 ] ; then
systemctl --user stop tablet.target
elif [ "$state" -eq 1 ] ; then
systemctl --user start tablet.target
fi
done
From there you can write systemd
user services depending on that target. See
for instance this user service
that automatically rotates the screen when in tablet mode.
See also other changes of that commit.