Getting reliable auto-rotation on a ThinkPad X1 Tablet Gen 3 running KDE Plasma on Wayland, using a systemd user service and raw accelerometer readings from /sys/bus/iio/ instead of relying on DBus orientation.
Context
-
OS: Debian 13 (Trixie).
-
Desktop: KDE Plasma on Wayland.
-
Device: Lenovo ThinkPad X1 Tablet Gen 3.
-
Issue: iio-sensor-proxy detects the accelerometer, but orientation is not reliably consumed/published for Plasma auto-rotation.
-
Approach: Read raw accelerometer values from IIO sysfs and apply rotations via kscreen-doctor.
Why this setup works
-
iio:deviceN can change across reboot/resume, so we autodetect the accelerometer directory each run.
-
kscreen-doctor is the correct Wayland-friendly tool for KScreen outputs (instead of xrandr).
-
Running as a systemd user service is more robust than KDE Autostart for a daemon-style loop: restart-on-failure, journald logs, consistent lifecycle.
-
Plasma Wayland environment variables must be synced into systemd --user, otherwise GUI tools may misbehave when started by systemd.
Requirements
Directory and file layout
-
~/.config/plasma-workspace/env/10-systemd-user-env.sh.
-
~/.local/bin/auto-rotate-kde.
-
~/.config/systemd/user/auto-rotate.service.
-
Optional lock file: ~/.config/autorotate.lock.
1) Sync Plasma session env into systemd user manager
This ensures systemd --user services see WAYLAND_DISPLAY, XDG_RUNTIME_DIR, DBUS_SESSION_BUS_ADDRESS, etc.
Reboot or log out/in once.
Verification.
2) The rotation script
Notes.
-
OUTPUT_ID is hard-set to output.eDP-1 (stable for internal panel on this model).
-
IIO_DIR is autodetected each run because iio:deviceN can change.
-
Thresholds are tuned for large raw-value scale (often > 1,000,000).
-
Lock file pauses rotation instantly.
-
Touch/pen mapping is handled by Wayland automatically, so no xinput remapping is needed.
Create the script.
3) systemd user service unit
Create the unit.
Rotation lock
Pause rotation.
Resume rotation.
Verification
Manual compositor-level test.
Service status.
Logs.
Debug mode
Enable debug for the service (properly via systemd user manager env).
Disable debug.
Sensor scale notes and tuning
-
If your values exceed 1,000,000, that is fine — thresholds must match that scale.
-
Recommended tuning starting point (already used above).
-
THRESHOLD=120000.
-
Z_DOMINANCE=800000.
-
If rotation is too “nervous”, increase STABILITY_COUNT to 4.
-
If rotation is too slow, reduce STABILITY_COUNT to 2.
Raw value watch (device index may change, pick the one that exists).
Clean-up notes
-
The directory ~/.config/plasma-workspace/env/ is still needed because Plasma uses it to run the environment sync script.
-
A ~/.config/systemd/user/auto-rotate.service.d/ drop-in directory is not required in this final setup.
Remove the drop-in directory if it exists.
Full rollback (restore previous state)
Disable and remove everything.
Remove now-empty directories if desired.
Final result
-
Auto-rotation works reliably on KDE Plasma Wayland with a supervised systemd --user service.
-
Accelerometer device reallocation is handled automatically.
-
Session env is propagated cleanly via Plasma’s env hook.
-
Manual lock is available for instant override.
Comments
Post a Comment