X-Git-Url: https://git.donarmstrong.com/?p=deb_pkgs%2Fautorandr.git;a=blobdiff_plain;f=autorandr.py;h=84fb3b356e86aee9d00ab601f1b381461a9c0df5;hp=548f3129767ab32b52b561dc4f0f2fd6ab4bfd79;hb=986e5cfaf68e695483c7d388e4ea093a28862445;hpb=bae286948aaeced03357adccfb14d1ce84a568d1 diff --git a/autorandr.py b/autorandr.py index 548f312..84fb3b3 100755 --- a/autorandr.py +++ b/autorandr.py @@ -72,7 +72,7 @@ Usage: autorandr [options] --debug enable verbose output --batch run autorandr for all users with active X11 sessions - To prevent a profile from being loaded, place a script call "block" in its + To prevent a profile from being loaded, place a script called "block" in its directory. The script is evaluated before the screen setup is inspected, and in case of it returning a value of 0 the profile is skipped. This can be used to query the status of a docking station you are about to leave. @@ -476,6 +476,17 @@ def load_profiles(profile_path): return profiles +def get_symlinks(profile_path): + "Load all symlinks from a directory" + + symlinks = {} + for link in os.listdir(profile_path): + file_name = os.path.join(profile_path, link) + if os.path.islink(file_name): + symlinks[link] = os.readlink(file_name) + + return symlinks + def find_profiles(current_config, profiles): "Find profiles matching the currently connected outputs" detected_profiles = [] @@ -843,6 +854,7 @@ def main(argv): return profiles = {} + profile_symlinks = {} try: # Load profiles from each XDG config directory # The XDG spec says that earlier entries should take precedence, so reverse the order @@ -850,6 +862,7 @@ def main(argv): system_profile_path = os.path.join(directory, "autorandr") if os.path.isdir(system_profile_path): profiles.update(load_profiles(system_profile_path)) + profile_symlinks.update(get_symlinks(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") @@ -858,11 +871,14 @@ def main(argv): 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)) + profile_symlinks.update(get_symlinks(profile_path)) # Sort by descending mtime profiles = OrderedDict(sorted(profiles.items(), key=lambda x: -x[1]["config-mtime"])) except Exception as e: raise AutorandrException("Failed to load profiles", e) + profile_symlinks = { k: v for k, v in profile_symlinks.items() if v in (x[0] for x in virtual_profiles) or v in profiles } + config, modes = parse_xrandr_output() if "--fingerprint" in options: @@ -965,6 +981,11 @@ def main(argv): load_profile = options["--default"] if load_profile: + if load_profile in profile_symlinks: + if "--debug" in options: + print("'%s' symlinked to '%s'" % (load_profile, profile_symlinks[load_profile])) + load_profile = profile_symlinks[load_profile] + if load_profile in ( x[0] for x in virtual_profiles ): load_config = generate_virtual_profile(config, modes, load_profile) scripts_path = os.path.join(profile_path, load_profile)