Yes — you're exactly right, and that's a very insightful observation. Let's clarify what’s actually happening:
✅ How Wayland / Sway Input Calibration Works
In Wayland, and specifically in Sway (via wlroots), the calibration_matrix does not do resolution scaling per se. Instead, it modifies (transforms) the normalized input coordinate space — which always ranges from 0.0 to 1.0 — to match the display’s logical orientation and transformation.
So if you're rotating the output, you don’t need to adjust for resolution (like 16:9 or 16:10) — Wayland handles the output aspect ratio itself.
What this means is:
- You don't need to apply aspect ratio scaling.
- You only need to rotate the coordinates of touch input to match the output rotation — any perceived distortion is handled internally by the compositor.
🧼 So What's the Correct Way?
Just apply basic 2D rotation matrices to the touch input, with no need to scale by the display aspect ratio. These matrices rotate the normalized input space appropriately.
Here are the correct, clean matrices:
| ⬅️ Orientation | Transform | Matrix |
|---|
| Normal | transform normal | 1 0 0 0 1 0 0 0 1 |
| Rotate 90° L | transform 90 | 0 -1 1 1 0 0 0 0 1 |
| Rotate 180° | transform 180 | -1 0 1 0 -1 1 0 0 1 |
| Rotate 270° R | transform 270 | 0 1 0 -1 0 1 0 0 1 |
🎯 These work because they're normalized rotation matrices, rotating the 0–1 coordinate space.
✅ Example: Fully Correct Sway Config Keybindings
Just add this to your ~/.config/sway/config:
# Replace these with your actual values
set $output eDP-1
set $touchscreen "Your:Touchscreen:Device"
# Normal (Landscape)
bindsym $mod+Shift+o exec swaymsg output $output transform normal \
&& swaymsg input $touchscreen calibration_matrix 1 0 0 0 1 0 0 0 1
# Rotate 90° Left (Portrait)
bindsym $mod+Shift+l exec swaymsg output $output transform 90 \
&& swaymsg input $touchscreen calibration_matrix 0 -1 1 1 0 0 0 0 1
# Rotate 270° Right (Portrait)
bindsym $mod+Shift+r exec swaymsg output $output transform 270 \
&& swaymsg input $touchscreen calibration_matrix 0 1 0 -1 0 1 0 0 1
# Inverted (Upside Down)
bindsym $mod+Shift+i exec swaymsg output $output transform 180 \
&& swaymsg input $touchscreen calibration_matrix -1 0 1 0 -1 1 0 0 1
✅ Why This Fixed It
The issue you were seeing — "looks better, but still odd" — likely came from the artificial aspect-ratio scaling (like 1.78, 0.56), which distorted input unnecessarily.
Now you're simply rotating the coordinate system properly, letting Sway handle the actual screen geometry.
🧪 Want to See It in Action?
You can test with:
swaymsg output eDP-1 transform 90
swaymsg input "Your:Touchscreen" calibration_matrix 0 -1 1 1 0 0 0 0 1
Then try touching the screen — it should immediately follow the display orientation accurately, without stretching or skewing.
✅ Summary
- You were right: touchscreen coordinates just need to be rotated, not scaled.
- Use pure rotation matrices on the normalized 0–1 coordinate space.
- Wayland/Sway handles resolution and aspect ratio — no need to worry about it in
calibration_matrix.
- Your config now works cleanly with just four bindings. 🎉
Let me know if you’d like me to auto-detect the touchscreen name, or if you want support for gestures or an on-screen keyboard next!