Tablet PC

From ArchWiki

This article or section needs language, wiki syntax or style improvements. See Help:Style for reference.

Reason: Bad style. (Discuss in Talk:Tablet PC)

This article aggregates information to get Arch Linux working on a tablet PC. The instructions contain information for getting the touch keyboard, stylus, stylus rotation, and screen rotation to work properly on such devices.

Stylus

Install xf86-input-wacom.

Note:
  • To configure styles devices manually (although not recommended), see the Linux Wacom Project Wiki.
  • If your keyboard stops working properly in X after installing xf86-input-wacom, comment all unnecessary entries in /usr/share/X11/xorg.conf.d/70-wacom.conf and put the resulting file in /etc/xorg.conf.d/70-wacom.conf.

On-screen keyboards

See List of applications/Utilities#On-screen keyboards.

With GNOME

Depending on your device, the default GNOME screen keyboard will work automatically when you tap on text input fields. If "Tablet Mode" detection is not working on your device (mutter issue), you might want to customize Gnome Settings > Accessibility.

Enabling Screen keyboard will allow it to always display when a text input field becomes focused.

Always Show Accessibility Menu will allow you to manually enable or disable this depending on your needs.

Rotation

Screen rotation

Enable Xserver option

Unless you are running a very old Xserver, rotation capabilities (included in xrandr) should already be on by default. If not, you can enable xrandr by adding the following option to the Screen section of the xorg.conf file.

Option         "RandRRotation" "on"

Save the file and restart the xserver for changes to take effect.

Use xrandr

The simplest way is to use:

 xrandr -o 1 #portrait mode
 xrandr -o 0 #back to normal

or similarly:

 xrandr -o left #portrait mode
 xrandr -o normal #back to normal

On some drivers, rotating the screen with xrandr -o 1 or xrandr -o left messes-up the dpi: the fonts become unreadable. The xrandr -o option is quite old. Using the --rotate solves the issue, but we need to specify the --output option first. Identify the wanted device with xrandr, and type something like:

 xrandr --output eDP --rotate left

Stylus rotation

With xsetwacom

If not done yet and in analogy to graphics tablet, an approach to get also the inputs of the touch panel rotated is to install the xf86-input-wacom Xorg driver just as suggested above. After doing so there are various commands available how to manipulate and manage the inputs of the touch panel.

To set the stylus input to portrait mode:

$ xsetwacom set stylus Rotate cw

To return to landscape mode:

$ xsetwacom set stylus Rotate none

In case the device 'stylus' cannot be found, use:

$ xsetwacom list devices

to get a list of devices.

For example:

xsetwacom set "Wacom Co.,Ltd. Pen and multitouch sensor Pen stylus" Rotate cw

Source: https://xournal.sourceforge.net/manual.html

If you still cannot change the rotation, you can try to use xinput.

With xinput

You can also use xinput to turn the stylus, like you would rotate a touchscreen.

To set the stylus input to portrait mode:

 xinput set-prop <Name of Stylus|Touch Screen> --type=float "Coordinate Transformation Matrix"  0 -1 1 1 0 0 0 0 1

To return to landscape mode:

 xinput set-prop <Name of Stylus|Touch Screen> --type=float "Coordinate Transformation Matrix"  0  0 0 0 0 0 0 0 0 

If your stylus is only listed as keyboard while using "xinput list", these are my results:

$ xinput list
⎡ Virtual core pointer                    	id=2	[master pointer  (3)]
⎜   ↳ SynPS/2 Synaptics TouchPad              	id=14	[slave  pointer  (2)]
⎣ Virtual core keyboard                   	id=3	[master keyboard (2)]
    ↳ Virtual core XTEST keyboard             	id=5	[slave  keyboard (3)]
    ↳ ELAN0732:00 04F3:272A Pen               	id=11	[slave  keyboard (3)] #My Pen

You can try touching the screen with the pen:

$ xinput list
⎡ Virtual core pointer                    	id=2	[master pointer  (3)]
⎜   ↳ SynPS/2 Synaptics TouchPad              	id=14	[slave  pointer  (2)]
⎜   ↳ ELAN0732:00 04F3:272A Pen Pen (0)       	id=17	[slave  pointer  (2)] #My Pen Pointer
⎣ Virtual core keyboard                   	id=3	[master keyboard (2)]
    ↳ Virtual core XTEST keyboard             	id=5	[slave  keyboard (3)]
    ↳ ELAN0732:00 04F3:272A Pen               	id=11	[slave  keyboard (3)] #My Pen Keyboard

Using the now listed pointer, the commands should work as expected, turning the stylus.

This worked on my HP Envy x360.

Xfce: Stylus and screen rotation

The following script will rotate the display 90 degrees clockwise every time it is executed. It will also rotate the Wacom pointer so that the stylus will still work.

rotate.sh
#!/bin/bash

case $(xfconf-query -c pointers -p /Wacom_ISDv4_90_Pen_stylus/Properties/Wacom_Rotation) in
    2)  # Currently top is rotated left, we should set it normal (0°)
          xrandr -o 0
          xfconf-query -c pointers -p /Wacom_ISDv4_90_Pen_stylus/Properties/Wacom_Rotation -s 0
          xfconf-query -c xsettings -p /Xft/RGBA -s rgb
          ;;
    0)  # Screen is not rotated, we should rotate it right (90°)
           xrandr -o 3
           xfconf-query -c pointers -p /Wacom_ISDv4_90_Pen_stylus/Properties/Wacom_Rotation -s 1
           xfconf-query -c xsettings -p /Xft/RGBA -s vbgr
           ;;
    1)    # Top of screen is rotated right, we should invert it (180°)
           xrandr -o 2
           xfconf-query -c pointers -p /Wacom_ISDv4_90_Pen_stylus/Properties/Wacom_Rotation -s 3
           xfconf-query -c xsettings -p /Xft/RGBA -s bgr
           ;;
    3)  # Screen is inverted, we should rotate it left (270°)
           xrandr -o 1
           xfconf-query -c pointers -p /Wacom_ISDv4_90_Pen_stylus/Properties/Wacom_Rotation -s 2
           xfconf-query -c xsettings -p /Xft/RGBA -s vrgb
           ;;
    *)
           echo "Unknown result from 'xfconf-query -c pointers -p /Wacom_ISDv4_90_Pen_stylus/Properties/Wacom_Rotation'" >&2
           exit 1
           ;;
esac

Save the file and make it executable.

You can create a link to it on your desktop or panel, or link it to a keyboard shortcut or special button on your tablet.

Automatic rotation

With xrandr + xinput

The following python script was developed to automatic rotate the screen and the touchscreen. Furthermore, it disable the touchpad for inverted, right, and left orientation, and supports automatic detection of accelerometers, touchscreens, and touchpad devices.

It works for devices with an accelerometer communicating through the industrial I/O subsystem /sys/bus/iio/devices/iio:deviceX, where X is the number of the device. Usually, it is necessary to change the following parameters dpath, devicename, and touchpad.

See rotate.py or a C version of the script that aims to reduce some system overhead: 2in1screen.c.

You will need to replace your actual touch device name and recompile. Instruction to recompile is located at the 1st line. You can put this in .xinitrc before the exec line:

.xinitrc
#!/bin/sh
# xrandr --dpi 180
xrdb -merge ~/.Xresources
~/bin/2in1screen &
exec i3

Note that there are many other rotate scripts on github, including:

With GNOME

See iio-sensor-proxy. Install the iio-sensor-proxy package, a git version iio-sensor-proxy-gitAUR is available.

If you want the rotation, but have the problem that GNOME is adjusting your brightness automatically in a bad way, then you can use these commands to disable it.

For current user, which can also be done via power management GUI:

$ dbus-launch gsettings set org.gnome.settings-daemon.plugins.power ambient-enabled false

For GDM, which cannot be done via GUI, run as the gdm user:

[gdm]$ dbus-launch gsettings set org.gnome.settings-daemon.plugins.power ambient-enabled false

In the default Wayland mode GNOME screen rotation is broken on some laptops that don't report the screen flip kernel event (SW_TABLET_MODE) and so GNOME does not turn on some tablet features: there is a discussion on GitLab. Install the gnome-shell-extension-screen-autorotateAUR extension to always assume tablet mode when there is a touch screen.

Alternatively use the X11 mode, which you can select from the login screen.

With a KDE module

Note:
  • From Plasma 5.25+, kded-rotation-gitAUR is not needed for Plasma Wayland Session.
  • kded_rotation is in early development stages and is a bit hacky. Use caution.

Install iio-sensor-proxy or iio-sensor-proxy-gitAUR and kded-rotation-gitAUR, then restart your Plasma session. Screen rotation should now just work.

For automatic touch screen rotation edit /usr/bin/orientation-helper script, changing the hardcoded input device name to match the one you have (choose from the output of xinput list).

With rot8

Install rot8-gitAUR and execute rot8 for Wayland or rot8 --touchscreen TOUCHSCREEN for X11. This integrates well with i3 or sway by using exec rot8.

To only start rot8 when the tabletmode is enabled, you can use acpid and modify the handler at /etc/acpi/handler.sh to execute rot8 when the tabletmode event is triggered (you can get the correct event by calling acpi_listen and trigger the event by flipping your display).

/etc/acpi/handler.sh
...
    video/tabletmode)
        case "$3" in
            0000008A)
                #echo 'tablet mode'
                case "$4" in
                    00000001)
                        DISPLAY=:0 rot8 --touchscreen TOUCHSCREEN &
                        logger 'tablet mode enabled'
                        ;;
                    00000000)
                        killall rot8
                        DISPLAY=:0 xrandr --output eDP-1 --rotate normal
                        rmmod wacom
                        modprobe wacom
                        logger 'tablet mode disabled'
                        ;;
                    *)
                        logger "ACPI action undefined: $4"
                        ;;
                esac
                ;;
            *)
                logger "ACPI action undefined: $3"
        esac
        ;;
 ...

rot8 will automatically detect orientation and rotate modern Linux desktop screen and input devices. For additional configuration see [1].

Tablet mode

You can use linuxflip-gitAUR or detect-tablet-mode-gitAUR to configure laptop and tablet modes (e.g. enable/disable keyboard/touchpad/trackpoint, start/kill on-screen keyboard etc.)

If no sensor is detected, it can be manually triggered using tablet-modeAUR.

Desktop Environments / Window Managers

i3

Using a tiling window manager like i3 makes a lot of sense for a tablet, where screen space is limited. While that may seem unintuitive at first – think about it: Android, iOS and Windows 10's tablet mode all use tiling window managers. Thus, i3 is an excellent window managers for tablets running Arch. The problem is that i3 is designed to be used with a keyboard, without a mouse, so there are no touch controls built in. For the most part, users will need to build their own, though touch gestures (see #Tips and tricks) or by adding touch button controls to a status bar or panel. Users of the polybar status bar can try i3touchmenu.

Xfce

Xfce works fine on tablets. However, when xfce-screensaver locks, there is no way to show an on-screen keyboard by default. One can be enabled by going to Settings > Screensaver > Lock Screen and enabling the On Screen Keyboard option. You will also need to add the command required to display your keyboard of choice. For example, using onboard enter this command: onboard -e

Tips and tricks

Easystroke

Easystroke is a gesture recognition application, recognizing gestures by a variety of input devices, to include pen stylus, mouse, and touch. Gestures can be used to launch programs, enter text, emulate buttons and keys, and scroll. Easystroke is available in the AUR: easystroke-gitAUR.

Note:

Easystroke is now unmaintained, the author recommand mouse-actions instead mouse-actions-cli-binAUR and mouse-actions-gui-binAUR.

Check pen battery

See: Laptop#Battery state

Launch CellWriter under pen

One useful application of Easystroke is to use it to launch CellWriter right below your mouse pointer.

This article or section needs language, wiki syntax or style improvements. See Help:Style for reference.

Reason: Script dump, in-code comments (Discuss in Talk:Tablet PC)
Note: This script requires the xdotool package, which is not installed by default.
#!/bin/bash
# Original author: mr_deimos (ubuntuforums.org). February 14, 2010
# Many bugs fixed and improvements made by Ben Wong.  October 20, 2010

# This script toggles the cellwriter letter recognizer window.
# If a cellwriter window is visible, it will be hidden.
# If cellwriter is not already running, this will create a new process.
# If coordinates are specified, the window pops up at those coordinates. 
# If coordinates are not specified, the window is toggled, but not moved.

