X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=autorandr.py;h=1e08e50c67ef8da6421739a20482ae5c8aa4d2b4;hb=d8eca8018138de26eae947a3f7357711a0b56d9c;hp=1339014c01cbfb2879fd654325bf0faec899a1c6;hpb=9fe52b370dc224ef80abac1e4baff60e3f6651a5;p=deb_pkgs%2Fautorandr.git diff --git a/autorandr.py b/autorandr.py index 1339014..1e08e50 100755 --- a/autorandr.py +++ b/autorandr.py @@ -4,7 +4,7 @@ # autorandr.py # Copyright (c) 2015, Phillip Berndt # -# Experimental autorandr rewrite in Python +# Autorandr rewrite in Python # # This script aims to be fully compatible with the original autorandr. # @@ -66,9 +66,10 @@ Usage: autorandr [options] To change this behaviour and switch to a fallback configuration, specify --default . - Another script called "postswitch "can be placed in the directory - ~/.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() @@ -123,7 +124,7 @@ class XrandrOutput(object): "gamma": "1.0:1.0:1.0", } - XRANDR_DEFAULTS = dict(XRANDR_13_DEFAULTS.items() + XRANDR_12_DEFAULTS.items()) + XRANDR_DEFAULTS = dict(list(XRANDR_13_DEFAULTS.items()) + list(XRANDR_12_DEFAULTS.items())) def __repr__(self): return "<%s%s %s>" % (self.output, (" %s..%s" % (self.edid[:5], self.edid[-5:])) if self.edid else "", " ".join(self.option_vector)) @@ -496,15 +497,21 @@ def main(argv): print(str(e)) options = { "--help": True } - profile_path = os.path.expanduser("~/.autorandr") - + 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)