Skip to content

Instantly share code, notes, and snippets.

@oVerde
Last active November 19, 2024 23:33
Show Gist options
  • Save oVerde/c781646d002d29f8a5afd38e36add538 to your computer and use it in GitHub Desktop.
Save oVerde/c781646d002d29f8a5afd38e36add538 to your computer and use it in GitHub Desktop.
In Linux devices running GNOME toggles the keyboard and touchpad on and off for a proper tablet mode.
#!/bin/sh
# toggle tablet mode script
#
# Toggles the keyboard and touchpad on and off for tablet mode on many devices
# PLEASE ENSURE THAT YOU ARE USING GNOME OR RUNNING SOME ONBOARD KEYBOARD APP BEFORE RUNNING THIS SCRIPT.
# This toggler a system variable named TABLET_MODE, OFF and then turns it ON
# Depends on `notify-send` and `xinput`
# if you dont have any: `brew install libnotify xinput`
# Must run using `source ./tgTABLETMODE.sh`
# would appreciate if anyone could turn this in a GNOME Plugin
if [[ $TABLET_MODE == 1 ]]; then
xinput | grep 'Touchpad' | cut -d '=' -f 2 | cut -f 1 | while read -r line; do
xinput enable $line
done
xinput | grep 'Keyboard' | cut -d '=' -f 2 | cut -f 1 | while read -r line; do
xinput enable $line
done
gsettings set org.gnome.desktop.a11y.applications screen-keyboard-enabled false
unset TABLET_MODE
notify-send "Tablet Mode OFF" -u critical
else
export TABLET_MODE=1
xinput | grep 'Touchpad' | cut -d '=' -f 2 | cut -f 1 | while read -r line; do
xinput disable $line
done
xinput | grep 'Keyboard' | cut -d '=' -f 2 | cut -f 1 | while read -r line; do
xinput disable $line
done
gsettings set org.gnome.desktop.a11y.applications screen-keyboard-enabled true
notify-send "Tablet Mode ON" -u critical
fi
@oVerde
Copy link
Author

oVerde commented May 15, 2022

If you have an OSK solution, you can comment lines 37 and 22, there the script forces it so you can get your kb/tp back on. It will cause some drawback like the OSK showing all the time even when out of Tablet Mode. This does fix when you restart, and is a know GNOME bug.

@ChocolateLoverRaj
Copy link

How do you do this on Wayland and KDE?

@oVerde
Copy link
Author

oVerde commented Jan 19, 2024

Should not work on KDE @ChocolateLoverRaj, just on Gnome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment