Touch Screen and Tablet on x220 Tablet and FreeBSD

My main laptop is a Lenovo x220 Tablet with an an awesome swivel screen. The screen on the laptop is a touch screen and wacom tablet which uses a pen that hides in the side of the laptop.

I had quite a bit of trouble getting this all setup. Wacom touch and pen devices are supported by webcamd in FreeBSD. I set up webcamd as documented elsewhere on the internet and while I could see webcamd grabbing the input devices the touch screen or pen didn't work at all under X.

Eventually I figured out the problem was xorg not detecting the hid device nodes. To solve this I had to manually create an xorg.conf and the following sections.

Section "ServerLayout"
    Identifier     "X.org Configured"
    Screen      0  "Screen0" 0 0
    Screen      1  "Screen1" RightOf "Screen0"
    InputDevice    "Mouse0" "CorePointer"
    InputDevice    "Keyboard0" "CoreKeyboard"
    InputDevice    "stylus" "SendCoreEvents"
    InputDevice    "touch" "SendCoreEvents" 
EndSection

...

Section "InputDevice"
    Driver        "wacom"
    Identifier    "stylus"
    Option        "Device"       "/dev/input/event0"
    Option        "Type"         "stylus"
    Option        "USB"          "on"                 # USB ONLY
    Option        "Mode"         "Absolute"           # other option: "Absolute"
    Option        "Vendor"       "WACOM"
    Option        "tilt"         "off"  # add this if your tablet supports tilt
    Option        "Threshold"    "5"   # the official linuxwacom howto advises this line
EndSection

Section "InputDevice"
    Driver        "wacom"
    Identifier    "touch"
    Option        "Device"       "/dev/input/event1"
    Option        "Type"         "touch"
    Option        "USB"          "on"                  # USB ONLY
    Option        "Mode"         "Absolute"            # other option: "Absolute"
    Option        "Vendor"       "WACOM"
    Option        "tilt"         "off"  # add this if your tablet supports tilt
    Option        "Threshold"    "5"   # the official linuxwacom howto advises this line
EndSection

With the now xorg.conf dropped into /etc I could now restart the server and boom, touch screen and tablet working quite well.

When I sniveled the screen I wanted to to be able to rotate my display and input devices to the correct orientation. I wrote a little shell script that can either advance the screen rotation by 90 degrees or set it back to the default orientation.

#!/bin/sh

output=LVDS1
rotation="normal";

stylus="stylus"
touch="touch"

if [ "normal" == "$1" ]; then
    rotation="left";
else
    rotation=`xrandr --query --verbose | grep $output | awk '{print $5}'`
fi

case $rotation in
    normal)
        xrandr --output $output --rotation right
        xsetwacom --set "$stylus" Rotate cw
        xsetwacom --set "$touch"  Rotate cw
    ;;
    right)
        xrandr --output $output --rotation inverted
        xsetwacom --set "$stylus" Rotate half
        xsetwacom --set "$touch"  Rotate half
    ;;
    inverted)
        xrandr --output $output --rotation left
        xsetwacom --set "$stylus" Rotate ccw
        xsetwacom --set "$touch"  Rotate ccw
    ;;
    left)
        xrandr --output $output --rotation normal
        xsetwacom --set "$stylus" Rotate none
        xsetwacom --set "$touch"  Rotate none
    ;;
esac

I bound the script in my .i3/config to the two screen rotation buttons on the fron of the bezzel. I found the keycodes by using xev.

bindcode 198 exec rotate normal
bindcode 204 exec rotate

Overall the touch screen and tablet work quite well. When webcamd starts it doesn't always detect both the touch screen and tablet and sometimes in places them at different event points. If I could figure out a way to make these predictable or if a later xorg detects the input devices correctly then this setup would be perfect.

Open Screenshotting

There are a number of services out there that allow you to take a screenshot and upload it to a website. All of these tools that I have seen(I didn't look, at all) used have involved a proprietary service and uploading your images to someone else's hosting.

That isn't good enough for me, I needed an open tool I could use anywhere (FreeBSD support) with the ability to drop the resulting png into a directory on a webserver I control.

Here is my tool to solve this problem, screenshot. Screenshot can capture either the entire window or offer a picker to grab a certain area. I used import from ImageMagick to handle the capturing and some glue to upload the image. There is another option to open the image with feh if required.

$ screenshot open
$ screenshot upload
$ screenshot pick upload

The script also dumps file names and url into a log file, this makes it easy to track down the last taken screen shots. I have some awk magic to pull out the last url and throw it onto my clipboard.

#!/bin/sh

shotdir=$HOME/screenshots
site="mysite.me"
uploaddir="webdir/screenshots/"

if [ ! -d $shotdir ]; then
    mkdir $shotdir
fi

one=`word`
two=`word`

word=$one-$two.png
file=$shotdir/$word
name=`basename $file`
url=$site/screenshots/$name

pick=false
open=false
upload=false

for var in "$@"
do
    if [ "$var" = "pick" ]; then
        pick=true
        continue;
    fi

    if [ "$var" = "upload" ]; then
        upload=true
        continue;
    fi

    if [ "$var" = "open" ]; then
        open=true
        continue;
    fi
    file=$var
done

echo "File:" $file

echo $file "http://"$url >> $shotdir/screenshot.log

if $pick; then
    import $file;
else
    import -window root $file;
fi

if $upload; then
    scp $file $site:$uploaddir/$name
fi

if $open; then
    feh $file
fi

I use another shell script to generate a random word. This script uses my local system dictionary, /dev/random and some glue to get a random word. The glue uses three bytes read from /dev/random and uses od to format those bytes into something useful. I then use sed to seek to the line in the dictionary to get the word.

#!/bin/sh

words="/usr/share/dict/words"

num=`od -An -N3 -i /dev/random`

line=$(($num % `wc -l < $words`))

word=`sed -n "$line"p $words`

echo -n $word

More BSDCan Videos

The final set of videos from BSDCan 2015 have been released.

Radio day to Balmedie Beach

Planning a radio field day was all it took to ruin a week of perfect weather. Instead of the glorious sunshine and high temperatures of the previous days the North Sea took revenge and summoned an mighty Haar to punish us for our hubris.

We hit the beach with a bbq, food and a couple of radios. Hibby had his new toy, a clansman set including a 5m mast. The mast was light to carry, easy to slot together actually really easy to put up. I think with some practice it could be erected by one person by pegging in the guy lines first.

The bands were relatively quiet considering it was a Friday afternoon, but Hibby and Derecho had a couple of good contacts from across Europe. This radio nonsense was what interested me though, I was more interested in the playing in the dune system.

Paris loves the theatre

Paris loves the theatre, they have world renowned plays enjoyed by douchy teenage girls the world around. They love no theatre more than Security Theatre. To transit through Paris CDG and make it to the departure lounge you need to show your passport twice and your boarding pass at least six times.

In fact one agent of the airport was enjoying her role more than anyone I have seen at work. She scanned my boarding pass and scrutinized my passport before sending me through the metal discoverer.

At the other side I waited and waited expecting my bag. Instead I hear a shriek! 'You did not show me your pass'. I am dragged back through the magnetic arch to show my passport once again. This this with the agent shouting as if I had stripped half naked.

Oh fun.

BHX is a strange airport, security are trying to stay in business and keep manning up. They manage this by directing transfer passengers back through security to redo the dance, I did get set on the priority track though.

Of course, with a flights worth of passengers transferring this wasn't quick.

Past security and a worm whole takes you to a mall in the center of the city. A shopping horror exists until you overcome the forces of capitalism and resign your self to sit in the uncomfortable long.