Linux, Touchscreen and Trouble

Solutions to several problems I had with linux on a touchscreen-equiped laptop.


When installing linux on laptop, I started having a few problems with the touchscreen, especially when trying to rotate or extend the screen.

Know how to identify your devices

To manipulate input devices, I use xinput. To deal with displays, I use xrandr or the graphical interface. I need the identifiers of my devices in order to be able to interact with these.

xinput list --long | less

By examining the output of xinput, you can identify the device mentioning “touch” and get its id. In my case:

export TOUCHSCREEN='ATML1000:00 E206:5883'

Xrandr can tell you how your monitors are named.

xrandr | less

In my case, I get:

export MAINSCREEN='eDP-1'
export HDMISCREEN='HDMI-1'

How to disable the touchscreen

xinput --enable "$TOUCHSCREEN"
xinput --disable "$TOUCHSCREEN"

My setup is a simple script that flips the touchscreen on and off.

Code
#!/bin/sh
TOUCHSCREEN='ATML1000:00 E206:5883'

if [ ! -t 0 ]; then
SAYFILE=$(mktemp)
exec 3>&1 4>&2 >$SAYFILE 2>&1
say_cleanup () {
  notify-send "$(cat $SAYFILE)"
  exec 1>&3 2>&4
  rm $SAYFILE
}
trap say_cleanup EXIT
fi

is_enabled () {
  value=$(xinput --list-props "$TOUCHSCREEN" | grep -i "Device Enabled" | awk -F: '{ print $2 }')
  test $value -gt 0
}

if is_enabled; then
  xinput --disable "$TOUCHSCREEN";
  echo >&2 "Touch screen disabled."
else
  xinput --enable "$TOUCHSCREEN";
  echo >&2 "Touch screen enabled."
fi

Extending the screen

When using the graphical interface or xrandr to extend your screen, you might experience some trouble with the touchscreen.

xrandr --output "$MAINSCREEN" --mode "1920x1080" --primary \
       --output "$HDMISCREEN" --mode "1920x1080" --right-of "$MAINSCREEN"

In my case, the touch area gets mapped to the whole display area: if I touch on the right part of the touchscreen, it clicks on the right display.

A simple solution to that is to tell xinput that the touchscreen corresponds only to the main display.

xinput map-to-output "$TOUCHSCREEN" "$MAINSCREEN"

Rotating the screen

I use xrandr to rotate the screen in order to use the “tablet” mode.

xrandr --output "$MAINSCREEN" --rotate inverted

However, the touchscreen does not get “rotated” and you can guess that the result is a huge mess. This can be solved by using xinput.

xinput set-prop "$TOUCHSCREEN" "Coordinate Transformation Matrix" "-1 0 1 0 -1 1 0 0 1"

Here’s how my script looks like.

Code
#!/bin/sh
MAINSCREEN=eDP-1
TOUCHSCREEN='ATML1000:00 E206:5883'

left () {
  rotation=left
  matrix="0 -1 1 1 0 0 0 0 1"
}

right () {
  rotation=right
  matrix="0 1 0 -1 0 1 0 0 1"
}

normal () {
  rotation=normal
  matrix="1 0 0 0 1 0 0 0 1"
}

inverted () {
  rotation=inverted
  matrix="-1 0 1 0 -1 1 0 0 1"
}

if [ $# -lt 1 ]; then
  exit 1
fi;
$1 && {
  xrandr --output $MAINSCREEN --rotate $rotation
  xinput set-prop "$TOUCHSCREEN" "Coordinate Transformation Matrix" $matrix
}