Ubuntu MATE on a Hybrid Lenovo Miix 320

Hi there :slight_smile:
One year ago, I went to a supermarket to buy a 5€ carbon paper and went out from there with the carbon paper and a Lenovo Miix 320 with natively installed windows 10.
One hour later, the computer was running Ubuntu Mate 18.04 but i got many issues to make everything work.
Recently I done a fresh 20.04 install and saw that many issues were solved in this new LTS release.

I'm posting here some things I done in order to make easier for people that like me went buy something at the supermarket and arrived home with this computer.

Working on ubuntu mate :
Screen Rotation
Screen backlight control
Keypad + touchpad
USB ports
micro HDMI port
Screen (inverted, but perfectly working with some hacks)
Lid close sensor

Not working :
front and rear camera (there is no way to make it work)
SD card slot is working but only with external screen

Prepare a USB stick with ubuntu mate 20.04 live, plug it to your miix 320 and press power button and volume up button at the same time and hold them up to the moment you will see the lenovo logo to go inside UEFI BIOS menu.

Be careful, when you change the lid position, it can interrupt the USB communication, as the USB port is located in the keyboard part. Try to not move it so much once it booted.

Inside BIOS :
Disable secure boot inside BIOS if you are planning to do kernel upgrades
Boot form your pendrive. There is no need to send special boot options.
The screen is inverted left. You can rotate it with "Displays" that you will find inside the Mate menu for the installation.
Next run the install as for a normal install.

Once installed, do regular staff :
again invert the screen with "Displays" to right nd apply system - wide.
apt update & apt upgrade

First, the only thing we need to invert, is the login screen :slight_smile: :

└──╼ $cat /etc/lightdm/lightdm.conf.d/80-display-setup.conf 
display-setup-script=xrandr -o right 

Enable also this feature in the control center to have a touchscreen keyboard at login screen :

and inside onboard (the default onscreen keyboard) :

You can also play more with onboard :

External screen fix :
If you are using a external screen, you will notice that some things are trying to blink at the screen (desktop wallpaper is doing something strange) The fix is to set up the laptop screen back to normal rotation (do left for you) once plugged to external screen :


Ubuntu MATE up to 20.04 do not care about screen rotation. I have found on internet some scripts that i updated to make it work and have also a "tablet" mode.
First we need monitor-sensor (part of iio-sensor-proxy package)
and create a startup script (start at boot) :

# Auto rotate screen based on device orientation

# Receives input from monitor-sensor (part of iio-sensor-proxy package)
# Screen orientation and launcher location is set based upon accelerometer position
# Launcher will be on the left in a landscape orientation and on the bottom in a portrait orientation
# This script should be added to startup applications for the user

# Clear sensor.log so it doesn't get too long over time
> /tmp/sensor.log

# Launch monitor-sensor and store the output in a variable that can be parsed by the rest of the script
monitor-sensor >> /tmp/sensor.log 2>&1 &

# Parse output or monitor sensor to get the new orientation whenever the log file is updated
# Possibles are: normal, bottom-up, right-up, left-up
# Light data will be ignored
while inotifywait -e modify /tmp/sensor.log; do
# Read the last line that was added to the file and get the orientation
ORIENTATION=$(tail -n 1 /tmp/sensor.log | grep 'orientation' | grep -oE '[^ ]+$')

# Set the actions to be taken for each possible orientation
case "$ORIENTATION" in
xrandr --output DSI-1 --rotate right && xinput set-prop "FTSC1000:00 2808:1015" 'Coordinate Transformation Matrix' 0 1 0 -1 0 1 0 0 1;;
xrandr --output DSI-1 --rotate inverted && xinput set-prop "FTSC1000:00 2808:1015" 'Coordinate Transformation Matrix' -1 0 1 0 -1 1 0 0 1;;
xrandr --output DSI-1 --rotate normal && xinput set-prop "FTSC1000:00 2808:1015" 'Coordinate Transformation Matrix' 1 0 0 0 1 0 0 0 1;;
xrandr --output DSI-1 --rotate left && xinput set-prop "FTSC1000:00 2808:1015" 'Coordinate Transformation Matrix' 0 -1 1 1 0 0 0 0 1;;
xinput disable "FTSC1000:00 2808:1015" && xinput enable "FTSC1000:00 2808:1015"
#killall caja

Killing the caja process will force it to restart and re-draw the background and icons.
As you can see, natively, the miix screen is rotated, and only forcing rotation to right, it will be "normal" for us.
In order to get devices list (if yours differ) you can use the command xrandr list

Now install touchegg and leave the default config of it. You can also run it with automatic startup. This way you will have touch gestures working, like long press for right click, drag and so on.

This script will let you know if your computer didn't went to sleep after lid close or if by mistake the power button got pressed during the computer sleep (start at boot) :
#!/ bin/bash

while :
if [[ $(/usr/bin/cat /proc/acpi/button/lid/LID0/state | /usr/bin/grep closed) ]]; then
    date >>/tmp/lid.log;
    /usr/bin/echo "the lid is closed" >> /tmp/lid.log;
    /usr/bin/mplayer /usr/share/sounds/freedesktop-new/stereo/suspend-error.oga >/dev/null 2>&1;
    systemctl suspend;
    date >>/tmp/lid.log;
    /usr/bin/echo "the lid is opened" >> /tmp/lid.log;
sleep 60

A script to wash your computer and avoid unwanted operations.
It's disabling keyboard and mouse to let you wash it, next disables the touchscreen and enabling mouse and keyboard again, once done, all is enabled back (run on demand) :

zenity --info --text="Wash the computer external body before and click OK to continue"
xinput disable "HAILUCK CO.,LTD Lenovo HID Device"
xinput disable "HAILUCK CO.,LTD Lenovo HID Device Touchpad"
zenity --info --text="Keyboard and touchpad disabled for washing. Touch OK to continue"
xinput enable "HAILUCK CO.,LTD Lenovo HID Device"
xinput enable "HAILUCK CO.,LTD Lenovo HID Device Touchpad"

xinput disable "FTSC1000:00 2808:1015"
zenity --info --text="Touch screen disabled for washing. Click OK to continue"
xinput enable "FTSC1000:00 2808:1015"

Miix 320 have only 64Gb SSD disk. Snap packages keeps last 3 snaps of each snap you have installed. This script will delete all snaps except the one in use :

# https://superuser.com/a/1330590
# Removes old revisions of snaps

snap list --all | awk '/disabled/{print $1, $3}' |
    while read snapname revision; do
        snap remove "$snapname" --revision="$revision"

I'm strongly advising you to upgrade the default kernel to last available, upgrading kernel solves issues.

You can use mainline :

You can also enable ZSwap to quick up your miix (it's really working) :


Hi and thanks for this wonderful job. You seem comfortable with writing scripts, so I dare to ask. Would t be complicated to modify the screen-turning script so that it only operates when the keyboard is disconnected (tablet mode) ? If possible, it would make my day.