]> git.donarmstrong.com Git - deb_pkgs/autorandr.git/commitdiff
New upstream version 1.9 upstream/1.9
authorDon Armstrong <don@donarmstrong.com>
Sat, 22 Feb 2020 02:37:03 +0000 (18:37 -0800)
committerDon Armstrong <don@donarmstrong.com>
Sat, 22 Feb 2020 02:37:03 +0000 (18:37 -0800)
README.md
autorandr.1
autorandr.py
contrib/etc/xdg/autostart/autorandr-lid-listener.desktop [new file with mode: 0644]
contrib/listen_lid.sh [new file with mode: 0755]
contrib/systemd/autorandr-lid-listener.service [new file with mode: 0644]
setup.py

index bf81fa4576f27caae190a0d5f2a00ec3b39d475e..6c57b104575e5a245d84e4f2d7ff346c3e3ed8c1 100644 (file)
--- a/README.md
+++ b/README.md
@@ -41,6 +41,7 @@ Contributors to this version of autorandr are:
 * Brice Waegeneire
 * Chris Dunder
 * Christoph Gysin
+* Christophe-Marie Duquesne
 * Daniel Hahler
 * Maciej Sitarz
 * Mathias Svensson
@@ -153,7 +154,7 @@ candidate for doing that is `skip-options`, if you need it.
 
 ### Hook scripts
 
-Three more scripts can be placed in the configuration directory (as 
+Three more scripts can be placed in the configuration directory
 (as defined by the [XDG spec](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html),
 usually `~/.config/autorandr` or `~/.autorandr` if you have an old installation
 for user configuration and `/etc/xdg/autorandr` for system wide configuration):
@@ -213,8 +214,13 @@ profiles matching multiple (or any) monitors.
 
 ## Changelog
 
-**autorandr 1.9 (dev)**
+**autorandr 1.9**
 
+* *2019-11-10* Count closed lids as disconnected outputs
+* *2019-10-05* Do not overwrite existing configurations without `--force`
+* *2019-08-16* Accept modes that don't match the WWWxHHH pattern
+* *2019-03-22* Improve bash autocompletion
+* *2019-03-21* Store CRTC values in configurations
 * *2019-03-24* Fix handling of recently disconnected outputs (See #128 and #143)
 
 **autorandr 1.8.1**
index 2b2206a076b1fd966bf1322c1bf68d4bf1a74cec..d268822bba5ba0a11cd2661ccdcc1c8ae623526b 100644 (file)
@@ -63,7 +63,7 @@ Show version information and exit
 .br
 See https://github.com/phillipberndt/autorandr for a full list of contributors. 
 .SH REPORTING BUGS
-\fRReport issues upstream on GitHub:  https://githb.com/phillipberndt/autorandr/issues
+\fRReport issues upstream on GitHub:  https://github.com/phillipberndt/autorandr/issues
 .br
 \fRPlease attach the output of \fBxrandr --verbose\fR to your bug report if appropriate.
 .SH SEE ALSO
index cc1a25a0a40fd383c528538e075afdff581a674a..aa1be0b28d04f340504687898e2511139b06d33b 100755 (executable)
@@ -37,6 +37,7 @@ import subprocess
 import sys
 import shutil
 import time
+import glob
 
 from collections import OrderedDict
 from distutils.version import LooseVersion as Version
@@ -48,7 +49,7 @@ if sys.version_info.major == 2:
 else:
     import configparser
 
-__version__ = "1.8.1"
+__version__ = "1.9"
 
 try:
     input = raw_input
@@ -80,7 +81,7 @@ Usage: autorandr [options]
 --detected              only list detected (available) configuration(s)
 --dry-run               don't change anything, only print the xrandr commands
 --fingerprint           fingerprint your current hardware setup
---force                 force (re)loading of a profile
+--force                 force (re)loading of a profile / overwrite exiting files
 --skip-options <option> comma separated list of xrandr arguments (e.g. "gamma")
                         to skip both in detecting changes and applying a profile
 --version               show version information and exit
@@ -96,6 +97,18 @@ Usage: autorandr [options]
 """.strip()
 
 
+def is_closed_lid(output):
+    if not re.match(r'(eDP(-?[0-9]\+)*|LVDS(-?[0-9]\+)*)', output):
+        return False
+    lids = glob.glob("/proc/acpi/button/lid/*/state")
+    if len(lids) == 1:
+        state_file = lids[0]
+        with open(state_file) as f:
+            content = f.read()
+            return "close" in content
+    return False
+
+
 class AutorandrException(Exception):
     def __init__(self, message, original_exception=None, report_bug=False):
         self.message = message
@@ -505,6 +518,12 @@ def parse_xrandr_output():
         if output_modes:
             modes[output_name] = output_modes
 
+    # consider a closed lid as disconnected if other outputs are connected
+    if sum(o.edid != None for o in outputs.values()) > 1:
+        for output_name in outputs.keys():
+            if is_closed_lid(output_name):
+                outputs[output_name].edid = None
+
     return outputs, modes
 
 
@@ -608,13 +627,20 @@ def output_setup(configuration, setup):
             print(output, configuration[output].edid, file=setup)
 
 
-def save_configuration(profile_path, configuration):
+def save_configuration(profile_path, profile_name, configuration, forced=False):
     "Save a configuration into a profile"
     if not os.path.isdir(profile_path):
         os.makedirs(profile_path)
-    with open(os.path.join(profile_path, "config"), "w") as config:
+    config_path = os.path.join(profile_path, "config")
+    setup_path = os.path.join(profile_path, "setup")
+    if os.path.isfile(config_path) and not forced:
+        raise AutorandrException('Refusing to overwrite config "{}" without passing "--force"!'.format(profile_name))
+    if os.path.isfile(setup_path) and not forced:
+        raise AutorandrException('Refusing to overwrite config "{}" without passing "--force"!'.format(profile_name))
+
+    with open(config_path, "w") as config:
         output_configuration(configuration, config)
-    with open(os.path.join(profile_path, "setup"), "w") as setup:
+    with open(setup_path, "w") as setup:
         output_setup(configuration, setup)
 
 
@@ -1220,12 +1246,14 @@ def main(argv):
             sys.exit(1)
         try:
             profile_folder = os.path.join(profile_path, options["--save"])
-            save_configuration(profile_folder, config)
+            save_configuration(profile_folder, options['--save'], config, forced="--force" in options)
             exec_scripts(profile_folder, "postsave", {
                 "CURRENT_PROFILE": options["--save"],
                 "PROFILE_FOLDER": profile_folder,
                 "MONITORS": ":".join(enabled_monitors(config)),
             })
+        except AutorandrException as e:
+            raise e
         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"])
diff --git a/contrib/etc/xdg/autostart/autorandr-lid-listener.desktop b/contrib/etc/xdg/autostart/autorandr-lid-listener.desktop
new file mode 100644 (file)
index 0000000..9d16f07
--- /dev/null
@@ -0,0 +1,6 @@
+[Desktop Entry]
+Name=Autorandr Lid Listener
+Comment=Trigger autorandr whenever the lid state changes
+Type=Application
+Exec=bash -c "stdbuf -oL libinput debug-events | egrep --line-buffered '^ event[0-9]+\s+SWITCH_TOGGLE\s' | while read line; do autorandr --change --default default; done"
+X-GNOME-Autostart-Phase=Initialization
diff --git a/contrib/listen_lid.sh b/contrib/listen_lid.sh
new file mode 100755 (executable)
index 0000000..8de7eb6
--- /dev/null
@@ -0,0 +1,10 @@
+#!/bin/sh
+#
+# /!\ You must be part of the input group
+# sudo gpasswd -a $USER input
+
+stdbuf -oL libinput debug-events | \
+    grep -E --line-buffered '^[[:space:]-]+event[0-9]+[[:space:]]+SWITCH_TOGGLE[[:space:]]' | \
+    while read line; do
+    autorandr --change --default default
+done
diff --git a/contrib/systemd/autorandr-lid-listener.service b/contrib/systemd/autorandr-lid-listener.service
new file mode 100644 (file)
index 0000000..24b1c19
--- /dev/null
@@ -0,0 +1,12 @@
+[Unit]
+Description=Runs autorandr whenever the lid state changes
+
+[Service]
+Type=simple
+ExecStart=sh -c "stdbuf -oL libinput debug-events | grep -E --line-buffered '^[[:space:]-]+event[0-9]+[[:space:]]+SWITCH_TOGGLE[[:space:]]' | while read line; do autorandr --batch --change --default default; done"
+Restart=always
+RestartSec=30
+SyslogIdentifier=autorandr
+
+[Install]
+WantedBy=multi-user.target
index 9bf12e20cecd7fef825b91635d90034ef4642492..55b35412be951fd9a6b1341d2f5a63b9ff0de518 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -9,7 +9,7 @@ except:
 setup(
     name='autorandr',
 
-    version='1.8.1.post1',
+    version='1.9.post1',
 
     description='Automatically select a display configuration based on connected devices',
     long_description=long_description,