#!/bin/bash

# apps default fix orientation
WAYDROID_ORIENTATION_CONFIG='
[APPORIENTATION]
WaydroidDefaultOrientation=4
# Сканер ГИБДД (Принудительный портретный режим под поворот камеры)
waydroid.ru.ppr.mpauto=1
# Дефолтная камера (Принудительный портретный режим под поворот камеры)
waydroid.com.android.camera2=1
'

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 "ATTRS{name}==\"himax-stylus\", ENV{ID_INPUT_TOUCHSCREEN}=\"1\", ENV{ID_INPUT_MOUSE}=\"0\", ENV{ID_INPUT_KEY}=\"1\", ENV{ID_INPUT_TABLET}=\"\", 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 "/root/hardware/yadro/calibrate-touch-fly-dm" >> /etc/X11/fly-dm/Xsetup
