]> git.donarmstrong.com Git - deb_pkgs/autorandr.git/commitdiff
Add script hook `predetect`, executed before invoking xrandr to detect the current...
authorPhillip Berndt <phillip.berndt@googlemail.com>
Tue, 15 Nov 2016 14:51:33 +0000 (15:51 +0100)
committerPhillip Berndt <phillip.berndt@googlemail.com>
Fri, 20 Jan 2017 14:14:15 +0000 (15:14 +0100)
See bug #61

README.md
autorandr.py

index b20d47e2f7e2e10eeeef6b0369d4b968870c2693..d08b78c4222cc4337ae24cb671ae358b13000eb3 100644 (file)
--- 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**
 
index a47282fece8e24eefeea1dc01c1f90f971b1c0b3..5082ebd08d6489e3d092766ec463dbb189af9ef7 100755 (executable)
@@ -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_<CAPITALIZED_KEY_HERE>.
 
@@ -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: