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]
This commit is contained in:
Silvan Calarco 2024-01-05 18:12:41 +01:00
parent df0d774d32
commit 4bfa5f1674
6 changed files with 200 additions and 0 deletions

View File

@ -1,2 +1,4 @@
# surface-tools
Tools for using the Microsoft Surface with Linux.

9
autorotate.desktop Normal file
View File

@ -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

View File

@ -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<rotation>.*) \(",
+ XRANDR_INFO,
+ re.MULTILINE
+ )
+ if match:
+ screenname = out
+ break
+
path = device.device_path
prevorientation = ""

View File

@ -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()
+
+

View File

@ -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<rotation>.*) .*",
+ state,
+ re.MULTILINE
+ )
+ if match:
+ screen = out
+ break
+
for id in matches:
subprocess.call([xinput, "map-to-output", id, screen])
+
sleep(1)

68
surface-tools.spec Normal file
View File

@ -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 <silvan.calarco@mambasoft.it>
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 <silvan.calarco@mambasoft.it> 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 <silvan.calarco@mambasoft.it> 20180914git-1mamba
- package created using the webbuild interface