+ # Load profiles from each XDG config directory
+ for directory in os.environ.get("XDG_CONFIG_DIRS", "").split(":"):
+ system_profile_path = os.path.join(directory, "autorandr")
+ if os.path.isdir(system_profile_path):
+ profiles.update(load_profiles(system_profile_path))
+ # For the user's profiles, prefer the legacy ~/.autorandr if it already exists
+ # profile_path is also used later on to store configurations
+ profile_path = os.path.expanduser("~/.autorandr")
+ if not os.path.isdir(profile_path):
+ # Elsewise, follow the XDG specification
+ profile_path = os.path.join(os.environ.get("XDG_CONFIG_HOME", os.path.expanduser("~/.config")), "autorandr")
+ if os.path.isdir(profile_path):
+ profiles.update(load_profiles(profile_path))
+ # Sort by descending mtime
+ profiles = OrderedDict(sorted(profiles.items(), key=lambda x: -x[1]["config-mtime"]))