]> git.donarmstrong.com Git - deb_pkgs/autorandr.git/commitdiff
Fix mtime updating for --cycle
authorPhillip Berndt <phillip.berndt@googlemail.com>
Thu, 16 Dec 2021 09:14:19 +0000 (10:14 +0100)
committerPhillip Berndt <phillip.berndt@googlemail.com>
Thu, 16 Dec 2021 09:14:19 +0000 (10:14 +0100)
mtime updating resulted in --cycle always switching between the two most
recently used profiles. Invert the sort order if --cycle is in use to
mitigate.

See #244

README.md
autorandr.py

index b4740afd23cedb4b5d0c45ca8e3454148cedae20..e53f999c921946d7c06daaacafa697401c471294 100644 (file)
--- a/README.md
+++ b/README.md
@@ -251,6 +251,7 @@ options nvidia_drm modeset=1
 
 **autorandr 1.12**
 * *2021-12-16* Switch default interpreter to Python 3
+* *2021+12-16* Add `--list` to list all profiles
 
 **autorandr 1.11**
 * *2020-05-23* Handle empty sys.executable
index 9f1f557baf14f82241cd50538e047f535f12a19d..7ad9736b136f516a7f0309a3b80b17f907b53809 100755 (executable)
@@ -1270,8 +1270,12 @@ 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"]))
+        # 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)
 
@@ -1426,7 +1430,7 @@ def main(argv):
                 scripts_path = profile["path"]
             except KeyError:
                 raise AutorandrException("Failed to load profile '%s': Profile not found" % load_profile)
-            if load_profile in detected_profiles and detected_profiles[0] != load_profile:
+            if "--dry-run" not in options:
                 update_mtime(os.path.join(scripts_path, "config"))
         add_unused_outputs(config, load_config)
         if load_config == dict(config) and "-f" not in options and "--force" not in options: