From dfa452536364225bc602232a7aa582f6f45f5b67 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 070a453..276a145 100644 --- a/README.md +++ b/README.md @@ -117,6 +117,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 @@ -125,4 +130,5 @@ The most useful one is `$AUTORANDR_CURRENT_PROFILE`. ## Changelog +* *2016-11-15* New script hook, `predetect` * *2016-10-03* Install a desktop file to `/etc/xdg/autostart` by default diff --git a/autorandr.py b/autorandr.py index 84fb3b3..81ae34a 100755 --- a/autorandr.py +++ b/autorandr.py @@ -729,6 +729,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_. @@ -748,8 +750,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) @@ -879,6 +884,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: