Run Ubuntu MATE On A 2-in-1 Convertible Laptop
5 Steps To Configure The Lenovo IdeaPad Flex 5i With It's Stylus Using Ubuntu MATE
Ubuntu MATE provides support for touch screens by default. My Lenovo Flex 5i is a 2-in-1 (a.k.a "convertible") laptop with the ability to use the touch screen with a finger or an included stylus on the screen. I did have to make some adjustments to the stylus/screen mapping when using the stylus. In this article I describe those adjustments and some optional additional setup steps that make it more convenient to use the laptop in tablet mode. The specific model I have is Lenovo IdeaPad Flex 5i 14IAU7 (Model 82R70000US) and I believe that the process I describe will help anyone with a 2-in-1 laptop, regardless of make or model.
After I replaced Windows with Ubunt MATE 22.04, everything appeared to work just fine before I tried rotating the screen. For purposes of testing, I used the Displays application to rotate the screen left, right, and inverted as well as to the normal orientation. After rotating the screen, using my finger on the touch screen worked just fine no matter the orientation. However, the stylus only worked properly in the normal landscape orientation. I found that the stylus appeared to be mapped incorrectly in the other orientations. For example, when orienting the screen upside down (inverted landscape), tapping the stylus in the upper left corner of the screen would make the pointer appear in the lower right corner.
How To Map the Stylus Correctly for Different Screen Orientations
In order to get the stylus to map correctly, and knowing that the finger touch was mapped correctly, I compared the mapping for finger and stylus in each orientation. Here is how I did that. (Reference: https://wiki.archlinux.org/title/Tablet_PC)
1. Determine the names of the touch-enabled hardware device using the 'xsetwacom' command:
I typed this command into a terminal:$ xsetwacom --list devices
Here is the output I received:Wacom HID 52C8 Pen stylus id: 9 type: STYLUS
Wacom HID 52C8 Pen eraser id: 15 type: ERASER
Wacom HID 52C8 Finger touch id: 10 type: TOUCH
(xsetwacom is installed in Ubuntu MATE 22.04 by default.)
2. Determine the coordinate map for each device using 'xinput list-props'.
In my case, I discovered that the stylus used this mapping no matter the screen orientation. Here is the command I used to determine that:$ xinput list-props "Wacom HID 52C8 Pen stylus"
This is the result I got for the stylus regardless of the screen orientation:Device 'Wacom HID 52C8 Pen stylus':
Device Enabled (190): 1
Coordinate Transformation Matrix (192): 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000
We don't need all of that for the mapping. Here is the key information we need from this with all the extra zeros removed:"Coordinate Transformation Matrix" 1 0 0 0 1 0 0 0 1
Now, while the screen was in each of the 4 orientations, I ran this command to see the mapping used by the finger touch device, that was behaving correctly:$ xinput list-props "Wacom HID 52C8 Finger touch"
This lists the Coordinate Transformation Matrix information we will need for each orientation:Normal orientation: "Coordinate Transformation Matrix" 1 0 0 0 1 0 0 0 1
Left orientation: "Coordinate Transformation Matrix" 0 -1 1 1 0 0 0 0 1
Inverted orientation: "Coordinate Transformation Matrix" -1 0 1 0 -1 1 0 0 1
Right orientation: "Coordinate Transformation Matrix" 0 1 0 -1 0 1 0 0 1
How To Create On-Screen Buttons To Automate Screen Rotation
3. Scripts to Change Screen Orientation and Stylus Mapping Using a Launcher On A Panel
I created 4 separate buttons on the lower panel (I'm using Ubuntu MATE's "Familiar" panel layout.) First, I wrote 4 scripts using the commands 'xrandr' to rotate the screen, 'xinput set-prop' to set the mapping, 'gsettings set' to enable or disable finger touch (to prevent my hand from accidentally moving the cursor when using the pen) and 'notify-send' to provide feedback on the screen. Note: Each of the commands I used are provided out of the box in Ubuntu MATE 22.04.
______________________________________________________________
#!/bin/sh
# rotate-normal script
#
# Rotates the Lenovo Flex 5i touch screen to normal landscape.
# ############################################################
# Larry Bushey
#
xrandr --output eDP-1 --rotate normal # rotate the screen
caja -q # make sure the wallpaper looks right with the new orientation
xinput set-prop "Wacom HID 52C8 Pen stylus" --type=float "Coordinate Transformation Matrix" 1 0 0 0 1 0 0 0 1 # map the stylus taps correcly
xinput enable "Wacom HID 52C8 Finger touch"
gsettings set org.mate.peripherals-touchpad touchpad-enabled true
gsettings set org.ayatana.indicator.datetime show-day true # Personal preference on the wider screen
gsettings set org.ayatana.indicator.datetime show-date true
notify-send --icon=/usr/share/icons/mate/scalable/status/touchpad-enabled.svg "Enabled" "Your Flex5's touchpad is enabled."
notify-send --icon=/usr/share/icons/Yaru/48x48/emblems/emblem-default.png "Enabled" "Your finger touch is enabled."
______________________________________________________________
#!/bin/sh
# rotate-left script
#
# Rotates the Lenovo Flex 5i touch screen to left portrait.
# ############################################################
# Larry Bushey
#
xrandr --output eDP-1 --rotate left
caja -q # Fix the wallpaper
xinput set-prop "Wacom HID 52C8 Pen stylus" --type=float "Coordinate Transformation Matrix" 0 -1 1 1 0 0 0 0 1
xinput disable "Wacom HID 52C8 Finger touch"
gsettings set org.ayatana.indicator.datetime show-day false # Personal preference on the narrower screen
gsettings set org.ayatana.indicator.datetime show-date false
______________________________________________________________
#!/bin/sh
# rotate-inverted script
#
# Rotates the Lenovo Flex 5i touch screen to inverted landscape.
# ############################################################
# Larry Bushey
#
xrandr --output eDP-1 --rotate inverted
caja -q
xinput set-prop "Wacom HID 52C8 Pen stylus" --type=float "Coordinate Transformation Matrix" -1 0 1 0 -1 1 0 0 1
xinput disable "Wacom HID 52C8 Finger touch"
gsettings set org.ayatana.indicator.datetime show-day true
gsettings set org.ayatana.indicator.datetime show-date true
______________________________________________________________
#!/bin/sh
# rotate-right script
#
# Rotates the Lenovo Flex 5i touch screen to right portrait.
# ############################################################
# Larry Bushey
#
xrandr --output eDP-1 --rotate right
caja -q
xinput set-prop "Wacom HID 52C8 Pen stylus" --type=float "Coordinate Transformation Matrix" 0 1 0 -1 0 1 0 0 1
xinput disable "Wacom HID 52C8 Finger touch"
gsettings set org.ayatana.indicator.datetime show-day false
gsettings set org.ayatana.indicator.datetime show-date false
______________________________________________________________
4. Create Menu Items and Panel Buttons
Finally, I created 4 buttons (app lauchers) and assigned the appropriate script to each button to simplify switching screen orientations and stylus mappings. Ubuntu MATE makes it very easy to add icons (also referred to as shortcuts or launchers) to the menu, desktop, and panels and have them launch applications or custom scripts. (Reference: https://guide.ubuntu-mate.org/#personalization-icons)
- Right-click on a panel near where you want the new launcher (button) to appear and choose Add To Panel from the menu.
- Choose Custom Application Launcher from the list and click Add.
- Click in the field labeled Name and enter the words you want to appear when you hover over the button. For the first button, I named it "Orientation Landscape".
- In the Command field, click the Browse button then navigate to, and open, the script you want to run.
- To change the icon for the menu item, click on the icon that is displayed by default. It's a button! Browse the icons and pixmap folders to select the icon you want to use, then click Open. For this button, I used an inverted "V" icon located here:
/usr/share/icons/Yaru/scalable/status/orientation-landscape-symbolic.svg - Click the OK button to create your panel launcher.
- Right-click and choose Move and then Lock To Panel to ensure that the button appears exactly where you want it on the panel.
Ubuntu MATE icons from the Yaru Theme that I used for my panel icons: /usr/share/icons/Yaru/scalable/actions/object-rotate-left-symbolic.svg
/usr/share/icons/Yaru/scalable/actions/object-rotate-right-symbolic.svg
/usr/share/icons/Yaru/scalable/status/orientation-landscape-inverse-symbolic.svg
/usr/share/icons/Yaru/scalable/status/orientation-landscape-symbolic.svg
/usr/share/icons/Yaru/scalable/status/orientation-portrait-left-symbolic.svg
/usr/share/icons/Yaru/scalable/status/orientation-portrait-right-symbolic.svg
/usr/share/icons/Yaru/scalable/devices/tablet-symbolic.svg
How To Enable The On-screen Keyboard
5. Enable Onboard
Onboard is the name of Ubuntu MATE's on-screen keyboard. Onboard is pre-installed in Ubuntu MATE and is available at the press of a few keys for anyone requiring the use of an on-screen keyboard in place of a traditional hardware keyboard. In addition to supporting mobility-impaired users, Onboard provides support for tablet and touch-screen computers, like when the 2-in-1 is in tablet mode and the physical keyboard is disabled.
You can also enable Onboard so that it is available on-screen right at startup:
- Open the Assistive Technologies Preference tool, found at Menu > Control Center > Assistive Technology.
- Check the box labeled Enable assistive technologies.
- Click the Preferred Applications button.
- Select the Accessibility tab.
- Check the box labeled Run at start and click Close.
Note: More settings and preferences for Onboard are listed in the Control Center application in the Personal section as "Onboard Settings".
How To Configure Stylus Hardware Buttons (An Optional Step)
Use 'xinput --list devices' to determine the name of the stylus to use, as we did above. For my laptop, the command to enable right-click is:
xsetwacom --set "Wacom HID 52C8 Pen stylus" button 2 3 (Set button 2 to right-click)
Additional references: