surface-tools/surface-tools-20180914git-autorotate-autodetect.patch

68 lines
2.1 KiB
Diff
Raw Permalink Normal View History

diff -Nru surface-tools-20180914git.orig/autorotate/autorotate surface-tools-20180914git/autorotate/autorotate
--- surface-tools-20180914git.orig/autorotate/autorotate 2018-09-14 10:02:55.000000000 +0200
+++ surface-tools-20180914git/autorotate/autorotate 2018-09-14 10:29:23.835658053 +0200
@@ -1,9 +1,9 @@
#!/usr/bin/python
#####CONFIGURATION#####
-sensorname="accel_3d"
+#sensorname="accel_3d"
-screenname="eDP1"
+#screenname="eDP1"
#####PROGRAM CODE#####
#Do not change unless you know what you are doing!
@@ -30,6 +30,8 @@
import subprocess
import os.path
import signal
+import gi
+gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GdkPixbuf, GObject
hasAppIndicator = True
@@ -38,6 +40,12 @@
except:
hasAppIndicator = False
+def run_shell_cmd(cmd):
+ """runs a shell commands and returns the string generated by the command."""
+ p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
+ 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)
@@ -91,9 +99,28 @@
GObject.timeout_add(1000, checkRotation)
context = pyudev.Context()
-for device in context.list_devices(subsystem="iio").match_attribute("name", sensorname): break
+
+try:
+ for device in context.list_devices(subsystem="iio").match_attribute("name", sensorname): break
+except:
+ for device in context.list_devices(subsystem="iio"): break
assert device
+"""Find which output to rotate, and get its current rotation"""
+# Cache the xrandr info as we'll use it several times
+XRANDR_INFO = run_shell_cmd('xrandr --verbose')
+
+# Find the display we are interested to move (= the laptop panel)
+POSSIBLE_OUTPUT = [ "DSI1", "DSI-1", "eDP1", "LVDS", "LVDS1" ]
+for out in POSSIBLE_OUTPUT:
+ match = re.search("^" + out + r" connected .* \(.*\) (?P<rotation>.*) \(",
+ XRANDR_INFO,
+ re.MULTILINE
+ )
+ if match:
+ screenname = out
+ break
+
path = device.device_path
prevorientation = ""