From f171c8a5ad91dd586320d89c504c316d18f3d056 Mon Sep 17 00:00:00 2001 From: Phillip Berndt Date: Tue, 15 Nov 2016 15:51:33 +0100 Subject: [PATCH] Add script hook `predetect`, executed before invoking xrandr to detect the current config See bug #61 --- README.md | 6 ++++++ autorandr.py | 10 ++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b20d47e..d08b78c 100644 --- a/README.md +++ b/README.md @@ -122,6 +122,11 @@ about it. The same holds for `preswitch`, which is executed before the switch takes place, and `postsave`, which is executed after a profile was stored/altered. +If you experience issues with xrandr being executed too early after connecting +a new monitor, then you can create a script `predetect`, which will be executed +before autorandr attempts to run xrandr. Place e.g. `sleep 1` into that file +to make autorandr wait a second before running xrandr. + All scripts can also be placed in any of the `$XDG_CONFIG_DIRS`. In addition to the script names themselves, any executables in subdirectories named `script_name.d` (e.g. `postswitch.d`) are executed as well. In scripts, some of @@ -131,6 +136,7 @@ The most useful one is `$AUTORANDR_CURRENT_PROFILE`. ## Changelog * *2017-01-18* Accept comments (lines starting with `#`) in config/setup files +* *2017-01-20* New script hook, `predetect` **autorandr 1.0** diff --git a/autorandr.py b/autorandr.py index a47282f..5082ebd 100755 --- a/autorandr.py +++ b/autorandr.py @@ -744,6 +744,8 @@ def exec_scripts(profile_path, script_name, meta_information=None): and system-wide configuration folders, named script_name or residing in subdirectories named script_name.d. + If profile_path is None, only global scripts will be invoked. + meta_information is expected to be an dictionary. It will be passed to the block scripts in the environment, as variables called AUTORANDR_. @@ -763,8 +765,11 @@ def exec_scripts(profile_path, script_name, meta_information=None): if not os.path.isdir(user_profile_path): user_profile_path = os.path.join(os.environ.get("XDG_CONFIG_HOME", os.path.expanduser("~/.config")), "autorandr") - for folder in chain((profile_path, os.path.dirname(profile_path), user_profile_path), - (os.path.join(x, "autorandr") for x in os.environ.get("XDG_CONFIG_DIRS", "/etc/xdg").split(":"))): + candidate_directories = chain((user_profile_path,), (os.path.join(x, "autorandr") for x in os.environ.get("XDG_CONFIG_DIRS", "/etc/xdg").split(":"))) + if profile_path: + candidate_directories = chain((profile_path,), candidate_directories) + + for folder in candidate_directories: if script_name not in ran_scripts: script = os.path.join(folder, script_name) @@ -907,6 +912,7 @@ def main(argv): 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 } + exec_scripts(None, "predetect") config, modes = parse_xrandr_output() if "--fingerprint" in options: -- 2.39.2