]> git.donarmstrong.com Git - deb_pkgs/autorandr.git/blobdiff - autorandr.py
Follow XDG completely: Also load configurations from the system-wide directories
[deb_pkgs/autorandr.git] / autorandr.py
index e79aefbc72470cf130f8aa74ce9f7e7883162574..1e08e50c67ef8da6421739a20482ae5c8aa4d2b4 100755 (executable)
@@ -66,9 +66,10 @@ Usage: autorandr [options]
  To change this behaviour and switch to a fallback configuration, specify
  --default <profile>.
 
- Another script called "postswitch "can be placed in the directory
- ~/.config/autorandr as well as in any profile directories: The scripts are executed
- after a mode switch has taken place and can notify window managers.
+ Another script called "postswitch" can be placed in the directory
+ ~/.config/autorandr (or ~/.autorandr if you have an old installation) as well
+ as in any profile directories: The scripts are executed after a mode switch
+ has taken place and can notify window managers.
 
  The following virtual configurations are available:
 """.strip()
@@ -496,19 +497,21 @@ def main(argv):
         print(str(e))
         options = { "--help": True }
 
-    profile_dir = os.path.expanduser("~/.autorandr")
-    if not os.path.isdir(profile_dir):
-        profile_dir = os.path.join(os.environ.get("XDG_CONFIG_HOME", os.path.expanduser("~/.config")), "autorandr")
-
-    profile_path = os.path.join(profile_dir, "profiles")
-
+    profiles = {}
     try:
-        profiles = load_profiles(profile_path)
-    except OSError as e:
-        if e.errno == 2: # No such file or directory
-            profiles = {}
-        else:
-            raise e
+        # 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))
     except Exception as e:
         print("Failed to load profiles:\n%s" % str(e), file=sys.stderr)
         sys.exit(1)