summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorMike Crute <crutem@amazon.com>2019-02-22 10:47:42 -0800
committerMike Crute <crutem@amazon.com>2019-03-21 15:17:31 -0700
commit367c9ac02a76b3d2b55a0e155828117c2386b231 (patch)
treeb4bb0d239d0f274992f2e70ac161c3a2b34e04e6 /bin
parentda42323622884cfcafeba9e3f848143bdaa96832 (diff)
downloaddotfiles-367c9ac02a76b3d2b55a0e155828117c2386b231.tar.bz2
dotfiles-367c9ac02a76b3d2b55a0e155828117c2386b231.tar.xz
dotfiles-367c9ac02a76b3d2b55a0e155828117c2386b231.zip
Rewrite enumerate-displays in python
Looking at the /sys filesystem gets the mapping wrong for some reason. XRandr sees DP-2-8 whereas /sys sees DP-5 or DP-3 (for which there are no physical analogs) and doesn't contain any file mapping the two. The long-term correct answer is to rewrite this in C and use the XRandr APIs directly but I need this to work right now for some presentations so Python it is.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/enumerate-displays91
1 files changed, 75 insertions, 16 deletions
diff --git a/bin/enumerate-displays b/bin/enumerate-displays
index 996a135..40aea68 100755
--- a/bin/enumerate-displays
+++ b/bin/enumerate-displays
@@ -1,21 +1,80 @@
1#!/bin/bash 1#!/usr/bin/env python3
2# 2#
3# Simple script to do all the ugly munging or connected displays on a Dell XPS 3# TODO: Rewrite this in C and just use the XRandr APIs directly
4# 13. Is used by a Lua function within Awesome that actually determines what to
5# do with those displays.
6# 4#
7 5
8for output in /sys/class/drm/card*-*; do 6import re
9 if [ "$(cat $output/status)" == "connected" ]; then 7import sys
10 card=$(basename $output); card=${card##card?-} 8import subprocess
11 edid=$(cat $output/edid | parse-edid 2>&1 | grep Identifier | cut -d '"' -f2)
12 edid_sum=$(md5sum -b $output/edid | cut -f1 -d' ')
13 9
14 # The EDID data is corrupt on the Dell XPS panels for some reason
15 if [ "$edid_sum" == "99030a11512deeb0371adf0a6c6a8a06" ] || [ "$edid_sum" == "31a6481b493cdfcd9e50c67290644eed" ]; then
16 edid="DELL_XPS_13"
17 fi
18 10
19 echo "$card:$edid" 11def is_host_xps():
20 fi 12 try:
21done 13 with open("/sys/class/dmi/id/product_name", "r") as fp:
14 product = fp.read()
15
16 return bool(re.match("XPS 13 93[78]0", product))
17 except FileNotFoundError:
18 return False
19
20
21def parse_edid(hex_list):
22 proc = subprocess.Popen(
23 ["parse-edid"], stdin=subprocess.PIPE, stdout=subprocess.PIPE,
24 stderr=subprocess.PIPE)
25
26 out, _ = proc.communicate(bytes.fromhex("".join(hex_list)))
27
28 identifier = re.findall(
29 '\tIdentifier "([^"]+)"\n',
30 out.decode("us-ascii", errors="backslashreplace"))
31
32 if identifier:
33 return identifier[0]
34 else:
35 return None
36
37
38def get_connected_displays():
39 out = subprocess.check_output(["xrandr", "--verbose", "--query"])
40
41 current_display = None
42 in_edid = False
43 current_edid = []
44
45 all_edids = {}
46
47 for line in out.decode("us-ascii").split("\n"):
48 if ' connected ' in line:
49 current_display = line.split(" ")[0]
50
51 if current_display and 'EDID:' in line:
52 in_edid = True
53 continue
54
55 if in_edid and line[:2] == "\t\t":
56 current_edid.append(line.strip())
57 elif in_edid and line[:2] != "\t\t":
58 all_edids[current_display] = parse_edid(current_edid)
59 in_edid = False
60 current_display = None
61 current_edid = []
62
63 return all_edids
64
65
66def main():
67 is_xps = is_host_xps()
68
69 for display, edid in get_connected_displays().items():
70 # The EDID data is corrupted on all Dell XPSes
71 if is_xps and display == "eDP-1":
72 edid = "DELL_XPS_13"
73
74 print("{display}:{edid}".format(**locals()))
75
76 return 0
77
78
79if __name__ == "__main__":
80 sys.exit(main())