# Implementation Note: this script is trickier than it should be
# because cellwriter does two stupid things. First, it has no
# --get-state option, so we can't tell if it is hidden or not. Second,
# both the notification area applet and the actual program window have
# the same window name in X, which means we can't simply use xwininfo
# to find out if it is showing or not. 
#
# (Of course, we wouldn't have to be doing this crazy script at all,
# if cellwriter had a --toggle-window option to toggle showing the
# keyboard, but that's another rant...)
#
# To work around the problem, we'll assume that if the window we got
# information about from xwininfo is smaller than 100 pixels wide, it
# must be an icon in the notification area. This may be the wrong
# assumption, but, oh well...

if [[ "$1" == "-v" || "$1" == "--verbose" ]]; then
    verbose=echo
    shift
else
    verbose=:
fi

if [[ "$1" && -z "$2"  ||  "$1" == "-h"  ||  "$1" == "--help" ]] ; then 
    cat >&2 <<EOF
$(basename $0): Toggle showing the cellwriter window, optionally moving it."

Usage:  $(basename $0) [x y]"
	Where x and y are the desired position of the cellwriter window."
	If x and y are omitted, the window is not moved."
EOF
    exit 1
fi

if [[ "$1" && "$2" ]]; then
    x=$[$1-20]			# Offset slightly so cursor will be in window 
    y=$[$2-30]
    [ $x -lt 0 ] && x=0		# Minimum value is zero
    [ $y -lt 0 ] && y=0
fi

if ! xwininfo -root >/dev/null; then
    echo "$(basename $0): Error: Could not connect to your X server." >&2
    exit 1
fi

# Try to obtain CellWriter's window id.
# We can't use "xwininfo -name" b/c that might find the notification icon. 
OLDIFS="$IFS"
IFS=$'\n'
for line in $(xwininfo -root -tree | grep CellWriter); do
    line=0x${line#*0x}		# Just to get rid of white space before 0x.
    $verbose -en "Checking: $line\t"
    if [[ $line =~ (0x[A-Fa-f0-9]+).*\)\ *([0-9]+)x([0-9]+) ]]; then
	id=${BASH_REMATCH[1]}
	width=${BASH_REMATCH[2]}
	height=${BASH_REMATCH[3]}
	if [[ $width -gt 100 ]]; then
	    $verbose "looks good."
	    CW_WIN_ID=$id
	    break;
	else
	    $verbose "too small, ignoring."
	fi
    else
	echo "BUG: The xwininfo regular expression in $0 is broken." >&2
    fi
done
IFS="$OLDIFS"

#Check if Cellwriter's window is visible
if [ "$CW_WIN_ID" ] ; then
    CW_MAP_STATE=`xwininfo -id "$CW_WIN_ID"|grep "Map State"|cut -f 2 -d :`
else
    $verbose "Can't find cellwriter window, checking for a running process..."
    if ! pgrep -x cellwriter >& /dev/null; then
	$verbose "No cellwriter process running, starting a new one."
	if [[ "$x" && "$y" ]]; then
	    cellwriter --show-window --window-x=$x --window-y=$y &
	else
	    cellwriter --show-window &
	fi
	exit 0
    else
	$verbose "Found a process, so the window has not been created yet."
	$verbose "Pretending the window is UnMapped."
	CW_MAP_STATE=IsUnMapped
    fi
fi

$verbose "Map state: $CW_MAP_STATE"

case "$CW_MAP_STATE" in

    *IsViewable*)		# Window is currently visible.
	$verbose "hiding window"
	cellwriter --hide-window &
	;;

    *IsUnMapped*)		# Window is currently hidden or non-existent.
	if [[ "$x" && "$y" && "$CW_WIN_ID" ]]; then
	    $verbose "moving window to $x $y"
	    xdotool windowmove $CW_WIN_ID $x $y
	fi
	$verbose "showing window"
	cellwriter --show-window &    # In bg in case cw is not already running
	;;

    *) 				# This will never happen...
	echo "BUG: cellwriter is neither viewable nor unmapped" >&2
	echo "BUG: ...which means this script, $0, is buggy." >&2
	exit 1
	;;
esac

exit 0

