]> git.donarmstrong.com Git - deb_pkgs/autorandr.git/commitdiff
Merge pull request #169 from chmduquesne/closed_lid_treated_as_disconnected
authorPhillip Berndt <phillip.berndt@googlemail.com>
Sun, 10 Nov 2019 21:27:47 +0000 (22:27 +0100)
committerGitHub <noreply@github.com>
Sun, 10 Nov 2019 21:27:47 +0000 (22:27 +0100)
Treating a closed lid as disconnected

README.md
autorandr.py
contrib/etc/xdg/autostart/autorandr-lid-listener.desktop [new file with mode: 0644]
contrib/listen_lid.sh [new file with mode: 0755]
contrib/systemd/autorandr-lid-listener.service [new file with mode: 0644]

index 56e9e35b797fb59c6d9e58faeb3e05ddee7be9e8..200be07adfe6c359b9c68aa43c967ae89df03fa6 100644 (file)
--- a/README.md
+++ b/README.md
@@ -41,6 +41,7 @@ Contributors to this version of autorandr are:
 * Brice Waegeneire
 * Chris Dunder
 * Christoph Gysin
+* Christophe-Marie Duquesne
 * Daniel Hahler
 * Maciej Sitarz
 * Mathias Svensson
index 44e9ad2595df97b5dd5a9b8e16c917e3e3cbedc6..36f8420ab39654d5d0ec509a9f20912a2071b456 100755 (executable)
@@ -37,6 +37,7 @@ import subprocess
 import sys
 import shutil
 import time
+import glob
 
 from collections import OrderedDict
 from distutils.version import LooseVersion as Version
@@ -96,6 +97,18 @@ Usage: autorandr [options]
 """.strip()
 
 
+def is_closed_lid(output):
+    if not re.match(r'(eDP(-?[0-9]\+)*|LVDS(-?[0-9]\+)*)', output):
+        return False
+    lids = glob.glob("/proc/acpi/button/lid/*/state")
+    if len(lids) == 1:
+        state_file = lids[0]
+        with open(state_file) as f:
+            content = f.read()
+            return "close" in content
+    return False
+
+
 class AutorandrException(Exception):
     def __init__(self, message, original_exception=None, report_bug=False):
         self.message = message
@@ -505,6 +518,12 @@ def parse_xrandr_output():
         if output_modes:
             modes[output_name] = output_modes
 
+    # consider a closed lid as disconnected if other outputs are connected
+    if sum(o.edid != None for o in outputs.values()) > 1:
+        for output_name in outputs.keys():
+            if is_closed_lid(output_name):
+                outputs[output_name].edid = None
+
     return outputs, modes
 
 
diff --git a/contrib/etc/xdg/autostart/autorandr-lid-listener.desktop b/contrib/etc/xdg/autostart/autorandr-lid-listener.desktop
new file mode 100644 (file)
index 0000000..9d16f07
--- /dev/null
@@ -0,0 +1,6 @@
+[Desktop Entry]
+Name=Autorandr Lid Listener
+Comment=Trigger autorandr whenever the lid state changes
+Type=Application
+Exec=bash -c "stdbuf -oL libinput debug-events | egrep --line-buffered '^ event[0-9]+\s+SWITCH_TOGGLE\s' | while read line; do autorandr --change --default default; done"
+X-GNOME-Autostart-Phase=Initialization
diff --git a/contrib/listen_lid.sh b/contrib/listen_lid.sh
new file mode 100755 (executable)
index 0000000..7288490
--- /dev/null
@@ -0,0 +1,10 @@
+#!/bin/bash
+#
+# /!\ You must be part of the input group
+# sudo gpasswd -a $USER input
+
+stdbuf -oL libinput debug-events | \
+    egrep --line-buffered '^ event[0-9]+\s+SWITCH_TOGGLE\s' | \
+    while read line; do
+    autorandr --change --default default
+done
diff --git a/contrib/systemd/autorandr-lid-listener.service b/contrib/systemd/autorandr-lid-listener.service
new file mode 100644 (file)
index 0000000..a6776ee
--- /dev/null
@@ -0,0 +1,12 @@
+[Unit]
+Description=Runs autorandr whenever the lid state changes
+
+[Service]
+Type=simple
+ExecStart=bash -c "stdbuf -oL libinput debug-events | egrep --line-buffered '^ event[0-9]+\s+SWITCH_TOGGLE\s' | while read line; do autorandr --batch --change --default default; done"
+Restart=always
+RestartSec=30
+SyslogIdentifier=autorandr
+
+[Install]
+WantedBy=multi-user.target