From cbfaa5d956793559c60040d7902e778ba8adec69 Mon Sep 17 00:00:00 2001 From: Silvan Calarco Date: Fri, 5 Jan 2024 18:12:41 +0100 Subject: [PATCH] autorotate: fixes and touchscreen rotation support for chuwi [release 20180914git-4mamba;Sat Aug 03 2019] --- ...autorotate-chuwi-fix-and-touchscreen.patch | 135 ++++++++++++++++++ surface-tools.spec | 9 +- 2 files changed, 141 insertions(+), 3 deletions(-) create mode 100644 surface-tools-20180914git-autorotate-chuwi-fix-and-touchscreen.patch diff --git a/surface-tools-20180914git-autorotate-chuwi-fix-and-touchscreen.patch b/surface-tools-20180914git-autorotate-chuwi-fix-and-touchscreen.patch new file mode 100644 index 0000000..329c196 --- /dev/null +++ b/surface-tools-20180914git-autorotate-chuwi-fix-and-touchscreen.patch @@ -0,0 +1,135 @@ +diff -Nru surface-tools-20180914git.orig/autorotate/autorotate surface-tools-20180914git/autorotate/autorotate +--- surface-tools-20180914git.orig/autorotate/autorotate 2019-08-03 21:13:46.720000000 +0200 ++++ surface-tools-20180914git/autorotate/autorotate 2019-08-03 21:14:01.072000000 +0200 +@@ -3,12 +3,14 @@ + #####CONFIGURATION##### + #sensorname="accel_3d" + +-#screenname="eDP1" ++screenname = None ++touchname = None + + #####PROGRAM CODE##### + #Do not change unless you know what you are doing! + + xrandr="/usr/bin/xrandr" ++xinput="/usr/bin/xinput" + + resourcepaths=[ + "./", +@@ -36,6 +38,7 @@ + + hasAppIndicator = True + try: ++ gi.require_version('AppIndicator', '0.1') + from gi.repository import AppIndicator3 as AppIndicator + except: + hasAppIndicator = False +@@ -46,9 +49,15 @@ + out = p.stdout.read().strip() + return out #This is the stdout from the shell command + +-def twos_comp(val): +- if val & (1 << (16-1)) != 0: +- val = val - (1 << 16) ++def twos_comp(val, scale): ++ if scale: ++ # Chuwi ++ val = val * scale / 9.8 ++ else: ++ # Microsoft Surface (unsupported) ++ print 1 << 16 ++ if val & (1 << (16-1)) != 0: ++ val = val - (1 << 16) + return val + + def getOrientation(accelX, accelY, accelZ): +@@ -56,18 +65,32 @@ + absAccelY = abs(accelY) + absAccelZ = abs(accelZ) + +- if absAccelZ > 4 * absAccelX and absAccelZ > 4 * absAccelY: +- orientation = "flat" +- elif 3 * absAccelY > 2 * absAccelX: +- orientation = "inverted" if accelY > 0 else "normal" +- else: +- orientation = "left" if accelX > 0 else "right" ++ orientation = "nochange" ++ if absAccelZ > 0.5: ++ orientation = "nochange" ++ elif absAccelX > 3 * absAccelY: ++ orientation = "normal" if accelX > 0 else "inverted" ++ elif absAccelY > 3 * absAccelX: ++ orientation = "right" if accelY > 0 else "left" + + return orientation + + def rotate(orientation): +- if orientation in orientations: ++ if orientation in orientations and screenname is not None: + subprocess.call([xrandr, "--output", screenname, "--rotate", orientation]) ++ if touchname is not None: ++ if orientation == "normal": ++ subprocess.call([xinput, "set-prop", "pointer:" + touchname, "Coordinate Transformation Matrix", ++ "0", "0", "0", "0", "0", "0", "0", "0", "0"]) ++ elif orientation == "inverted": ++ subprocess.call([xinput, "set-prop", "pointer:" + touchname, "Coordinate Transformation Matrix", ++ "-1", "0", "1", "0", "-1", "1", "0", "0", "1"]) ++ elif orientation == "right": ++ subprocess.call([xinput, "set-prop", "pointer:" + touchname, "Coordinate Transformation Matrix", ++ "0", "1", "0", "-1", "0", "1", "0", "0", "1"]) ++ elif orientation == "left": ++ subprocess.call([xinput, "set-prop", "pointer:" + touchname, "Coordinate Transformation Matrix", ++ "0", "-1", "1", "1", "0", "0", "0", "0", "1"]) + + def toggleRotLock(event): + global rotlock +@@ -84,14 +107,14 @@ + icon.set_from_pixbuf(lockrot if rotlock else unlockrot) + + def checkRotation(): +- if not rotlock: +- device = pyudev.Device.from_path(context, path) +- accelX = twos_comp(device.attributes.asint("in_accel_x_raw")) +- accelY = twos_comp(device.attributes.asint("in_accel_y_raw")) +- accelZ = twos_comp(device.attributes.asint("in_accel_z_raw")) +- +- orientation = getOrientation(accelX, accelY, accelZ) ++ device = pyudev.Device.from_path(context, path) ++ scale = float(device.attributes.__getitem__("in_accel_scale")) ++ accelX = twos_comp(device.attributes.asint("in_accel_x_raw"), scale) ++ accelY = twos_comp(device.attributes.asint("in_accel_y_raw"), scale) ++ accelZ = twos_comp(device.attributes.asint("in_accel_z_raw"), scale) ++ orientation = getOrientation(accelX, accelY, accelZ) + ++ if not rotlock and orientation != "nochange": + global prevorientation + if orientation != prevorientation: + prevorientation = orientation +@@ -121,6 +144,20 @@ + screenname = out + break + ++# Cache the xinput info ++XINPUT_INFO = run_shell_cmd('xinput --list --name-only') ++ ++# Find the display we are interested to move (= the laptop panel) ++POSSIBLE_OUTPUT = [ "CHPN0001:00" ] ++for out in POSSIBLE_OUTPUT: ++ match = re.search("^" + out + "$", ++ XINPUT_INFO, ++ re.MULTILINE ++ ) ++ if match: ++ touchname = out ++ break ++ + path = device.device_path + + prevorientation = "" +@@ -169,5 +206,3 @@ + Gtk.main() + else: + checkRotation() +- +- diff --git a/surface-tools.spec b/surface-tools.spec index ae3389c..b4a4d0c 100644 --- a/surface-tools.spec +++ b/surface-tools.spec @@ -1,6 +1,6 @@ Name: surface-tools Version: 20180914git -Release: 3mamba +Release: 4mamba Summary: Tools for using the Microsoft Surface with Linux Group: System/Kernel and Hardware Vendor: openmamba @@ -13,6 +13,7 @@ Source1: autorotate.desktop Patch0: surface-tools-20180914git-autorotate-autodetect.patch Patch1: surface-tools-20180914git-check-and-fork.patch Patch2: surface-tools-20180914git-penmon-autodetect.patch +Patch3: surface-tools-20180914git-autorotate-chuwi-fix-and-touchscreen.patch License: GPL ## AUTOBUILDREQ-BEGIN ## AUTOBUILDREQ-END @@ -25,13 +26,12 @@ BuildRoot: %{_tmppath}/%{name}-%{version}-root %description Tools for using the Microsoft Surface with Linux. -%debug_package - %prep %setup -q %patch0 -p1 %patch1 -p1 %patch2 -p1 +%patch3 -p1 %build @@ -59,6 +59,9 @@ install -D -m0755 penmon/penmon %{buildroot}%{_datadir}/penmon/penmon %doc LICENSE %changelog +* Sat Aug 03 2019 Silvan Calarco 20180914git-4mamba +- autorotate: fixes and touchscreen rotation support for chuwi + * Tue Mar 05 2019 Silvan Calarco 20180914git-3mamba - patch #0 updated to detect DSI-1 displays