]> git.donarmstrong.com Git - deb_pkgs/autorandr.git/blobdiff - autorandr.py
Version bump: 1.9
[deb_pkgs/autorandr.git] / autorandr.py
index a2ac5446ab4f33cff337b73fa52db8fd3cf65b7b..aa1be0b28d04f340504687898e2511139b06d33b 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
@@ -48,7 +49,7 @@ if sys.version_info.major == 2:
 else:
     import configparser
 
-__version__ = "1.8.1"
+__version__ = "1.9"
 
 try:
     input = raw_input
@@ -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
 
 
@@ -619,9 +638,9 @@ def save_configuration(profile_path, profile_name, configuration, forced=False):
     if os.path.isfile(setup_path) and not forced:
         raise AutorandrException('Refusing to overwrite config "{}" without passing "--force"!'.format(profile_name))
 
-    with open(os.path.join(profile_path, "config"), "w") as config:
+    with open(config_path, "w") as config:
         output_configuration(configuration, config)
-    with open(os.path.join(profile_path, "setup"), "w") as setup:
+    with open(setup_path, "w") as setup:
         output_setup(configuration, setup)
 
 
@@ -1233,11 +1252,10 @@ def main(argv):
                 "PROFILE_FOLDER": profile_folder,
                 "MONITORS": ":".join(enabled_monitors(config)),
             })
+        except AutorandrException as e:
+            raise e
         except Exception as e:
-            if isinstance(e, AutorandrException):
-                raise e
-            else:
-                raise AutorandrException("Failed to save current configuration as profile '%s'" % (options["--save"],), e)
+            raise AutorandrException("Failed to save current configuration as profile '%s'" % (options["--save"],), e)
         print("Saved current configuration as profile '%s'" % options["--save"])
         sys.exit(0)