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
+ (?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
))+
\s*
(?P<modes>(?:
- [0-9]+x[0-9]+.+?\*current.+\s+h:.+\s+v:.+clock\s+(?P<rate>[0-9\.]+)Hz\s* | # Interesting (current) resolution: Extract rate
+ (?P<mode_width>[0-9]+)x(?P<mode_height>[0-9]+).+?\*current.+\s+
+ h:.+\s+v:.+clock\s+(?P<rate>[0-9\.]+)Hz\s* | # Interesting (current) resolution: Extract rate
[0-9]+x[0-9]+.+\s+h:.+\s+v:.+\s* # Other resolutions
)*)
"""
if not match["connected"]:
options["off"] = None
edid = None
+ elif not match["width"]:
+ options["off"] = None
+ edid = "".join(match["edid"].strip().split())
else:
- if match["rotate"] not in ("left", "right"):
- options["mode"] = "%sx%s" % (match["width"], match["height"])
+ if "mode_width" in match:
+ options["mode"] = "%sx%s" % (match["mode_width"], match["mode_height"])
else:
- options["mode"] = "%sx%s" % (match["height"], match["width"])
+ if match["rotate"] not in ("left", "right"):
+ options["mode"] = "%sx%s" % (match["width"], match["height"])
+ else:
+ 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"
transformation = ",".join(match["transform"].strip().split())
if transformation != "1.000000,0.000000,0.000000,0.000000,1.000000,0.000000,0.000000,0.000000,1.000000":
options["transform"] = transformation
+ if "mode_width" not in match:
+ # TODO We'd need to apply the reverse transformation here. Let's see if someone complains, I doubt that this
+ # special case is actually required.
+ print("Warning: Output %s has a transformation applied. Could not determine correct mode!", file=sys.stderr)
if match["gamma"]:
gamma = match["gamma"].strip()
if gamma != "1.0:1.0:1.0":
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"]
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 "
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