From 54abf9d6f1b712fd40279230f4e8e6cfce8ea54a Mon Sep 17 00:00:00 2001 From: Phillip Berndt Date: Thu, 16 Dec 2021 10:14:19 +0100 Subject: [PATCH] Fix mtime updating for --cycle 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 | 1 + autorandr.py | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b4740af..e53f999 100644 --- 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 diff --git a/autorandr.py b/autorandr.py index 9f1f557..7ad9736 100755 --- a/autorandr.py +++ b/autorandr.py @@ -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: -- 2.39.2