#!/bin/bash

WAYDROID_ORIENTATION_CONFIG='
[APPORIENTATION]
WaydroidDefaultOrientation=4
waydroid.ru.rutube.app=2
waydroid.com.vkontakte.android=2
waydroid.ru.yandex.taxi=2
waydroid.ru.vtb24.mobilebanking.android=2
waydroid.ru.rostel=2
waydroid.ru.mosmetro.metro=2
waydroid.ru.fns.lkfl=2
waydroid.ru.sberbankmobile=2
waydroid.org.telegram.messenger.web=2
waydroid.ru.mail.mailapp=2
'

sed -i '/\[APPORIENTATION\]/d' /etc/xdg/plasmamobilerc
sed -i '/WaydroidDefaultOrientation=*/d' /etc/xdg/plasmamobilerc
echo "$WAYDROID_ORIENTATION_CONFIG" >> /etc/xdg/plasmamobilerc

echo "ENV{IIO_SENSOR_PROXY_TYPE}==\"*accel*\", ENV{ACCEL_MOUNT_MATRIX}=\"1,0,0;0,1,0;0,0,1\"" > /etc/udev/rules.d/99-astra-mobile-orientation.rules

# calibrate touch
echo "ATTRS{name}==\"himax-touchscreen\", ENV{LIBINPUT_CALIBRATION_MATRIX}=\"0 -1 1 1 0 0\"" > /etc/udev/rules.d/99-astra-mobile-touch.rules
echo >> /etc/udev/rules.d/99-astra-mobile-touch.rules

# fix touch on fly-dm
rm /usr/share/X11/xorg.conf.d/41-evdev.conf

cat > /etc/X11/xorg.conf.d/ts11.conf <<EOF
Section "Monitor"
    Identifier   "Monitor0"
    VendorName   "Monitor Vendor"
    ModelName    "Monitor Model"
    Option "Rotate"    "right"
EndSection

Section "Screen"
    Identifier "Screen0"
    Device     "Card0"
    Monitor    "Monitor0"
EndSection
EOF

echo "xinput map-to-output 'pointer:himax-touchscreen'  DSI-1" >> /etc/X11/fly-dm/Xsetup
