]> git.donarmstrong.com Git - deb_pkgs/autorandr.git/blobdiff - autorandr.py
Keep outputs with edid when loading profiles
[deb_pkgs/autorandr.git] / autorandr.py
index c7aa86623b29503d9e60aad794543a159d5792c8..1be7e7bbd31763397e3507217d15a285db4a7f8d 100755 (executable)
@@ -83,12 +83,14 @@ class XrandrOutput(object):
             disconnected |
             unknown\ connection |
             (?P<connected>connected)\s+                                                 # If connected:
+            (?:
             (?P<primary>primary\ )?                                                     # Might be primary screen
             (?P<width>[0-9]+)x(?P<height>[0-9]+)                                        # Resolution (might be overridden below!)
             \+(?P<x>[0-9]+)\+(?P<y>[0-9]+)\s+                                           # Position
             (?:\(0x[0-9a-fA-F]+\)\s+)?                                                  # XID
             (?P<rotate>(?:normal|left|right|inverted))\s+                               # Rotation
             (?:(?P<reflect>X\ and\ Y|X|Y)\ axis)?                                       # Reflection
+            )?                                                                          # .. but everything of the above only if the screen is in use.
         ).*
         (?:\s*(?:                                                                       # Properties of the output
             Gamma: (?P<gamma>[0-9\.:\s]+) |                                             # Gamma value
@@ -191,6 +193,9 @@ class XrandrOutput(object):
         if not match["connected"]:
             options["off"] = None
             edid = None
+        elif not match["width"]:
+            options["off"] = None
+            edid = "".join(match["edid"].strip().split())
         else:
             if "mode_width" in match:
                 options["mode"] = "%sx%s" % (match["mode_width"], match["mode_height"])
@@ -201,6 +206,8 @@ class XrandrOutput(object):
                     options["mode"] = "%sx%s" % (match["height"], match["width"])
             if match["rotate"] != "normal":
                 options["rotate"] = match["rotate"]
+            if "primary" in match and match["primary"]:
+                options["primary"] = None
             if "reflect" in match:
                 if match["reflect"] == "X":
                     options["reflect"] = "x"
@@ -235,17 +242,17 @@ class XrandrOutput(object):
             if line:
                 line = line.split(None, 1)
                 options[line[0]] = line[1] if len(line) > 1 else None
-        if "off" in options:
+
+        if options["output"] in edid_map:
+            edid = edid_map[options["output"]]
+        elif "off" in options:
             edid = None
         else:
-            if options["output"] in edid_map:
-                edid = edid_map[options["output"]]
-            else:
-                fuzzy_edid_map = [ re.sub("(card[0-9]+|-)", "", x) for x in edid_map.keys() ]
-                fuzzy_output = re.sub("(card[0-9]+|-)", "", options["output"])
-                if fuzzy_output not in fuzzy_edid_map:
-                    raise RuntimeError("Failed to find a corresponding output in config/setup for output `%s'" % options["output"])
-                edid = edid_map[list(edid_map.keys())[fuzzy_edid_map.index(fuzzy_output)]]
+            fuzzy_edid_map = [ re.sub("(card[0-9]+|-)", "", x) for x in edid_map.keys() ]
+            fuzzy_output = re.sub("(card[0-9]+|-)", "", options["output"])
+            if fuzzy_output not in fuzzy_edid_map:
+                raise RuntimeError("Failed to find a corresponding output in config/setup for output `%s'" % options["output"])
+            edid = edid_map[list(edid_map.keys())[fuzzy_edid_map.index(fuzzy_output)]]
         output = options["output"]
         del options["output"]
 
@@ -278,6 +285,8 @@ def debug_regexp(pattern, string):
         bounds = ( 0, len(string) )
         while bounds[0] != bounds[1]:
             half = int((bounds[0] + bounds[1]) / 2)
+            if half == bounds[0]:
+                break
             bounds = (half, bounds[1]) if regex.search(pattern, string[:half], partial=True) else (bounds[0], half - 1)
         partial_length = bounds[0]
         return ("Regular expression matched until position "
@@ -331,7 +340,7 @@ def load_profiles(profile_path):
                 buffer.append(line)
 
         for output_name in list(config.keys()):
-            if "off" in config[output_name].options:
+            if config[output_name].edid is None:
                 del config[output_name]
 
         profiles[profile] = config