]> git.donarmstrong.com Git - deb_pkgs/autorandr.git/commitdiff
Add an option to match profiles based on edid
authorSimon Piriou <spiriou31@gmail.com>
Mon, 17 May 2021 09:52:46 +0000 (11:52 +0200)
committerSimon Piriou <spiriou31@gmail.com>
Mon, 17 May 2021 19:14:40 +0000 (21:14 +0200)
In some cases the display names change so the profile matching fails.
This commit introduces the "--match-edid" option, that allows one to
specify that the profiles matching should be done based on display edid.

This is done by updating the profiles after loading, based on current
display name/edid mapping requested using xrandr.

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

index d268822bba5ba0a11cd2661ccdcc1c8ae623526b..698ac7c3fe70e768f512b467593e768d1c773640 100644 (file)
@@ -50,6 +50,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 25b0f53d79cfd7ab55580a0de370ff50bad5963b..6ebd55261bf83d503acf5f1257ff05426b892411 100755 (executable)
@@ -80,6 +80,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
 --skip-options <option> comma separated list of xrandr arguments (e.g. "gamma")
                         to skip both in detecting changes and applying a profile
@@ -593,6 +594,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 = []
@@ -1211,7 +1242,7 @@ def main(argv):
         opts, args = getopt.getopt(argv[1:], "s:r:l:d:cfh",
                                    ["batch", "dry-run", "change", "default=", "save=", "remove=", "load=",
                                     "force", "fingerprint", "config", "debug", "skip-options=", "help",
-                                    "current", "detected", "version"])
+                                    "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)),
@@ -1264,16 +1295,19 @@ def main(argv):
             profiles.update(load_profiles(profile_path))
             profile_symlinks.update(get_symlinks(profile_path))
             read_config(options, profile_path)
-        # Sort by descending mtime
-        profiles = OrderedDict(sorted(profiles.items(), key=lambda x: -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 descending mtime
+    profiles = OrderedDict(sorted(profiles.items(), key=lambda x: -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 03beabe9f2f87bdebe2e96f3f8e0bc8519dd24c1..f7bef4f2bdb479469939b3fa0d6d78d3eee608d4 100644 (file)
@@ -10,7 +10,7 @@ _autorandr ()
        prev="${COMP_WORDS[COMP_CWORD-1]}"
 
        opts="-h -c -s -r -l -d"
-       lopts="--help --change --save --remove --load --default --force --fingerprint --config --dry-run"
+       lopts="--help --change --save --remove --load --default --force --fingerprint --match-edid --config --dry-run"
 
        # find system-level autorandr dirs
        OIFS="$IFS"
index b6cacbb1d3ad42807d6e06e9ed175705d45af424..e17fc00e275b9b51672d52cb640fc589b7975282 100644 (file)
@@ -32,6 +32,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]" \
        --skip-options"[skip xrandr options]:xrandr options:_values -s , options gamma brightness panning transform primary mode pos rate" \
        --version"[show version]"