#!/bin/bash

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

#default orientation
sed -i "s/rotation\": 8/rotation\": 2/" /usr/share/kscreen/generic-config

#x11
echo "ATTRS{name}==\"Goodix Capacitive TouchScreen\", ENV{LIBINPUT_CALIBRATION_MATRIX}=\"-1 0 1 0 -1 1 0 0 1\"" > /etc/udev/rules.d/99-astra-mobile-touch.rules
echo >> /etc/udev/rules.d/99-astra-mobile-touch.rules
udevadm trigger

echo 'Section "InputClass"
        Identifier      "calibration"
        MatchProduct    "Goodix Capacitive TouchScreen"
        Option  "Calibration"   "0 1200  0 1920"
        Option "TransformationMatrix"  "0 1 0 -1 0 1 0 0 1"
EndSection

Section "Monitor"
        Identifier   "Monitor0"
        VendorName   "Monitor Vendor"
        ModelName    "Monitor Model"
        Option "Rotate"    "left"
EndSection

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

' > /etc/X11/xorg.conf.d/99-calibration.conf

# choose right touchscreen configuration in BIOS
sed -i "s/ acpi_osi=Linux//" /etc/default/grub
sed -i "s/\(GRUB_CMDLINE_LINUX_DEFAULT=\".*\)\"/\1 acpi_osi=Linux\"/" /etc/default/grub
update-grub

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