]> git.donarmstrong.com Git - deb_pkgs/autorandr.git/commitdiff
New upstream version 1.6 upstream/1.6
authorDon Armstrong <don@donarmstrong.com>
Thu, 2 Aug 2018 02:32:54 +0000 (19:32 -0700)
committerDon Armstrong <don@donarmstrong.com>
Thu, 2 Aug 2018 02:32:54 +0000 (19:32 -0700)
README.md
autorandr.py
contrib/bash_completion/autorandr
contrib/systemd/autorandr.service
setup.py

index 999f353ceca200629b7ce82493925abba53bf65a..27cb2893e8a7e7e51f0642a13da9aaa69535b5f0 100644 (file)
--- a/README.md
+++ b/README.md
@@ -38,6 +38,7 @@ Contributors to this version of autorandr are:
 * Adrián López
 * andersonjacob
 * Alexander Wirt
+* Brice Waegeneire
 * Chris Dunder
 * Christoph Gysin
 * Daniel Hahler
@@ -189,7 +190,11 @@ If you switch back from `docked` to `mobile`, `~/.config/autorandr/postswitch`
 is executed instead of the `mobile` specific `postswitch`.
 
 In these scripts, some of autorandr's state is exposed as environment variables
-prefixed with `AUTORANDR_`. The most useful one is `$AUTORANDR_CURRENT_PROFILE`.
+prefixed with `AUTORANDR_`, such as:
+- `AUTORANDR_CURRENT_PROFILE`
+- `AUTORANDR_CURRENT_PROFILES`
+- `AUTORANDR_PROFILE_FOLDER`
+- `AUTORANDR_MONITORS`
 
 If you experience issues with xrandr being executed too early after connecting
 a new monitor, then you can use a `predetect` script to delay the execution.
@@ -205,6 +210,15 @@ profiles matching multiple (or any) monitors.
 
 ## Changelog
 
