]> git.donarmstrong.com Git - deb_pkgs/autorandr.git/commitdiff
Merge pull request #248 from spiriou/master
authorPhillip Berndt <phillip.berndt@googlemail.com>
Thu, 16 Dec 2021 09:41:36 +0000 (10:41 +0100)
committerGitHub <noreply@github.com>
Thu, 16 Dec 2021 09:41:36 +0000 (10:41 +0100)
Add --match-edid option to match profiles based on edid

autorandr.1
autorandr.py
caca [new file with mode: 0644]
contrib/bash_completion/autorandr
contrib/zsh_completion/_autorandr

index 6ff816c465ab27d6142128a4fe17b4ff78c5fd63..d20264b920e3963db2fb3d21a95d9e558f297608 100644 (file)
@@ -53,6 +53,9 @@ Don't change anything, only print the xrandr commands
 .BR \-\-fingerprint
 Fingerprint the current hardware setup
 .TP
+.BR \-\-match-edid
+Match displays based on edid instead of name
+.TP
 .BR \-\-force
 Force loading or reloading of a profile
 .TP
index 7ad9736b136f516a7f0309a3b80b17f907b53809..24d8b3a9df0674291c91ac88756975fc08223315 100755 (executable)
@@ -85,6 +85,7 @@ Usage: autorandr [options]
 --detected              only list detected (available) configuration(s)
 --dry-run               don't change anything, only print the xrandr commands
 --fingerprint           fingerprint your current hardware setup
+--match-edid            match diplays based on edid instead of name
 --force                 force (re)loading of a profile / overwrite exiting files
 --list                  list configurations
 --skip-options <option> comma separated list of xrandr arguments (e.g. "gamma")
@@ -599,6 +600,36 @@ def match_asterisk(pattern, data):
     return matched * 1. / total
 
 
+def update_profiles_edid(profiles, config):
+    edid_map = {}
+    for c in config:
+        if config[c].edid is not None:
+            edid_map[config[c].edid] = c
+
+    for p in profiles:
+        profile_config = profiles[p]["config"]
+
+        for edid in edid_map:
+            for c in profile_config.keys():
+                if profile_config[c].edid != edid or c == edid_map[edid]:
+                    continue
+
+                print("%s: renaming display %s to %s" % (p, c, edid_map[edid]))
+
+                tmp_disp = profile_config[c]
+
+                if edid_map[edid] in profile_config:
+                    # Swap the two entries
+                    profile_config[c] = profile_config[edid_map[edid]]
+                    profile_config[c].output = c
+                else:
+                    # Object is reassigned to another key, drop this one
+                    del profile_config[c]
+
+                profile_config[edid_map[edid]] = tmp_disp
+                profile_config[edid_map[edid]].output = edid_map[edid]
+
+
 def find_profiles(current_config, profiles):
     "Find profiles matching the currently connected outputs, sorting asterisk matches to the back"
     detected_profiles = []
@@ -1217,7 +1248,7 @@ def main(argv):
         opts, args = getopt.getopt(argv[1:], "s:r:l:d:cfh",
                                    ["batch", "dry-run", "change", "cycle", "default=", "save=", "remove=", "load=",
                                     "force", "fingerprint", "config", "debug", "skip-options=", "help",
-                                    "list", "current", "detected", "version"])
+                                    "list", "current", "detected", "version", "match-edid"])
     except getopt.GetoptError as e:
         print("Failed to parse options: {0}.\n"
               "Use --help to get usage information.".format(str(e)),
@@ -1270,20 +1301,23 @@ def main(argv):
             profiles.update(load_profiles(profile_path))
             profile_symlinks.update(get_symlinks(profile_path))
             read_config(options, profile_path)
-        # Sort by mtime
-        sort_direction = -1
-        if "--cycle" in options:
-            # When cycling through profiles, put the profile least recently used to the top of the list
-            sort_direction = 1
-        profiles = OrderedDict(sorted(profiles.items(), key=lambda x: sort_direction * x[1]["config-mtime"]))
     except Exception as e:
         raise AutorandrException("Failed to load profiles", e)
 
-    profile_symlinks = {k: v for k, v in profile_symlinks.items() if v in (x[0] for x in virtual_profiles) or v in profiles}
-
     exec_scripts(None, "predetect")
     config, modes = parse_xrandr_output()
 
+    if "--match-edid" in options:
+        update_profiles_edid(profiles, config)
+
+    # Sort by mtime
+    sort_direction = -1
+    if "--cycle" in options:
+        # When cycling through profiles, put the profile least recently used to the top of the list
+        sort_direction = 1
+    profiles = OrderedDict(sorted(profiles.items(), key=lambda x: sort_direction * x[1]["config-mtime"]))
+    profile_symlinks = {k: v for k, v in profile_symlinks.items() if v in (x[0] for x in virtual_profiles) or v in profiles}
+
     if "--fingerprint" in options:
         output_setup(config, sys.stdout)
         sys.exit(0)
diff --git a/caca b/caca
new file mode 100644 (file)
index 0000000..e69de29
index 904ef8035e557e34a20b381d6a3ccbe9872b1418..0af11ec70834a7b2e0bdeb3a95f1f0a75d6c8ce2 100644 (file)
@@ -10,7 +10,7 @@ _autorandr ()
        prev="${COMP_WORDS[COMP_CWORD-1]}"
 
        opts="-h -c -s -r -l -d"
-       lopts="--help --change --cycle --save --remove --load --list --default --force --fingerprint --config --dry-run"
+       lopts="--help --change --cycle --save --remove --load --list --default --force --fingerprint  --match-edid --config --dry-run"
 
        # find system-level autorandr dirs
        OIFS="$IFS"
index 848f614aaaf646e594faac0ad7b9e31ee0a8d4a3..1667f0c560a75a030c9613e89a9b387468ed4991 100644 (file)
@@ -33,6 +33,7 @@ _autorandr () {
        --debug"[enable verbose output]" \
        --dry-run"[don't change anything]" \
        --fingerprint"[fingerprint current hardware]" \
+       --match-edid"[match displays using edid]" \
        --force"[force loading of a profile]" \
        --list"[list all profiles]" \
        --skip-options"[skip xrandr options]:xrandr options:_values -s , options gamma brightness panning transform primary mode pos rate" \