rachel.cafe/_posts/2021-10-09-linux_on_x13_yoga.md
2022-01-27 19:44:11 +01:00

3.7 KiB
Raw Blame History

This is a rather short blog post on how to get the Thinkpad X13 Yoga (Gen 2) working properly on Linux. This includes, making audio work, removing screen tears, making the screen auto rotate, and making the desktop a comfortable size. Im writing this cause there isnt that much info out there on this system, and hopefully this prevents duplicated efforts.

Stylus and Touch

Work out of the box! No, seriously! If it doesnt work for you try finding out if your distribution has a Wacom driver package and install that.

Audio

Out of the box Alsa did not detect any devices whatsoever. Though in the output of lspci it showed that the sound card had Intel snd drivers loaded. The solution to this was to simply download the sof-firmware package, on Ubuntu you need to install firmware-sof-signed.

Video stutters/lockups/cursor lag

The video worked well for me mostly, though occasionally the cursor would lag behind, creating ghost copies of itself or terminals would freeze up for a second. I never had any issues with hardware acceleration though. This is solved by adding “i915.enable_psr=0” to the kernel commandline. If youre using GRUB (if you dont know what this means then you are) you need to append this inside the quotes of the line GRUB_CMDLINE_DEFAULT in the file /etc/default/grub. After saving you changes run update-grub. If youre not using grub or running a distro without update-grub Im going to assume you know how to do this.

HiDPI

Ive got the 2K version of the X13, because it was cheaper (the more decked out one was for sale). Needless to say that that many pixels on a 13” screen can cause some visibility issues.

To solve this you just need to adjust the DPI setting in the display options.

If youre not using a desktop enviornment this is fixed by adding the following line to your ~/.Xresources.

Xft.dpi: 144

If youre using xinit/startx youll also want to add this to your xinitrc (if its not already there).

xrdb -merge "$HOME/.Xresources"

Making the screen auto rotate

Note that you might not need this as some desktop environments handle this automatically.

Long story short, many other people have written, bad, half working scripts. Ive hacked together these and written a, less bad, working script.

#!/bin/sh -e
# Auto rotate screen based on device orientation

# Might be necessary depending on your environment
export DISPLAY=:0

# put your display name here
DNAME=eDP1

# may change grep to match your touchscreen(s)
INDEVS="$(xinput | awk '/Wacom/ { split($8,a,"="); print a[2] }')"

rotate () {
    ORIENTATION=$1

    NEW_ROT="normal"
    CTM="1 0 0 0 1 0 0 0 1"

    # Set the actions to be taken for each possible orientation
    case "$ORIENTATION" in
    normal)
        NEW_ROT="normal"
        CTM="1 0 0 0 1 0 0 0 1"
        ;;
    bottom-up)
        NEW_ROT="inverted"
        CTM="-1 0 1 0 -1 1 0 0 1"
        ;;
    right-up)
        NEW_ROT="right"
        CTM="0 1 0 -1 0 1 0 0 1"
        ;;
    left-up)
        NEW_ROT="left"
        CTM="0 -1 1 1 0 0 0 0 1"
        ;;
    esac

    xrandr --output "$DNAME" --rotate "$NEW_ROT"
    for INDEV in $INDEVS; do
        xinput set-prop "$INDEV" 'Coordinate Transformation Matrix' $CTM
    done

}

monitor-sensor | while read -r line; do
    case "$line" in
        *orientation*)
            set -- $line
            rotate "$4"
            ;;
    esac
done

To use this make sure to install iio-sensor-proxy, and then edit this line

DNAME=eDP1

to the name listed as connected by the output of the xrandr command.

Then mark the file as executable and add it to your autostart.

If your wallpaper looks weird after rotating you can edit the script, adding a line which re-sets your wallpaper after this line.

    xrandr --output "$DNAME" --rotate "$NEW_ROT"