+**autorandr 1.6**
+
+* *2018-04-19* Bugfix: Do not load default profile unless --change is set
+* *2018-04-30* Added a `AUTORANDR_MONITORS` variable to hooks (by @bricewge, #106)
+* *2018-06-29* Fix detection of current configuration if extra monitors are active
+* *2018-07-11* Bugfix in the latest change: Correctly handle "off" minitors when comparing
+* *2018-07-19* Do not kill spawned user processes from systemd unit
+* *2018-07-20* Correctly handle "off" minitors when comparing -- fixup for another bug.
+
 **autorandr 1.5**
 
 * *2018-01-03* Add --version
index 5a0a6860fea0c82bf72e1521781cbd06513f71a4..4187932632c1bb008c3d88cad62a31f1f1912611 100755 (executable)
@@ -48,7 +48,7 @@ if sys.version_info.major == 2:
 else:
     import configparser
 
-__version__ = "1.5"
+__version__ = "1.6"
 
 try:
     input = raw_input
@@ -68,7 +68,7 @@ help_text = """
 Usage: autorandr [options]
 
 -h, --help              get this small help
--c, --change            reload current setup
+-c, --change            automatically load the first detected profile
 -d, --default <profile> make profile <profile> the default profile
 -l, --load <profile>    load profile <profile>
 -s, --save <profile>    save your current setup to profile <profile>
@@ -631,6 +631,35 @@ def call_and_retry(*args, **kwargs):
     return retval
 
 
+def get_fb_dimensions(configuration):
+    width = 0
+    height = 0
+    for output in configuration.values():
+        if "off" in output.options or not output.edid:
+            continue
+        # This won't work with all modes -- but it's a best effort.
+        o_width, o_height = map(int, output.options["mode"].split("x"))
+        if "transform" in output.options:
+            a, b, c, d, e, f, g, h, i = map(float, output.options["transform"].split(","))
+            w = (g * o_width + h * o_height + i)
+            x = (a * o_width + b * o_height + c) / w
+            y = (d * o_width + e * o_height + f) / w
+            o_width, o_height = x, y
+        if "pos" in output.options:
+            o_left, o_top = map(int, output.options["pos"].split("x"))
+            o_width += o_left
+            o_height += o_top
+        if "panning" in output.options:
+            match = re.match("(?P<w>[0-9]+)x(?P<h>[0-9]+)(?:\+(?P<x>[0-9]+))?(?:\+(?P<y>[0-9]+))?.*", output.options["panning"])
+            if match:
+                detail = match.groupdict()
+                o_width = int(detail.get("w")) + int(detail.get("x", "0"))
+                o_height = int(detail.get("h")) + int(detail.get("y", "0"))
+        width = max(width, o_width)
+        height = max(height, o_height)
+    return int(width), int(height)
+
+
 def apply_configuration(new_configuration, current_configuration, dry_run=False):
     "Apply a configuration"
     outputs = sorted(new_configuration.keys(), key=lambda x: new_configuration[x].sort_key)
@@ -659,6 +688,13 @@ def apply_configuration(new_configuration, current_configuration, dry_run=False)
     #   explicitly, so avoid it unless necessary.
     #   (See https://github.com/phillipberndt/autorandr/issues/72)
 
+    fb_dimensions = get_fb_dimensions(new_configuration)
+    try:
+        base_argv += ["--fb", "%dx%d" % fb_dimensions]
+    except:
+        # Failed to obtain frame-buffer size. Doesn't matter, xrandr will choose for the user.
+        pass
+
     auxiliary_changes_pre = []
     disable_outputs = []
     enable_outputs = []
@@ -719,10 +755,24 @@ def apply_configuration(new_configuration, current_configuration, dry_run=False)
 
 
 def is_equal_configuration(source_configuration, target_configuration):
-    "Check if all outputs from target are already configured correctly in source"
+    """
+        Check if all outputs from target are already configured correctly in source and
+        that no other outputs are active.
+    """
     for output in target_configuration.keys():
-        if (output not in source_configuration) or (source_configuration[output] != target_configuration[output]):
-            return False
+        if "off" in target_configuration[output].options:
+            if (output in source_configuration and "off" not in source_configuration[output].options):
+                return False
+        else:
+            if (output not in source_configuration) or (source_configuration[output] != target_configuration[output]):
+                return False
+    for output in source_configuration.keys():
+        if "off" in source_configuration[output].options:
+            if output in target_configuration and "off" not in target_configuration[output].options:
+                return False
+        else:
+            if output not in target_configuration:
+                return False
     return True
 
 
@@ -1023,6 +1073,15 @@ def dispatch_call_to_sessions(argv):
             X11_displays_done.add(display)
 
 
+def enabled_monitors(config):
+    monitors = []
+    for monitor in config:
+        if "--off" in config[monitor].option_vector:
+            continue
+        monitors.append(monitor)
+    return monitors
+
+
 def read_config(options, directory):
     """Parse a configuration config.ini from directory and merge it into
     the options dictionary"""
@@ -1125,7 +1184,11 @@ def main(argv):
         try:
             profile_folder = os.path.join(profile_path, options["--save"])
             save_configuration(profile_folder, config)
-            exec_scripts(profile_folder, "postsave", {"CURRENT_PROFILE": options["--save"], "PROFILE_FOLDER": profile_folder})
+            exec_scripts(profile_folder, "postsave", {
+                "CURRENT_PROFILE": options["--save"],
+                "PROFILE_FOLDER": profile_folder,
+                "MONITORS": ":".join(enabled_monitors(config)),
+            })
         except Exception as e:
             raise AutorandrException("Failed to save current configuration as profile '%s'" % (options["--save"],), e)
         print("Saved current configuration as profile '%s'" % options["--save"])
@@ -1207,7 +1270,7 @@ def main(argv):
 
     if "-d" in options:
         options["--default"] = options["-d"]
-    if not load_profile and "--default" in options:
+    if not load_profile and "--default" in options and ("-c" in options or "--change" in options):
         load_profile = options["--default"]
 
     if load_profile:
@@ -1245,6 +1308,7 @@ def main(argv):
                 script_metadata = {
                     "CURRENT_PROFILE": load_profile,
                     "PROFILE_FOLDER": scripts_path,
+                    "MONITORS": ":".join(enabled_monitors(load_config)),
                 }
                 exec_scripts(scripts_path, "preswitch", script_metadata)
                 if "--debug" in options:
index a106b7e2ff3bb3ed82edf3a7f31571dacd2cb189..e7f098c1b4474db3596c2e659fbf74e80b469feb 100644 (file)
@@ -1,8 +1,9 @@
 # autorandr/auto-disper completion by Maciej 'macieks' Sitarz <macieks@freesco.pl>
+# XDG additions and service dir filtering by Vladimir-csp
 
 _autorandr ()
 {
-       local cur prev opts lopts prfls
+       local cur prev opts lopts prfls AR_DIRS OIFS
 
        COMPREPLY=()
        cur="${COMP_WORDS[COMP_CWORD]}"
@@ -10,10 +11,27 @@ _autorandr ()
 
        opts="-h -c -s -r -l -d"
        lopts="--help --change --save --remove --load --default --force --fingerprint --config --dry-run"
-       if [ -d ~/.autorandr ]; then
-               prfls="`find ~/.autorandr/* -maxdepth 1 -type d -printf '%f\n'`"
-       elif [ -d ~/.config/autorandr ]; then
-               prfls="`find ~/.config/autorandr/* -maxdepth 1 -type d -printf '%f\n'`"
+
+       # find system-level autorandr dirs
+       OIFS="$IFS"
+       IFS=':'
+               for DIR in ${XDG_CONFIG_DIRS:-/etc/xdg}
+               do
+                       IFS="$OIFS"
+                       [ -d "$DIR/autorandr" ] && AR_DIRS=( "${AR_DIRS[@]}" "$DIR/autorandr" )
+               done
+       IFS="$OIFS"
+
+       # find user-level autorandr dir
+       if [ -d "$HOME/.autorandr" ]; then
+               AR_DIRS=( "${AR_DIRS[@]}" "$HOME/.autorandr" )
+       elif [ -d "${XDG_CONFIG_HOME:-$HOME/.config}/autorandr/" ]; then
+               AR_DIRS=( "${AR_DIRS[@]}" "${XDG_CONFIG_HOME:-$HOME/.config}/autorandr/" )
+       fi
+
+       if [ -n "${AR_DIRS}" ]
+       then
+               prfls="$(find "${AR_DIRS[@]}" -mindepth 1 -maxdepth 1 -type d ! -name "*.d" -printf '%f\n' | sort -u)"
        else
                prfls=""
        fi
index d270c5e68e7c4caee09711ef8e3227b39409b8ba..20277f9a66f5d343168cf6bdd6938012538d1e13 100644 (file)
@@ -11,6 +11,7 @@ StartLimitBurst=1
 ExecStart=/usr/bin/autorandr --batch --change --default default
 Type=oneshot
 RemainAfterExit=false
+KillMode=process
 
 [Install]
 WantedBy=sleep.target
index 28562ec3d805080c65b4088b98dc18b390b37156..4309c15fe3e3e4b306612b0bbaa204c037d097df 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -9,7 +9,7 @@ except:
 setup(
     name='autorandr',
 
-    version='1.5-1',
+    version='1.6-1',
 
     description='Automatically select a display configuration based on connected devices',
     long_description=long_description,