Fix for disabling keyboard and touchpad in tablet mode
For some 2-in-1 laptops (e.g., Lenovo Yoga 7i), GNOME handles tablet mode fairly well (flip screen and enable virtual keyboard). However, keyboard and touchpad keep active even in tablet mode (not the desirable behaviour if you want to use the stylus or fully open the screen).
The instructions above help creating two ACPI event callbacks for when we enter tablet mode, disabling and enabling mouse and keyboard automatically.
This solution was tested in a Lenovo Yoga 7i running Pop!_OS 22.04. It should also work for Ubuntu 22.04 and variants (althout it was not tested in anything other than Pop!_OS).
cat <<- "EOF" | sudo tee /etc/acpi/events/lenovo-enable-tablet-mode
event=video/tabletmode TBLT 0000008A 00000001
action=/etc/acpi/disable-keyboard-touchpad.sh
EOF
cat <<- "EOF" | sudo tee /etc/acpi/events/lenovo-disable-tablet-mode
event=video/tabletmode TBLT 0000008A 00000000
action=/etc/acpi/enable-keyboard-touchpad.sh
EOF
cat <<- "EOF" | sudo tee /etc/acpi/disable-keyboard-touchpad.sh
#!/bin/bash
# Warning: xinput needs and XAUTHORITY environment variables
# Here we are setting them manually. Change those if necessary
export DISPLAY=":1"
export XAUTHORITY="/run/user/1000/gdm/Xauthority"
# Disable keyboard and touchpad in tablet mode
# Warning: You may need to replace the grep argument by your own kerboard string
xinput | grep 'Touchpad' | cut -d '=' -f 2 | cut -f 1 | xargs xinput disable
xinput | grep 'AT Translated Set 2 keyboard' | cut -d '=' -f 2 | cut -f 1 | xargs xinput disable
EOF
cat <<- "EOF" | sudo tee /etc/acpi/enable-keyboard-touchpad.sh
#!/bin/bash
# Warning: xinput needs and XAUTHORITY environment variables
# Here we are setting them manually. Change those if necessary
export DISPLAY=":1"
export XAUTHORITY="/run/user/1000/gdm/Xauthority"
# Enable keyboard and touchpad when leaving tablet mode
# Warning: You may need to replace the grep argument by your own kerboard string
xinput | grep 'Touchpad' | cut -d '=' -f 2 | cut -f 1 | xargs xinput enable
xinput | grep 'AT Translated Set 2 keyboard' | cut -d '=' -f 2 | cut -f 1 | xargs xinput enable
EOF
sudo chmod +x /etc/acpi/enable-keyboard-touchpad.sh /etc/acpi/disable-keyboard-touchpad.sh
sudo systemctl restart acpid.service