diff --git a/dist/hyperpixel4-rotate b/dist/hyperpixel4-rotate old mode 100755 new mode 100644 index eaa80ce..7cdf98f --- a/dist/hyperpixel4-rotate +++ b/dist/hyperpixel4-rotate @@ -1,21 +1,88 @@ #!/bin/bash ORIENTATION=$1 +DO_XORG=$2 DEVICE="pointer:Goodix Capacitive TouchScreen" UDEV_FILE="/etc/udev/rules.d/98-hyperpixel4-calibration.rules" DISP_FILE="/usr/share/dispsetup.sh" +XORG_CONF_FILE="/usr/share/X11/xorg.conf.d/88-hyperpixel4.conf" +LIGHTDM_CONF_FILE="/etc/lightdm/lightdm.conf" + +function success() { + echo -e "$(tput setaf 2)$1$(tput sgr0)" +} + +function inform() { + echo -e "$(tput setaf 6)$1$(tput sgr0)" +} + +function warning() { + echo -e "$(tput setaf 1)$1$(tput sgr0)" +} + +function compatibility_check { + grep -e "^dtoverlay=vc4-fkms-v3d.*" /boot/config.txt > /dev/null + if [ $? -ne 0 ]; then + warning "Rotation requires hardware support on the Pi 4 or Pi 400" + warning "Ensure \"dtoverlay=vc4-fkms-v3d\" is enabled in /boot/config.txt" + exit 1 + fi +} + +function set_xorg_conf { + inform "Rotating display $1"; + xrandr --output DSI-1 --rotate $1 + + inform "Setting libinput Calibration Matrix: 1 0 0 0 1 0"; + xinput set-prop "pointer:$DEVICE" "libinput Calibration Matrix" 1 0 0 0 1 0 0 0 1 + + inform "Setting Coordinate Transformation Matrix: $2 $3 $4 $5 $6 $7"; + xinput set-prop "pointer:$DEVICE" "Coordinate Transformation Matrix" $2 $3 $4 $5 $6 $7 0 0 1 + + inform "Saving xorg config to $XORG_CONF_FILE"; + sudo tee $XORG_CONF_FILE > /dev/null < /dev/null + if [ $? -eq 0 ]; then + warning "You might want to comment-out \"display-setup-script\" from $LIGHTDM_CONF_FILE\n" + fi +} function set_matrix { - printf "Setting matrix: $1 $2 $3 $4 $5 $6\n"; - xinput set-prop "$DEVICE" "libinput Calibration Matrix" $1 $2 $3 $4 $5 $6 0 0 1 - - printf "Saving touch settings to $UDEV_FILE\n"; - echo "ATTRS{name}==\"Goodix Capacitive TouchScreen\", ENV{LIBINPUT_CALIBRATION_MATRIX}=\"$1 $2 $3 $4 $5 $6\"" | sudo tee $UDEV_FILE > /dev/null + inform "Setting touch transform matrix: $1 $2 $3 $4 $5 $6"; + xinput set-prop "pointer:$DEVICE" "libinput Calibration Matrix" $1 $2 $3 $4 $5 $6 0 0 1 + + inform "Saving touch settings to $UDEV_FILE"; + echo "ATTRS{name}==\"$DEVICE\", ENV{LIBINPUT_CALIBRATION_MATRIX}=\"$1 $2 $3 $4 $5 $6\"" | sudo tee $UDEV_FILE > /dev/null + echo "ATTRS{name}==\"EP0110M09\", ENV{LIBINPUT_CALIBRATION_MATRIX}=\"$1 $2 $3 $4 $5 $6\"" | sudo tee -a $UDEV_FILE > /dev/null } function set_display { - printf "Rotating display\n"; - sudo python2 - < /dev/null + if [ $? -ne 0 ]; then + warning "The display setup script is not configured in $LIGHTDM_CONF_FILE" + warning "Maybe you're not using Raspberry Pi OS." + warning "Add \"display-setup-script=$DISP_FILE\" to $LIGHTDM_CONF_FILE or use the Xorg config method (add --xorg to this command)\n" + fi + + inform "Persisting display settings to $DISP_FILE"; + sudo chown `whoami` $DISP_FILE + python2 - <\n" - exit 0 + warning "No DISPLAY variable set, trying :0.0" + export DISPLAY=:0.0 fi if [ "$ORIENTATION" == "right" ]; then - set_display $ORIENTATION - set_matrix 0 1 0 -1 0 1 + if [ "$DO_XORG" == "--xorg" ]; then + set_xorg_conf $ORIENTATION 0 1 0 -1 0 1 + else + set_display $ORIENTATION + set_matrix 0 1 0 -1 0 1 + fi exit 0 fi if [ "$ORIENTATION" == "left" ]; then - set_display $ORIENTATION - set_matrix 0 -1 1 1 0 0 + if [ "$DO_XORG" == "--xorg" ]; then + set_xorg_conf $ORIENTATION 0 -1 1 1 0 0 + else + set_display $ORIENTATION + set_matrix 0 -1 1 1 0 0 + fi exit 0 fi if [ "$ORIENTATION" == "inverted" ]; then - set_display $ORIENTATION - set_matrix -1 0 1 0 -1 1 + if [ "$DO_XORG" == "--xorg" ]; then + set_xorg_conf $ORIENTATION -1 0 1 0 -1 1 + else + set_display $ORIENTATION + set_matrix -1 0 1 0 -1 1 + fi exit 0 fi if [ "$ORIENTATION" == "normal" ]; then - set_display $ORIENTATION - set_matrix 1 0 0 0 1 0 + if [ "$DO_XORG" == "--xorg" ]; then + set_xorg_conf $ORIENTATION 1 0 0 0 1 0 + else + set_display $ORIENTATION + set_matrix 1 0 0 0 1 0 + fi exit 0 fi