Save the script as cellwriter.sh in either /usr/local/bin/ or $HOME/bin, and make it executable.

Then create a gesture in Easystroke tied to the following command:

cellwriter.sh $EASYSTROKE_X1 $EASYSTROKE_Y1

When you launch it (using the gesture you created), it will open right under your pen.

Gestures for the Alphabet

You can also use Easystroke to make gestures for the entire alphabet, replacing much of the need for CellWriter. To avoid having to make separate gestures for the upper-case letters, you can use the following script to activate the shift key.

Note: This script requires the xautomation package, which is not installed by default.
#!/bin/bash
if [ -f /tmp/shift ]
then
  xte "keydown Shift_L" "key $1" "keyup Shift_L"
  rm -f /tmp/shift
else
  xte "key $1"
fi

Save the script as keypress.sh in either /usr/local/bin/ or $HOME/bin, and make it executable.

Then create a gesture in Easystroke tied to the following command:

touch /tmp/shift

This will activate the shift key. To activate the letter keys, tie your gestures to the following command:

keypress.sh $LETTER

Replace $LETTER with the letter in the alphabet in question.

So, when you want to enter an upper-case letter, use your gesture for the shift key followed by the letter. If you want a lower-case letter, simply use your gesture for the letter.

Xournal & Xournal++

Xournal

Xournal is an application for notetaking, sketching, and keeping a journal using a stylus. Xournal aims to provide superior graphical quality (subpixel resolution) and overall functionality.

You can also extend the functionality of xournalAUR with patches, to enable things such as autosaving documents and inserting images. See SourceForge for links to all the available patches. To apply a patch, see Patching packages.

Xournal++

Xournal++ (xournalpp) is the successor to Xournal that is currently in development. If you want a newer version Xournal, then you could try this. It is currently stable with little to no bugs that causes crashes.

GNOME Screensaver

To unlock your gnome-screensaverAUR using Cellwriter to enter your password, first start dconf-editor:

$ dconf-editor

Under /org/gnome/desktop/screensaver, embedded-keyboard-command to cellwriter --xid --keyboard-only, and check the embedded-keyboard-enabled checkbox.

Alternatively, instead of using the graphical registry editor, you can simply type these into your command line:

$ gsettings set org.gnome.desktop.screensaver embedded-keyboard-command "cellwriter --xid --keyboard-only"
$ gsettings set org.gnome.desktop.screensaver embedded-keyboard-enabled true

GDM

You can also use CellWriter with GDM. First open /etc/gdm/Init/Default as root with a text editor. Then near the bottom of the file, add the lines in bold as shown:

fi
cellwriter --keyboard-only &
exit 0

You can add --window-x and --window-y to adjust the position of CellWriter accordingly. For example:

cellwriter --keyboard-only --window-x=512 --window-y=768 &
Note: You can only use CellWriter with a Plain style GDM.

To start a fully fledged CellWriter instance within the user session, you might want to terminate the instance started with the keyboard-only switch within the gdm context. Add something such as killall cellwriter to your newly created file /etc/gdm/PostLogin/Default.

Note: This works in a single-user setup, if you have a multi-user setup, you might want to develop and post your more elaborate solution.

LightDM

Configuring LightDM to use Onboard for touchscreen login and unlocking is likely the simplest option (and stable) to provide onscreen keyboard login (when using the default GTK greeter).

Ensure onboard and lightdm-gtk-greeter-settings are installed and run lightdm-gtk-greeter-settings to configure onboard to start.

Specifiying onboard -t Droid -l Phone configures the Droid theme and sets the Phone layout.

Touchegg

Touchegg is a multitouch gesture recognizer. It can recongize up to five finger gestures (tap, drag, pinch, rotate...).

Troubleshooting

Wacom Drivers

These commands are useful in troubleshooting:

wacdump -f tpc /dev/ttyS0
xidump -l
xidump -u stylus

If xidump shows that your tablets max resolution is the same as screen resolution, then your wacom driver has rescaled your wacom coordinates to the X server's resolution. To fix this, try recompiling your linuxwacom driver with:

./configure --disable-quirk-tablet-rescale

Screen Rotation support

Some video drivers do not support rotation. To check if your driver supports rotation, check the output of xrandr for the list orientations:

normal left inverted right