Add edid modelines to xrandr facts

This commit is contained in:
Alexander Grothe 2019-01-07 21:32:08 +01:00
parent 58859dd8d7
commit a4dcadabcf

View File

@ -195,6 +195,7 @@ def parse_xrandr_verbose(iterator):
def parse_edid_data(edid): def parse_edid_data(edid):
vendor = "Unknown" vendor = "Unknown"
model = "Unknown" model = "Unknown"
modelines = []
try: try:
data = subprocess.check_output("parse-edid < {}".format(edid), data = subprocess.check_output("parse-edid < {}".format(edid),
shell=True, universal_newlines=True) shell=True, universal_newlines=True)
@ -202,11 +203,25 @@ def parse_edid_data(edid):
pass pass
else: else:
for line in data.splitlines(): for line in data.splitlines():
line = line.strip()
if "VendorName" in line: if "VendorName" in line:
vendor = line.strip().split('"')[1] vendor = line.split('"')[1]
if "ModelName" in line: if "ModelName" in line:
model = line.strip().split('"')[1] model = line.split('"')[1]
return vendor, model if "Modeline" in line:
print(line)
_, _, line = line.split('"', 2)
FF, H1, H2, H3, H4, V1, V2, V3, V4, FLAGS = line.split(None, 9)
print(FF, H1, H2, H3, H4, V1, V2, V3, V4, FLAGS)
refresh = round(float(FF) * 1E6 / (float(H4) * float(V4)))
interlaced = "interlaced" in FLAGS
if interlaced:
refresh /= 2
refresh = int(refresh)
modeline_name = '"{}x{}_{}{}"'.format(H1, V1, refresh, "i" if interlaced else '')
modelines.append(" ".join(("Modeline", modeline_name,
FF, H1, H2, H3, H4, V1, V2, V3, V4, FLAGS)))
return vendor, model, modelines
def collect_nvidia_data(): def collect_nvidia_data():
@ -283,8 +298,8 @@ def find_drm_connectors(primary):
if connected and xrandr_edid_bytes: if connected and xrandr_edid_bytes:
drm_edid = os.path.join(os.path.dirname(status_p), 'edid') drm_edid = os.path.join(os.path.dirname(status_p), 'edid')
try: try:
with open(drm_edid, 'rb') as f: with open(drm_edid, 'rb') as f:
is_primary = f.read() == xrandr_edid_bytes is_primary = f.read() == xrandr_edid_bytes
except IOError: except IOError:
continue continue
else: else:
@ -319,7 +334,7 @@ def output_data(data, write_edids=True):
gpu_name = None gpu_name = None
bus_id = None bus_id = None
def create_entry(my_dict, name, connector, resolution, refreshrate, vendor, model): def create_entry(my_dict, name, connector, resolution, refreshrate, vendor, model, modelines):
my_dict[name] = { my_dict[name] = {
'connector': connector, 'connector': connector,
'resolution': resolution, 'resolution': resolution,
@ -328,15 +343,16 @@ def output_data(data, write_edids=True):
'mode': "{}_{}".format(resolution, refreshrate), 'mode': "{}_{}".format(resolution, refreshrate),
'vendor': vendor, 'vendor': vendor,
'model': model, 'model': model,
'modelines': modelines,
} }
if gpu_name and bus_id: if gpu_name and bus_id:
result[name]['gpu_name'] = gpu_name result[name]['gpu_name'] = gpu_name
result[name]['bus_id'] = bus_id result[name]['bus_id'] = bus_id
connector_0, resolution_0, refreshrate_0 = max(modes, key=sort_mode)[:3] connector_0, resolution_0, refreshrate_0 = max(modes, key=sort_mode)[:3]
vendor_0, model_0 = parse_edid_data('/etc/X11/edid.{}.bin'.format(connector_0)) vendor_0, model_0, modelines_0 = parse_edid_data('/etc/X11/edid.{}.bin'.format(connector_0))
create_entry(result, 'primary', connector_0, resolution_0, create_entry(result, 'primary', connector_0, resolution_0,
refreshrate_0, vendor_0, model_0) refreshrate_0, vendor_0, model_0, modelines_0)
if write_edids: if write_edids:
drm = find_drm_connectors(Connector(connector_0, drm = find_drm_connectors(Connector(connector_0,
@ -346,9 +362,9 @@ def output_data(data, write_edids=True):
other_modes = [mode for mode in modes if mode[0] != connector_0] other_modes = [mode for mode in modes if mode[0] != connector_0]
if other_modes: if other_modes:
connector_1, resolution_1, refreshrate_1 = max(other_modes, key=sort_mode)[:3] connector_1, resolution_1, refreshrate_1 = max(other_modes, key=sort_mode)[:3]
vendor_1, model_1 = parse_edid_data('/etc/X11/edid.{}.bin'.format(connector_1)) vendor_1, model_1, modelines_1 = parse_edid_data('/etc/X11/edid.{}.bin'.format(connector_1))
create_entry(result, 'secondary', connector_1, resolution_1, create_entry(result, 'secondary', connector_1, resolution_1,
refreshrate_1, vendor_1, model_1) refreshrate_1, vendor_1, model_1, modelines_1)
module.exit_json(changed=True if write_edids else False, module.exit_json(changed=True if write_edids else False,
ansible_facts={'xrandr': data, 'xorg': result, 'drm': drm}) ansible_facts={'xrandr': data, 'xorg': result, 'drm': drm})