I have Lenovo ThinkPad X230 Tablet with Ubuntu 16.04. It has a convertible screen and when it is in tablet mode the touchpad is still active and make a mess.
I've created the following script and bound it to one of the built in buttons (by a custom shortcut):
#!/bin/bash -e
# Find the TouchPad device ID
ID="$(xinput | grep -ioP 'touchpad.*id=\K[0-9]*')"
if [ "$(LANG=C xinput --list-props "$ID" | awk 'NR==2{print $4}')" == "0" ]; then
# If the device is disabled, then enable it and kill 'onboard' virtual keyboard
xinput enable "$ID"; killall onboard; xrandr -o normal
elif [ "$(LANG=C xinput --list-props "$ID" | awk 'NR==2{print $4}')" == "1" ]; then
# If the device is enabled, then disable it and run 'onboard' virtual keyboard
xinput disable "$ID"; nohup onboard >/dev/null 2>&1 &
fi
The script works properly, but this is a fake solution and yesterday I spent few hours to learn how to do that in a proper way. So I decided to share this experience here.
To check whether the device is in tablet mode or not we could read the value (
0
or1
) of:This value is switched by specific events. We can catch these events and could bind scripts to them by using
acpid
- Advanced Configuration and Power Interface event daemon.1. Catch the events. Execute
acpi_listen
ornetcat -U /var/run/acpid.socket
, turn the lid in tablet mode, then turn it back. Here is an example output:Please note when the lid is close/open the result is different:
2. Configure
acpid
to recognize the events triggered by the device mode change. Run the following lines into a terminal as (single) commands:The above commands will create the files:
/etc/acpi/events/thinkpad-tablet-enabled
/etc/acpi/events/thinkpad-tablet-disabled
Note: The scripts for lid open/close aren't provided here. But they are similar as the above.
3. Restart
acpid
so it can re-read the event filters, including the ones you just added:4. Create the script
/etc/acpi/thinkpad-touchpad-in-twist-mode.sh
that will disable1
and enable0
the touchpad (&&
make it executable):$DISPAY
and$XAUTHORITY
of the current user's session, in order to allowroot
(who runs theacpid
process) to access the user's X session, respectivelyxinput
.$ID
of the touchpad. And depending on the value of the input variable$1
it will enable or disable the touckpad.Note: The backslashes before the dollar signs
\$
are intended to escape the variable (command substitution) expansion within thecat
command. So if you copy/paste the script (instead using of thecat
approach) you should remove them manually.References:
acpid
- Advanced Configuration and Power Interface event daemon.w
andawk
and Remove particular words from lines usinggrep -P '\K'
.Using the answer of pa4080, I had to make this change for it to work in Ubuntu 18.04: hard code my user (
tim
) in the script and run the script in the context of my user.File
/etc/acpi/events/thinkpad-lid-event
:and
lid.sh.post
:Made another variation acting on 'lid' and 'tabletmode' and just 2 rules catching the response from the ACPI events (use "%e" in the action, mind the quotes !):
Enjoy using the script ...
Edit: $USER doesn't always return a result when used by root ... So I replaced it using: user1="$(who | cut -d ' ' -f1)"