diff options
author | Tom Smeding <t.j.smeding@uu.nl> | 2022-03-30 12:38:59 +0200 |
---|---|---|
committer | Tom Smeding <t.j.smeding@uu.nl> | 2022-03-30 12:38:59 +0200 |
commit | bd2289bcae0a2f54949896a77527caacd222d2fc (patch) | |
tree | dbbabf36fdc18e53441f5396be0b1debeb7da51b | |
parent | 7db269e67821fea857b83e514aa9d77371b89972 (diff) |
-rwxr-xr-x | display-manager.py | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/display-manager.py b/display-manager.py index 49c631d..78d3fec 100755 --- a/display-manager.py +++ b/display-manager.py @@ -26,10 +26,11 @@ def current_setup(): if re.match(r"Screen [0-9]+:", line) is not None: continue else: - walk_display = line[:line.index(" ")] + walk_display, connected, *_ = line.split(" ") displays[walk_display] = { "current": None, - "preferred": None + "preferred": None, + "connected": connected == "connected" } elif indent == 2: continue @@ -59,16 +60,20 @@ def iter_find(l, predicate): if predicate(x): return x return None -def is_internal_display(name): +def is_internal_display(name, display): + if not display["connected"]: return False return name.startswith("eDP") -def is_external_display(name): - return name.startswith("HDMI") +def is_external_display(name, display): + if not display["connected"]: return False + return name.startswith("HDMI") or name.startswith("DP-") + +def uncurry(f): return lambda p: f(*p) def main(): setup = current_setup() - def props_for_name(name): + def props_for_name(name, display): nonlocal setup current = False if name is None else setup[name]["current"] is not None formatted = "<none>" if name is None else name + (" (enabled)" if current else "") @@ -78,18 +83,18 @@ def main(): "current": current } - internal = props_for_name(iter_find(setup.keys(), is_internal_display)) - external = props_for_name(iter_find(setup.keys(), is_external_display)) + internal = uncurry(props_for_name)(iter_find(setup.items(), uncurry(is_internal_display))) + external = uncurry(props_for_name)(iter_find(setup.items(), uncurry(is_external_display))) assert internal["name"] is not None assert internal["name"] != external["name"] - other_displays = [setup[name]["formatted"] for name in setup.keys() + other_displays = [name for name in setup.keys() if name not in [internal["name"], external["name"]]] message = "{} displays connected:\n- internal: {}\n- external: {}".format( len(setup.keys()), internal["formatted"], external["formatted"]) if len(other_displays) > 0: - message += "\n- unknown: {}".format(other_displays.join(", ")) + message += "\n- unknown: {}".format(", ".join(other_displays)) options = { "Only internal": ["--output", internal["name"], "--auto", "--output", external["name"], "--off"], |