Tuesday, September 26, 2017

Using the Lenovo Active Pen with Lenovo Yoga 720 13" on awesome window manager

I use xournal and mypaint to take notes and draw pictures on Lenovo Yoga 720 13" with the Lenovo active pen from Amazon. But, there are some configurations I had to change to make it work properly.


An xinput form the terminal shows that I have the following
Wacom devices:

Wacom HID 50EE Pen Stylus      id=11
Wacom HID 50EE Finger Touch  id=12
Wacom HID 50EE Pen Eraser      id=15

A few words about the devices.

The device Pen Stylus is activated when the pen is close to the screen. Use xinput test 11 to see it work. This device is related to two buttons:
Button 1: when the tip of the pen touches the screen
Button 2: when the upper button on the pen (i.e. away from the tip) is pressed. I use it as a 'select' tool in xournal.

 The device Pen Eraser is activated when the lower button (i.e. the one closer to the tip) is pressed on the Pen. This one has one button, Button 1 which is activated when the tip of the pen touches the screen while you hold down the lower button. (Run xinput test 15 to see it in action.)

xinput list-props 11 will, for example, show you all the available parameters for the stylus that can be changed. The changes can be made using
xinput set-prop device_id "Settings_name" value1 value2 ... valuen

For example, after playing around a bit I found that the following pressure curve is working well for my stylus:
0, 10, 90, 100. (Basically, I am dropping the low pressure inputs and scaling up the output for high pressure inputs, thus reducing hairline edges of the letters that I write.)
So, I issued the following command in the terminal:
xinput --set-prop "Wacom HID 50EE Pen Stylus" "Wacom Pressurecurve" 0 10 90 100
I also set my pressure threshold to 500 using:
xinput --set-prop "Wacom HID 50EE Pen Stylus" "Wacom Pressure Threshold" 500
(I used `xinput test 11` to find my desired pressure value)

With this setup, xournal has been working fine
except for an occasional glitch: when I click and hold button 2 of stylus (upper one) near the screen, move it away from the screen, release the button and bring the stylus close to the screen again, xinput detects a button 2 press automatically.

I could not figure out what the reason is, but I managed to resolve it by turning off the "Hover Click" option by:
xinput --set-prop "Wacom HID 50EE Pen stylus" "Wacom Hover Click" 0

Place these 3 xinput commands in you bashrc to run after booting.

The changes I have made in xournal configuration:

# in ~/.xournal/config or manually from the menus
eraser_mode=2 #set eraser option to "Delete strokes"
btn_2=selectregion #map button 2 to "Select"

With this configuration, pressing the lower button on the pen automatically turns the pen into an eraser. The only downside is that you need to touch the pen to the screen to use the "Select" tool using the upper button and it is a consequence of disabling Hover Click.

Still, I experience some buggy behavior like random click event here and there and it can be resolved temporarily on the go by disabling  and enabling the stylus:
xinput disable 11
sleep 0.5
xinput enable 11

I like to save these lines in a script file and place it in my wibox/menu bar so that I can just click on it while I am in the middle of using xournal.

I am yet to observe a specific pattern of these glitches to look for a solution. It is probably an issue similar to the previous one where xinput gets a false click when the stylus stops interacting with the screen before a button release.

This whole setup is unproductive unless you are using your laptop in a tablet mode  which means you would like to rotate your screen (along with the input devices)

To rotate the screen:
xrandr --output $Display --rotate $1
where $Display is the name of your primary display which can be found from the output of `xrandr`. Mine is called eDP1.
 $1 can be left, right, inverted or normal.

To rotate the touchpad, we need to use a coordinate transform matrix. I could not find an easier way and with this method multiple-finger-gestures like two-finger-scroll do not change directions.
To rotate the touchpad to left, use
xinput set-prop "$TOUCHPAD" "Coordinate Transformation Matrix" 0 -1 1 1 0 0 0 0 1
Here, my $TOUCHPAD is  'MSFT0001:01 06CB:7F8F Touchpad'.
 Other coordinate tranforms:
Normal: 1 0 0 0 1 0 0 0 1
Inverted: 0 1 0 -1 1 0 0 1
Right: 0 1 0 -1 0 1 0 0 1

To rotate the Wacom devices, I use
xsetwacom set "$WacomDevice" Rotate $Direction

where  $WacomDevice is the name of the Wacom Device and the $Direction can be none, half, cw or ccw.

I call these scripts with CTRL+Alt+Arrow_keys instead of letting the accelerometer decide the orientation.

Finally, the onscreen keyboard Onboard keeps stealing focus from the target input window. To fix this, edit clientbuttons in your rc.lua to change the rule of raising a window on left click like this:

awful.button({ }, 1, function (c) if c.class ~= "Onboard" then client.focus = c end c:raise() end),

No comments: