rachel.cafe/_posts/2021-10-09-linux_on_x13_yoga.md

112 lines
3.7 KiB
Markdown

---
layout: post
title: "Running Linux on the Thinkpad X13 Yoga (Gen 2)"
---
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. <!--more-->I'm writing this cause there isn't 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 doesn't 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 you're using GRUB (if you don't 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 you're not using grub or running a distro without `update-grub` I'm going to assume you know how to do this.
# HiDPI
I've 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 you're not using a desktop enviornment this is fixed by adding the following line to your ~/.Xresources.
```
Xft.dpi: 144
```
If you're using xinit/startx you'll also want to add this to your xinitrc (if it's not already there).
```sh
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. I've hacked together these and written a, less bad, working script.
```sh
#!/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
```sh
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.
```sh
xrandr --output "$DNAME" --rotate "$NEW_ROT"
```