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
## 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
.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
.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
-#!/usr/bin/env python
+#!/usr/bin/env python3
# encoding: utf-8
#
# autorandr.py
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:
--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
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 = []
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)),
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)
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
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)))
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:
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:
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"
-%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
"($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]"
}