]> git.donarmstrong.com Git - deb_pkgs/autorandr.git/commitdiff
Merge broadcast_rgb feature (#204)
authorPhillip Berndt <phillip.berndt@googlemail.com>
Thu, 16 Dec 2021 09:59:16 +0000 (10:59 +0100)
committerPhillip Berndt <phillip.berndt@googlemail.com>
Thu, 16 Dec 2021 09:59:16 +0000 (10:59 +0100)
.gitignore [new file with mode: 0644]
README.md
autorandr.1
autorandr.py
caca [new file with mode: 0644]
contrib/bash_completion/autorandr
contrib/packaging/rpm/autorandr.spec
contrib/zsh_completion/_autorandr

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..a01ee28
--- /dev/null
@@ -0,0 +1 @@
+.*.swp
index daa6b3883b17e6a7cc78e56e2ca8517bbdb1139f..40605295c119e56f15130320360701f5efd30ab4 100644 (file)
--- a/README.md
+++ b/README.md
@@ -147,9 +147,20 @@ names in your configuration directory to have autorandr use any of them
 as the default configuration without you having to change the system-wide
 configuration.
 
-You can store default values for any option in an INI-file in
-`~/.config/autorandr/settings.ini` in a section `config`. The most useful
-candidate for doing that is `skip-options`, if you need it.
+You can store default values for any option in an INI-file located at
+`~/.config/autorandr/settings.ini`. In a `config` section, you may place any
+default values in the form `option-name=option-argument`.
+
+A common and effective use of this is to specify default `skip-options`, for
+instance skipping the `gamma` setting if using
+[`redshift`](https://github.com/jonls/redshift) as a daemon.  To implement
+the equivalent of `--skip-options gamma`, your `settings.ini` file should look
+like this:
+
+```
+[config]
+skip-options=gamma
+```
 
 ## Advanced usage
 
@@ -238,6 +249,11 @@ options nvidia_drm modeset=1
 
 ## Changelog
 
+**autorandr 1.12**
+* *2021-12-16* Switch default interpreter to Python 3
+* *2021-12-16* Add `--list` to list all profiles
+* *2021-12-16* Add `--cycle` to cycle all detected profiles
+
 **autorandr 1.11**
 * *2020-05-23* Handle empty sys.executable
 * *2020-06-08* Fix Python 2 compatibility
index d268822bba5ba0a11cd2661ccdcc1c8ae623526b..d20264b920e3963db2fb3d21a95d9e558f297608 100644 (file)
@@ -38,6 +38,9 @@ List only the current (active) configuration(s)
 .BR \-\-config
 Dump the variable values of your current xrandr setup
 .TP
+.BR \-\-cycle
+Cycle through all detected profiles
+.TP
 .BR \-\-debug
 Enable verbose output
 .TP
@@ -50,14 +53,31 @@ Don't change anything, only print the xrandr commands
 .BR \-\-fingerprint
 Fingerprint the current hardware setup
 .TP
+.BR \-\-match-edid
+Match displays based on edid instead of name
+.TP
 .BR \-\-force
 Force loading or reloading of a profile
 .TP
+.BR \-\-list
+List all profiles
+.TP
 \fB\-\-skip\-options [\fIOPTION\fR] ...
 \fRSet a comma\-separated list of xrandr arguments to skip both in change detection and profile application. See \fBxrandr(1)\fR for xrandr arguments.
 .TP
 .BR \-\-version
 Show version information and exit
+.SH FILES
+Configuration files are searched for in the \fIautorandr
+\fRdirectory in the colon separated list of paths in \fI$XDG_CONFIG_DIRS
+\fR- or in \fI/etc/xdg
+\fRif that var is not set.  They are then looked for in \fI~/.autorandr
+\fRand if that doesn't exist, in \fI$XDG_CONFIG_HOME/autorandr
+\fRor in \fI~/.config/autorandr\fR if that var is unset.
+
+In each of those directories it looks for directories with \fIconfig\fR and
+\fIsetup\fR in them.  It is best to manage these files with the
+\fBautorandr\fR utility.
 .SH AUTHOR
 \fRPhillip Berndt <phillip.berndt@googlemail.com>
 .br
index f47a994ca2209040569ab76283ea8b2ef45f92f8..ec159bf6a0b5fc4a85b855f58cfba04b4a371f38 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # encoding: utf-8
 #
 # autorandr.py
@@ -39,10 +39,14 @@ import time
 import glob
 
 from collections import OrderedDict
-from distutils.version import LooseVersion as Version
 from functools import reduce
 from itertools import chain
 
+try:
+    from packaging.version import Version
+except ModuleNotFoundError:
+    from distutils.version import LooseVersion as Version
+
 if sys.version_info.major == 2:
     import ConfigParser as configparser
 else:
@@ -90,11 +94,14 @@ Usage: autorandr [options]
 --batch                 run autorandr for all users with active X11 sessions
 --current               only list current (active) configuration(s)
 --config                dump your current xrandr setup
+--cycle                 automatically load the next detected profile
 --debug                 enable verbose output
 --detected              only list detected (available) configuration(s)
 --dry-run               don't change anything, only print the xrandr commands
 --fingerprint           fingerprint your current hardware setup
+--match-edid            match diplays based on edid instead of name
 --force                 force (re)loading of a profile / overwrite exiting files
+--list                  list configurations
 --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
@@ -628,6 +635,36 @@ def match_asterisk(pattern, data):
     return matched * 1. / total
 
 
+def update_profiles_edid(profiles, config):
+    edid_map = {}
+    for c in config:
+        if config[c].edid is not None:
+            edid_map[config[c].edid] = c
+
+    for p in profiles:
+        profile_config = profiles[p]["config"]
+
+        for edid in edid_map:
+            for c in profile_config.keys():
+                if profile_config[c].edid != edid or c == edid_map[edid]:
+                    continue
+
+                print("%s: renaming display %s to %s" % (p, c, edid_map[edid]))
+
+                tmp_disp = profile_config[c]
+
+                if edid_map[edid] in profile_config:
+                    # Swap the two entries
+                    profile_config[c] = profile_config[edid_map[edid]]
+                    profile_config[c].output = c
+                else:
+                    # Object is reassigned to another key, drop this one
+                    del profile_config[c]
+
+                profile_config[edid_map[edid]] = tmp_disp
+                profile_config[edid_map[edid]].output = edid_map[edid]
+
+
 def find_profiles(current_config, profiles):
     "Find profiles matching the currently connected outputs, sorting asterisk matches to the back"
     detected_profiles = []
@@ -1245,9 +1282,9 @@ def read_config(options, directory):
 def main(argv):
     try:
         opts, args = getopt.getopt(argv[1:], "s:r:l:d:cfh",
-                                   ["batch", "dry-run", "change", "default=", "save=", "remove=", "load=",
+                                   ["batch", "dry-run", "change", "cycle", "default=", "save=", "remove=", "load=",
                                     "force", "fingerprint", "config", "debug", "skip-options=", "help",
-                                    "current", "detected", "version"])
+                                    "list", "current", "detected", "version", "match-edid"])
     except getopt.GetoptError as e:
         print("Failed to parse options: {0}.\n"
               "Use --help to get usage information.".format(str(e)),
@@ -1300,16 +1337,23 @@ def main(argv):
             profiles.update(load_profiles(profile_path))
             profile_symlinks.update(get_symlinks(profile_path))
             read_config(options, profile_path)
-        # Sort by descending mtime
-        profiles = OrderedDict(sorted(profiles.items(), key=lambda x: -x[1]["config-mtime"]))
     except Exception as e:
         raise AutorandrException("Failed to load profiles", e)
 
-    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 "--match-edid" in options:
+        update_profiles_edid(profiles, config)
+
+    # Sort by mtime
+    sort_direction = -1
+    if "--cycle" in options:
+        # When cycling through profiles, put the profile least recently used to the top of the list
+        sort_direction = 1
+    profiles = OrderedDict(sorted(profiles.items(), key=lambda x: sort_direction * x[1]["config-mtime"]))
+    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}
+
     if "--fingerprint" in options:
         output_setup(config, sys.stdout)
         sys.exit(0)
@@ -1406,10 +1450,11 @@ def main(argv):
         best_index = 9999
         for profile_name in profiles.keys():
             if profile_blocked(os.path.join(profile_path, profile_name), block_script_metadata):
-                if "--current" not in options and "--detected" not in options:
+                if not any(opt in options for opt in ("--current", "--detected", "--list")):
                     print("%s (blocked)" % profile_name)
                 continue
             props = []
+            is_current_profile = profile_name in current_profiles
             if profile_name in detected_profiles:
                 if len(detected_profiles) == 1:
                     index = 1
@@ -1417,16 +1462,17 @@ def main(argv):
                 else:
                     index = detected_profiles.index(profile_name) + 1
                     props.append("(detected) (%d%s match)" % (index, ["st", "nd", "rd"][index - 1] if index < 4 else "th"))
-                if ("-c" in options or "--change" in options) and index < best_index:
-                    load_profile = profile_name
-                    best_index = index
+                if index < best_index:
+                    if "-c" in options or "--change" in options or ("--cycle" in options and not is_current_profile):
+                        load_profile = profile_name
+                        best_index = index
             elif "--detected" in options:
                 continue
-            if profile_name in current_profiles:
+            if is_current_profile:
                 props.append("(current)")
             elif "--current" in options:
                 continue
-            if "--current" in options or "--detected" in options:
+            if any(opt in options for opt in ("--current", "--detected", "--list")):
                 print("%s" % (profile_name, ))
             else:
                 print("%s%s%s" % (profile_name, " " if props else "", " ".join(props)))
@@ -1435,7 +1481,7 @@ def main(argv):
 
     if "-d" in options:
         options["--default"] = options["-d"]
-    if not load_profile and "--default" in options and ("-c" in options or "--change" in options):
+    if not load_profile and "--default" in options and ("-c" in options or "--change" in options or "--cycle" in options):
         load_profile = options["--default"]
 
     if load_profile:
@@ -1454,7 +1500,7 @@ def main(argv):
                 scripts_path = profile["path"]
             except KeyError:
                 raise AutorandrException("Failed to load profile '%s': Profile not found" % load_profile)
-            if load_profile in detected_profiles and detected_profiles[0] != load_profile:
+            if "--dry-run" not in options:
                 update_mtime(os.path.join(scripts_path, "config"))
         add_unused_outputs(config, load_config)
         if load_config == dict(config) and "-f" not in options and "--force" not in options:
diff --git a/caca b/caca
new file mode 100644 (file)
index 0000000..e69de29
index 03beabe9f2f87bdebe2e96f3f8e0bc8519dd24c1..0af11ec70834a7b2e0bdeb3a95f1f0a75d6c8ce2 100644 (file)
@@ -10,7 +10,7 @@ _autorandr ()
        prev="${COMP_WORDS[COMP_CWORD-1]}"
 
        opts="-h -c -s -r -l -d"
-       lopts="--help --change --save --remove --load --default --force --fingerprint --config --dry-run"
+       lopts="--help --change --cycle --save --remove --load --list --default --force --fingerprint  --match-edid --config --dry-run"
 
        # find system-level autorandr dirs
        OIFS="$IFS"
index bc4a02b3f7caeb38f768d9bb7de4e23fecad1155..ae6ece8eed2f07640e3dfb5236ef3c452d497ec2 100644 (file)
-%define name autorandr
-%define version 1.11
-%define release 1
-
-# pmutils
-%define use_pm_utils 1
-%if 0%{?fedora} > 22
-%define use_pm_utils 0
-%endif
-%if 0%{?rhel} > 7
-%define use_pm_utils 0
-%endif
-
-# python 2 or 3
-%define py_ver 3
-%if 0%{?rhel}
-%define py_ver 2
-%endif
-
-Summary: Automatically select a display configuration based on connected devices
-Name: %{name}
-Version: %{version}
-Release: %{release}%{?dist}
-Source0: https://github.com/phillipberndt/%{name}/archive/%{version}/%{name}-%{version}.tar.gz
-License: GPLv3
-Group: Development/Libraries
-BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot
-Prefix: %{_prefix}
-Vendor: Phillip Berndt <phillip.berndt@googlemail.com>
-Url: https://github.com/phillipberndt/autorandr
-Requires: python%{py_ver}
-%if 0%{?use_pm_utils}
-Requires:      pm-utils
-%endif
-%{?systemd_ordering}
-BuildRequires: bash-completion
-BuildRequires: python%{py_ver}-devel
+Name:           autorandr
+Version:        1.11
+Release:        %autorelease
+Summary:        Automatically select a display configuration based on connected devices
+
+BuildArch:      noarch
+BuildRequires:  python3-devel
+
+License:        GPLv3
+URL:            https://github.com/phillipberndt/%{name}
+Source0:        %{url}/archive/%{version}/%{name}-%{version}.tar.gz
+
+BuildRequires: make
 BuildRequires: systemd
 BuildRequires: udev
-BuildRequires: gcc
-BuildRequires: libxcb-devel
-%if %{py_ver} == 2
-BuildRequires: python3-devel
-%endif
+BuildRequires: desktop-file-utils
 
 
 %description
-Automatically select a display configuration based on connected devices
-
-## Branch information
-
-This is a compatible Python rewrite of
-[wertarbyte/autorandr](https://github.com/wertarbyte/autorandr). Contributions
-for bash-completion, fd.o/XDG autostart, Nitrogen, pm-utils, and systemd can be
-found under [contrib](contrib/).
-
-The original [wertarbyte/autorandr](https://github.com/wertarbyte/autorandr)
-tree is unmaintained, with lots of open pull requests and issues. I forked it
-and merged what I thought were the most important changes. If you are searching
-for that version, see the [`legacy` branch](https://github.com/phillipberndt/autorandr/tree/legacy).
-Note that the Python version is better suited for non-standard configurations,
-like if you use `--transform` or `--reflect`. If you use `auto-disper`, you
-have to use the bash version, as there is no disper support in the Python
-version (yet). Both versions use a compatible configuration file format, so
-you can, to some extent, switch between them.  I will maintain the `legacy`
-branch until @wertarbyte finds the time to maintain his branch again.
-
-If you are interested in why there are two versions around, see
-[#7](https://github.com/phillipberndt/autorandr/issues/7),
-[#8](https://github.com/phillipberndt/autorandr/issues/8) and
-especially
-[#12](https://github.com/phillipberndt/autorandr/issues/12)
-if you are unhappy with this version and would like to contribute to the bash
-version.
+%{summary}.
+
+%prep
+%setup -q
+%py3_shebang_fix ./autorandr.py
+
+%post
+udevadm control --reload-rules
+%systemd_post autorandr.service
+
+%preun
+%systemd_preun autorandr.service
+
+%postun
+%systemd_postun autorandr.service
+
+%package bash-completion
+Summary: Bash completion for autorandr
+Requires: %{name}
+Requires: bash-completion
+%description bash-completion
+This package provides bash-completion files for autorandr
 
 
 %package zsh-completion
-Summary: zsh-completion for autorandr
+Summary: Zsh completion for autorandr
 Requires: zsh
 Requires: %{name}
 %description zsh-completion
 This package provides zsh-completion files for autorandr
 
-%package launcher
-Summary: Launcher daemon for autorandr
-Requires: libxcb
-Requires: %{name}
-%description launcher
-This package provides launcher daemon for autorandr
-
-%prep
-%setup -n %{name}-%{version} -n %{name}-%{version}
-%if %{py_ver} == 3
-pathfix.py -pni "%{__python3} %{py3_shbang_opts}" ./autorandr.py
-%else
-pathfix.py -pni "%{__python2} %{py2_shbang_opts}" ./autorandr.py
-%endif
-
 %install
-make DESTDIR="%{buildroot}" PREFIX=%{_prefix} install
-make DESTDIR="%{buildroot}" PREFIX=%{_prefix} install_launcher
+%make_install
 install -vDm 644 README.md -t "%{buildroot}/usr/share/doc/%{name}/"
-install -vDm 644 contrib/zsh_completion/_autorandr -t %{buildroot}%{_datarootdir}/zsh/site-functions/
+install -vDm 644 contrib/bash_completion/autorandr -t %{buildroot}%{_datadir}/bash-completion/completions/
+install -vDm 644 contrib/zsh_completion/_autorandr -t %{buildroot}%{_datadir}/zsh/site-functions/
+install -vDm 644 autorandr.1 -t %{buildroot}%{_mandir}/man1/
 
+%check
+desktop-file-validate %{buildroot}%{_sysconfdir}/xdg/autostart/autorandr.desktop
 
 %files
-%defattr(-,root,root,-)
-%attr(0644,root,root) %{_unitdir}/autorandr.service
-%license gpl-3.0.txt 
+%license gpl-3.0.txt
 %doc README.md
-%{_sysconfdir}/xdg/autostart/autorandr.desktop
+%{_mandir}/man1/*
 %{_bindir}/autorandr
-%{_mandir}
-%{_datarootdir}/bash-completion/completions/autorandr
+%{_unitdir}/autorandr.service
+%{_sysconfdir}/xdg/autostart/autorandr.desktop
 %{_udevrulesdir}/40-monitor-hotplug.rules
 
-%files zsh-completion
-%{_datarootdir}/zsh/site-functions/_autorandr
+%files bash-completion
+%{_datadir}/bash-completion/completions/autorandr
 
-%files launcher
-%{_bindir}/autorandr-launcher
-%{_sysconfdir}/xdg/autostart/autorandr-launcher.desktop
+%files zsh-completion
+%{_datadir}/zsh/site-functions/_autorandr
 
 %changelog
-* Mon Jun 07 2021 Jerzy Drozdz <jerzy.drozdz@jdsieci.pl> - 1.11-1
-- Updated to stable 1.11
-- Added launcher subpackage
-* Mon Jun 08 2020 Jerzy Drozdz <jerzy.drozdz@jdsieci.pl> - 1.10.1-1
-- Updated to stable 1.10.1
-- Added zsh-completion subpackage
-* Wed May 22 2019 Maciej Sitarz <macieksitarz@wp.pl> - 1.8.1-1
-- Updated to stable 1.8.1
-* Fri Sep 28 2018 Maciej Sitarz <macieksitarz@wp.pl> - 1.7-1
-- Updated to stable 1.7
-* Thu Jul 19 2018 Maciej Sitarz <macieksitarz@wp.pl> - 1.5-1
-- Updated to stable 1.5
-- Changed dest path for systemd service file
-* Sun Oct 01 2017 Jerzy Drozdz <rpmbuilder@jdsieci.pl> - 1.1-2
-- Added conditionals for pm-utils, compability with Fedora26+
-- Removed bash-completion from requisites
-- Removed udev from requisites
-* Sun Sep 03 2017 Jerzy Drozdz <rpmbuilder@jdsieci.pl> - 1.1-1
-- Update to stable 1.1
-* Fri Feb 17 2017 Jerzy Drozdz <rpmbuilder@jdsieci.pl> - 20170217git-1
-- Update to master
-* Wed Jul 6 2016 Jerzy Drozdz <rpmbuilder@jdsieci.pl> - 20160706git-1
-- Set default value of $XDG_CONFIG_DIRS to fulfill the standard
-* Fri Jul 1 2016 Jerzy Drozdz <rpmbuilder@jdsieci.pl> - 20160701git-1.1
-- fixed running udevadm in post
-* Fri Jul 1 2016 Jerzy Drozdz <rpmbuilder@jdsieci.pl> - 20160701git-1
-- initial build
+%autochangelog
index b6cacbb1d3ad42807d6e06e9ed175705d45af424..1667f0c560a75a030c9613e89a9b387468ed4991 100644 (file)
@@ -28,11 +28,14 @@ _autorandr () {
        "($exclude)"{-r,--remove}"[remove profile]:profile:__autorandr_saved_profile" \
        --batch"[run autorandr for all users]" \
        --current"[list current active configurations]" \
+       --cycle"[cycle through all detected profiles]" \
        --config"[dump current xrandr setup]" \
        --debug"[enable verbose output]" \
        --dry-run"[don't change anything]" \
        --fingerprint"[fingerprint current hardware]" \
+       --match-edid"[match displays using edid]" \
        --force"[force loading of a profile]" \
+       --list"[list all profiles]" \
        --skip-options"[skip xrandr options]:xrandr options:_values -s , options gamma brightness panning transform primary mode pos rate" \
        --version"[show version]"
 }