]> git.plutz.net Git - blast/blobdiff - modules/display_ws5inch.mk
enabled touch rotation, removed fixed screen rotation
[blast] / modules / display_ws5inch.mk
index 49b27b753907153b9e8283f6b6c9f6a34a392ef0..6f03a5d8a98d5cd49cf2f736409127b8fbde07e5 100644 (file)
@@ -1,16 +1,17 @@
-define display_ws5inch_boot :=
+PACKAGES += xserver-xorg-input-evdev xinput xinput-calibrator
+
+define RPICONFIG +=
 
-# Waveshare 5 Inch Display
+### Waveshare 5 Inch Display ###
 hdmi_group=2
 hdmi_mode=87
 hdmi_cvt=800 480 60 6 0 0 0
 hdmi_drive=1
-dtparam=i2c_arm=on
-dtparam=spi=on
-enable_uart=1
 dtoverlay=ads7846,cs=1,penirq=25,penirq_pull=2,speed=50000,keep_vref_on=0,swapxy=0,pmax=255,xohms=150,xmin=200,xmax=3900,ymin=200,ymax=3900
 endef
 
+export display_ws5inch_cfg display_ws5inch_rotation
+
 define display_ws5inch_cfg :=
 Section "InputClass"
        Identifier "evdev touchscreen catchall"
@@ -21,13 +22,38 @@ Section "InputClass"
 EndSection
 endef
 
-export display_ws5inch_boot display_ws5inch_cfg
+define display_ws5inch_rotation :=
+# Keep touch matrix rotated in accordance with screen rotation
+while sleep 3; do
+  oldrotate="$${rotate}"
+  rotate="$$(xrandr |grep primary)"
+  rotate="$${rotate#*+0+0 }"
+  rotate="$${rotate% (*}"
 
-PACKAGES += xserver-xorg-input-evdev xinput xinput-calibrator
+  [ "$${oldrotate}" = "$${rotate}" ] || case $$rotate in
+    left)     xinput set-prop 'ADS7846 Touchscreen' 'Coordinate Transformation Matrix' 0 -1 1  1 0 0  0 0 1;;
+    right)    xinput set-prop 'ADS7846 Touchscreen' 'Coordinate Transformation Matrix' 0 1 0  -1 0 1  0 0 1;;
+    inverted) xinput set-prop 'ADS7846 Touchscreen' 'Coordinate Transformation Matrix' -1 0 1  0 -1 1  0 0 1;;
+    *)        xinput set-prop 'ADS7846 Touchscreen' 'Coordinate Transformation Matrix' 1 0 0  0 1 0  0 0 1;;
+  esac
+done &
+endef
 
 .PHONY: _display_ws5inch
 _config: _display_ws5inch
 _display_ws5inch: ${CFGROOT} _copy _mount
-       printf %s "$${display_ws5inch_boot}" >>"$${CFGROOT}/boot/config.txt"
+       # Rough touch calibration
        mkdir -p "$${CFGROOT}/usr/share/X11/xorg.conf.d/"
-       printf %s "$${display_ws5inch_cfg}" >"$${CFGROOT}/usr/share/X11/xorg.conf.d/45-evdev.conf"
+       printf '%s\n' "$${display_ws5inch_cfg}" >"$${CFGROOT}/usr/share/X11/xorg.conf.d/45-evdev.conf"
+       # Resolution / Rotation stuff
+       mkdir -p "$${CFGROOT}/etc/X11/Xsession.d/"
+       printf 'xrandr --size 800x480\n' >"$${CFGROOT}/etc/X11/Xsession.d/10display_resolution"
+       printf '%s\n' "$$display_ws5inch_rotation" >"$${CFGROOT}/etc/X11/Xsession.d/20touch_rotation"
+       # Correct DPI scaling, although application support is mediocre
+       mkdir -p "$${CFGROOT}/etc/X11/Xresources/"
+       printf 'Xft.dpi: 180\n' >"$${CFGROOT}/etc/X11/Xresources/dpi_resolution"
+       # Workaround for applications that do not handle DPI scaling correctly
+       -sed -i 's;^Exec=;Exec=env GDK_DPI_SCALE=.5 ;' \
+         $${CFGROOT}/usr/share/applications/chromium*.desktop \
+         $${CFGROOT}/usr/share/applications/firefox*.desktop \
+         $${CFGROOT}/usr/share/applications/exo-web-browser.desktop