You're absolutely right — when rotating to 90° or 270° (portrait modes), input mappings can appear skewed or "squashed", especially if the calibration matrix assumes a square aspect ratio, but the actual screen is widescreen (e.g., 1920x1200 or 1920x1080).
🔍 Understanding the Issue
By default, the calibration_matrix rotates touchscreen coordinates in a [0–1] normalized coordinate space. However, if the display's aspect ratio is not 1:1, the calibration can feel off during rotation (e.g., touches appear shifted or scaled badly across the screen).
✅ Solution: Use Adjusted Calibration Matrices Based on Aspect Ratio
Let’s say your display is 1920x1200 (widescreen, 16:10). Here's how to adjust for that:
🧮 Adjust Matrices for 16:10 Ratio
We’ll base calculations on aspect ratio and resolution.
But generally, to do it manually (without full touchscreen tooling), we can approximate corrections.
For example:
Rotate 90° (left-portrait mode)
Instead of a basic:
0 -1 1
1 0 0
0 0 1
You might try scaling the coordinates:
0 -1.6 1
0.83 0 0
0 0 1
Where:
1.6 ≈ 1920 ÷ 1200 (aspect ratio)
0.83 ≈ 1200 ÷ 1920
This adjusts for screen width/height post-rotation so the coordinates scale properly when portraited.
But honestly — manually tweaking is tedious.
🛠️ Recommended Fix: Use wlr-randr + wlr-randr-aware tools or wev, or try an automatic method.
Option 1: Use wlr-randr to check output rotation
Install wlr-randr:
sudo apt install wlr-randr
Use it to confirm your output name and current resolution for more precise calibration if needed.
Option 2: Use weston-touch-calibrator to generate proper transform
On Wayland, you might also try weston-touch-calibrator (though not always compatible with Sway), or libinput-debug-events to observe how coordinates respond to touch.
✨ Optional: Use Smaller or Smarter Rotation Scripts
Here's a script that auto-applies correct screen rotation and scales the touchscreen better, assuming common resolutions:
#!/bin/bash
rotation=$1
TOUCHSCREEN="INSERT_YOUR_TOUCHSCREEN_NAME" # Use swaymsg -t get_inputs to find it
OUTPUT="eDP-1" # Change to your actual output
case "$rotation" in
normal)
swaymsg output "$OUTPUT" transform normal
swaymsg input "$TOUCHSCREEN" calibration_matrix 1 0 0 0 1 0 0 0 1
;;
left)
swaymsg output "$OUTPUT" transform 90
# Adjust for 16:10 / 1920x1200
swaymsg input "$TOUCHSCREEN" calibration_matrix 0 -1.6 1 0.83 0 0 0 0 1
;;
right)
swaymsg output "$OUTPUT" transform 270
swaymsg input "$TOUCHSCREEN" calibration_matrix 0 1.6 0 -0.83 0 1 0 0 1
;;
inverted)
swaymsg output "$OUTPUT" transform 180
swaymsg input "$TOUCHSCREEN" calibration_matrix -1 0 1 0 -1 1 0 0 1
;;
esac
You can now bind this script with arguments in your Sway config:
bindsym $mod+Shift+o exec ~/bin/rotate_screen.sh normal
bindsym $mod+Shift+l exec ~/bin/rotate_screen.sh left
bindsym $mod+Shift+r exec ~/bin/rotate_screen.sh right
bindsym $mod+Shift+i exec ~/bin/rotate_screen.sh inverted
Make sure it's executable:
chmod +x ~/bin/rotate_screen.sh
🔚 TL;DR:
- The “weird feel” in portrait rotation is due to aspect ratio not being handled in the touchscreen matrix.
- You can manually tweak calibration_matrix to account for the resolution/aspect ratio (e.g., 16:10 ≈ 1.6 scale).
- Better: write a rotation script that applies a screen transform and tweaks the matrix accordingly.
- Use tools like
swaymsg -t get_inputs, wlr-randr, and libinput debug-events to debug and refine.
If you tell me your touchscreen device name and screen resolution, I can generate more accurate matrices for you.