#!/bin/bash
# X11 default rotation + touch mapping for the portrait-mounted DSI panel.
# Wayland compositors honor the DRM panel-orientation property; plain X11 does
# not, so give X11 sessions a landscape default. Only sets the initial state -
# xrandr / desktop display settings override it. Configurable via
# /etc/default/vita-screen or ~/.config/vita-screen.conf:
#   ROT=left|right|normal|inverted   (default: left)
#   DISABLE=1
[ "${XDG_SESSION_TYPE:-}" = "x11" ] && [ -n "${DISPLAY:-}" ] || exit 0

[ -r /etc/default/vita-screen ] && . /etc/default/vita-screen
[ -r "${HOME}/.config/vita-screen.conf" ] && . "${HOME}/.config/vita-screen.conf"
[ "${DISABLE:-0}" = "1" ] && exit 0
ROT="${ROT:-left}"

sleep 2
xrandr --output DSI-1 --rotate "$ROT"

# Map the touchscreen (part of the TDDI panel) to the rotated output
TS=$(xinput list --name-only 2>/dev/null | grep -m1 -i 'Synaptics')
[ -n "$TS" ] && xinput map-to-output "$TS" DSI-1
