]> git.donarmstrong.com Git - deb_pkgs/autorandr.git/commitdiff
Treating a closed lid as disconnected
authorChristophe-Marie Duquesne <chmd@chmd.fr>
Thu, 31 Oct 2019 23:46:19 +0000 (00:46 +0100)
committerChristophe-Marie Duquesne <chmd@chmd.fr>
Thu, 31 Oct 2019 23:46:19 +0000 (00:46 +0100)
autorandr.py

index 44e9ad2595df97b5dd5a9b8e16c917e3e3cbedc6..963303e38c0181dcdd89d54e2f8b528be495587c 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
@@ -311,7 +324,7 @@ class XrandrOutput(object):
                 raise AutorandrException("Parsing XRandR output failed, couldn't find any display modes", report_bug=True)
 
         options = {}
-        if not match["connected"]:
+        if not match["connected"] or is_closed_lid(match["output"]):
             edid = None
         elif match["edid"]:
             edid = "".join(match["edid"].strip().split())