From 4bfa5f1674096ac8b96d24bfe4355e9ee3a73a04 Mon Sep 17 00:00:00 2001 From: Silvan Calarco Date: Fri, 5 Jan 2024 18:12:41 +0100 Subject: [PATCH] autorotate: apply patch to check rotation at startup and fork penmon: initial patch to support devices autodetection autorotate: disable session autostart (done in sddm Xsetup) [release 20180914git-2mamba;Sat Sep 15 2018] --- README.md | 2 + autorotate.desktop | 9 +++ ...ls-20180914git-autorotate-autodetect.patch | 67 ++++++++++++++++++ ...ace-tools-20180914git-check-and-fork.patch | 17 +++++ ...-tools-20180914git-penmon-autodetect.patch | 37 ++++++++++ surface-tools.spec | 68 +++++++++++++++++++ 6 files changed, 200 insertions(+) create mode 100644 autorotate.desktop create mode 100644 surface-tools-20180914git-autorotate-autodetect.patch create mode 100644 surface-tools-20180914git-check-and-fork.patch create mode 100644 surface-tools-20180914git-penmon-autodetect.patch create mode 100644 surface-tools.spec diff --git a/README.md b/README.md index cc7a57d..deb3f34 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,4 @@ # surface-tools +Tools for using the Microsoft Surface with Linux. + diff --git a/autorotate.desktop b/autorotate.desktop new file mode 100644 index 0000000..a84c2eb --- /dev/null +++ b/autorotate.desktop @@ -0,0 +1,9 @@ +[Desktop Entry] +Encoding=UTF-8 +Name=autorotate +Exec=/usr/share/autorotate/autorotate +Icon=/usr/share/autorotate/rotate.png +Type=Application +Comment=Automatic display rotation +Comment[it]=Rotazione automatica dello schermo +X-KDE-autostart-phase=1 diff --git a/surface-tools-20180914git-autorotate-autodetect.patch b/surface-tools-20180914git-autorotate-autodetect.patch new file mode 100644 index 0000000..609fa28 --- /dev/null +++ b/surface-tools-20180914git-autorotate-autodetect.patch @@ -0,0 +1,67 @@ +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", "eDP1", "LVDS", "LVDS1" ] ++for out in POSSIBLE_OUTPUT: ++ match = re.search("^" + out + r" connected .* \(.*\) (?P.*) \(", ++ XRANDR_INFO, ++ re.MULTILINE ++ ) ++ if match: ++ screenname = out ++ break ++ + path = device.device_path + + prevorientation = "" diff --git a/surface-tools-20180914git-check-and-fork.patch b/surface-tools-20180914git-check-and-fork.patch new file mode 100644 index 0000000..a746631 --- /dev/null +++ b/surface-tools-20180914git-check-and-fork.patch @@ -0,0 +1,17 @@ +diff -Nru surface-tools-20180914git.orig/autorotate/autorotate surface-tools-20180914git/autorotate/autorotate +--- surface-tools-20180914git.orig/autorotate/autorotate 2018-09-14 10:58:53.959407234 +0200 ++++ surface-tools-20180914git/autorotate/autorotate 2018-09-15 12:58:25.572548316 +0200 +@@ -163,5 +163,11 @@ + # https://bugzilla.gnome.org/show_bug.cgi?id=622084#c12 + signal.signal(signal.SIGINT, signal.SIG_DFL) + +- GObject.idle_add(checkRotation) +- Gtk.main() ++ newRef=os.fork() ++ if newRef==0: ++ GObject.idle_add(checkRotation) ++ Gtk.main() ++ else: ++ checkRotation() ++ ++ diff --git a/surface-tools-20180914git-penmon-autodetect.patch b/surface-tools-20180914git-penmon-autodetect.patch new file mode 100644 index 0000000..e6f652f --- /dev/null +++ b/surface-tools-20180914git-penmon-autodetect.patch @@ -0,0 +1,37 @@ +diff -Nru surface-tools-20180914git.orig/penmon/penmon surface-tools-20180914git/penmon/penmon +--- surface-tools-20180914git.orig/penmon/penmon 2018-09-14 10:02:55.000000000 +0200 ++++ surface-tools-20180914git/penmon/penmon 2018-09-15 13:25:03.688691667 +0200 +@@ -3,7 +3,8 @@ + #####CONFIGURATION##### + screen="eDP1" + inputnames=[ +- "NTRG0001:01 1B96:1B05 Pen" ++ "NTRG0001:01 1B96:1B05 Pen", ++ "TOUCHPAD" + ] + + #####PROGRAM CODE##### +@@ -23,10 +24,22 @@ + state = subprocess.check_output([xrandr, "-q"]) + if state != oldstate: + for input_ in inputnames: +- pattern = re.compile(input_ + " *\tid=([0-9]+)\t") ++ pattern = re.compile(".*" + input_ + ".* *\tid=([0-9]+)\t.* pointer .*") + output = subprocess.check_output([xinput, "list"]).decode("unicode_escape") + matches = re.findall(pattern, output) + ++ # Find the display we are interested to move (= the laptop panel) ++ POSSIBLE_OUTPUT = [ "DSI1", "eDP1", "LVDS", "LVDS1" ] ++ for out in POSSIBLE_OUTPUT: ++ match = re.search("^" + out + r" connected .* \(.*\) (?P.*) .*", ++ state, ++ re.MULTILINE ++ ) ++ if match: ++ screen = out ++ break ++ + for id in matches: + subprocess.call([xinput, "map-to-output", id, screen]) ++ + sleep(1) diff --git a/surface-tools.spec b/surface-tools.spec new file mode 100644 index 0000000..c6d0531 --- /dev/null +++ b/surface-tools.spec @@ -0,0 +1,68 @@ +Name: surface-tools +Version: 20180914git +Release: 2mamba +Summary: Tools for using the Microsoft Surface with Linux +Group: System/Kernel and Hardware +Vendor: openmamba +Distribution: openmamba +Packager: Silvan Calarco +URL: https://github.com/Surface-Pro-3/surface-tools +## GITSOURCE https://github.com/Surface-Pro-3/surface-tools.git master +Source: https://github.com/Surface-Pro-3/surface-tools.git/master/surface-tools-%{version}.tar.bz2 +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 +License: GPL +## AUTOBUILDREQ-BEGIN +## AUTOBUILDREQ-END +Requires: pyudev +Requires: pygobject +Requires: xrandr +Requires: xinput +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 + +%build + +%install +[ "%{buildroot}" != / ] && rm -rf "%{buildroot}" +install -d %{buildroot}%{_datadir}/autorotate +cp autorotate/*.png %{buildroot}%{_datadir}/autorotate +cp autorotate/autorotate %{buildroot}%{_datadir}/autorotate/ + +#install -D -m0644 %{SOURCE1} %{buildroot}%{_sysconfdir}/xdg/autostart/autorotate.desktop + +install -D -m0755 penmon/penmon %{buildroot}%{_datadir}/penmon/penmon + +%clean +[ "%{buildroot}" != / ] && rm -rf "%{buildroot}" + +%files +%defattr(-,root,root) +#%{_sysconfdir}/xdg/autostart/autorotate.desktop +%dir %{_datadir}/autorotate +%{_datadir}/autorotate/*.png +%{_datadir}/autorotate/autorotate +%dir %{_datadir}/penmon +%{_datadir}/penmon/penmon +%doc LICENSE + +%changelog +* Sat Sep 15 2018 Silvan Calarco 20180914git-2mamba +- autorotate: apply patch to check rotation at startup and fork +- penmon: initial patch to support devices autodetection +- autorotate: disable session autostart (done in sddm Xsetup) + +* Fri Sep 14 2018 Silvan Calarco 20180914git-1mamba +- package created using the webbuild interface