To fix the touchscreen orientation mismatch after screen rotation in SwayWM, you need to manually adjust the touchscreen's input transformation to match the screen rotation. Here's how:
1. Identify your touchscreen device
Run:
swaymsg -t get_inputs
Look for a device with "type": "touch" (e.g., "name": "Goodix Capacitive TouchScreen").
2. Add input transformation to your Sway config
In your ~/.config/sway/config, define transformations for the touchscreen. Example:
input "Goodix Capacitive TouchScreen" {
# Apply rotation to match screen orientation
transform 1 0 0 1 # Default (normal)
}
3. Create rotation scripts for screen + touchscreen
Create scripts to rotate both screen and touchscreen. Example for 90° rotation:
~/bin/rotate-left.sh
#!/bin/bash
# Rotate screen 90°
swaymsg output "*" transform 90
# Rotate touchscreen 90° (adjust matrix as needed)
swaymsg input "Goodix Capacitive TouchScreen" transform 0 -1 1 0
~/bin/rotate-right.sh
#!/bin/bash
# Rotate screen 270°
swaymsg output "*" transform 270
# Rotate touchscreen 270°
swaymsg input "Goodix Capacitive TouchScreen" transform 0 1 -1 0
~/bin/rotate-normal.sh
#!/bin/bash
# Reset screen
swaymsg output "*" transform normal
# Reset touchscreen
swaymsg input "Goodix Capacitive TouchScreen" transform 1 0 0 1
Make them executable:
chmod +x ~/bin/rotate-*.sh
4. Bind scripts to keybindings
Add to your Sway config:
# Rotate left (90°)
bindsym $mod+Shift+l exec ~/bin/rotate-left.sh
# Rotate right (270°)
bindsym $mod+Shift+r exec ~/bin/rotate-right.sh
# Reset to normal
bindsym $mod+Shift+n exec ~/bin/rotate-normal.sh
5. Common Transformation Matrices
Use these matrices for different rotations (replace 0 -1 1 0 in the scripts as needed):
| Rotation | Matrix | Command Snippet |
|---|
| 0° | 1 0 0 1 | transform 1 0 0 1 |
| 90° | 0 -1 1 0 | transform 0 -1 1 0 |
| 180° | -1 0 0 -1 | transform -1 0 0 -1 |
| 270° | 0 1 -1 0 | transform 0 1 -1 0 |
6. Test and Adjust
If touch input is inverted:
- Try swapping the matrix values.
- Use
swaymsg input "device" transform reset to debug.
Why This Works
swaymsg output "*" transform rotates the screen.
swaymsg input "device" transform adjusts touchscreen coordinates to match the new orientation.
This ensures your touchscreen aligns with the rotated display. For automatic rotation, combine this with the sensor script from earlier. Let me know if you need help! 📱✨