pax_global_header00006660000000000000000000000064132172311620014510gustar00rootroot0000000000000052 comment=8b9879ca9fe4463d60f60ad989f4e4337493fe03 autorandr-1.4/000077500000000000000000000000001321723116200133535ustar00rootroot00000000000000autorandr-1.4/.flake8000066400000000000000000000000551321723116200145260ustar00rootroot00000000000000[flake8] ignore = E722 max-line-length = 130 autorandr-1.4/Makefile000066400000000000000000000110021321723116200150050ustar00rootroot00000000000000DESTDIR=/ PREFIX=/usr/ .PHONY: all install uninstall autorandr bash_completion autostart_config pmutils systemd udev all: @echo "Call \"make install\" to install this program." @echo "Call \"make uninstall\" to remove this program." @echo @echo "The following components were autodetected and will be installed:" @echo " "$(DEFAULT_TARGETS) @echo @echo "The following locations have been detected (from pkg-config):" @echo " - BASH_COMPLETIONS_DIR: $(BASH_COMPLETIONS_DIR)" @echo " - SYSTEMD_UNIT_DIR: $(SYSTEMD_UNIT_DIR)" @echo " - UDEV_RULES_DIR: $(UDEV_RULES_DIR)" @echo " - PM_SLEEPHOOKS_DIR: $(PM_SLEEPHOOKS_DIR)" @echo @echo "You can use the TARGETS variable to override this, but need to set" @echo "the SYSTEMD_UNIT_DIR, PM_SLEEPHOOKS_DIR and UDEV_RULES_DIR variables" @echo "in case they were not detected correctly." @echo @echo 'E.g. "make install TARGETS='autorandr pmutils' PM_UTILS_DIR=/etc/pm/sleep.d".' @echo @echo "The following additional targets are available:" @echo @echo " make deb creates a Debian package" # Rules for autorandr itself DEFAULT_TARGETS=autorandr install_autorandr: install -D -m 755 autorandr.py ${DESTDIR}${PREFIX}/bin/autorandr uninstall_autorandr: rm -f ${DESTDIR}${PREFIX}/bin/autorandr # Rules for bash-completion BASH_COMPLETIONS_DIR:=$(shell pkg-config --variable=completionsdir bash-completion 2>/dev/null) ifneq (,$(BASH_COMPLETIONS_DIR)) DEFAULT_TARGETS+=bash_completion endif install_bash_completion: install -D -m 644 contrib/bash_completion/autorandr ${DESTDIR}/${BASH_COMPLETIONS_DIR}/autorandr uninstall_bash_completion: rm -f ${DESTDIR}/${BASH_COMPLETIONS_DIR}/autorandr # Rules for autostart config XDG_AUTOSTART_DIR=/etc/xdg/autostart DEFAULT_TARGETS+=autostart_config install_autostart_config: install -D -m 644 contrib/etc/xdg/autostart/autorandr.desktop ${DESTDIR}/${XDG_AUTOSTART_DIR}/autorandr.desktop ifneq ($(PREFIX),/usr/) sed -i -re 's#/usr/bin/autorandr#$(subst #,\#,${PREFIX})/bin/autorandr#g' ${DESTDIR}/${XDG_AUTOSTART_DIR}/autorandr.desktop endif uninstall_autostart_config: rm -f ${DESTDIR}/${XDG_AUTOSTART_DIR}/autorandr.desktop # Rules for systemd SYSTEMD_UNIT_DIR:=$(shell pkg-config --variable=systemdsystemunitdir systemd 2>/dev/null) ifneq (,$(SYSTEMD_UNIT_DIR)) DEFAULT_TARGETS+=systemd endif install_systemd: $(if $(SYSTEMD_UNIT_DIR),,$(error SYSTEMD_UNIT_DIR is not defined)) install -D -m 644 contrib/systemd/autorandr.service ${DESTDIR}/${SYSTEMD_UNIT_DIR}/autorandr.service ifneq ($(PREFIX),/usr/) sed -i -re 's#/usr/bin/autorandr#$(subst #,\#,${PREFIX})/bin/autorandr#g' ${DESTDIR}/${SYSTEMD_UNIT_DIR}/autorandr.service endif @echo @echo "To activate the systemd unit, run this command as root:" @echo " systemctl daemon-reload" @echo " systemctl enable autorandr.service" @echo uninstall_systemd: $(if $(SYSTEMD_UNIT_DIR),,$(error SYSTEMD_UNIT_DIR is not defined)) rm -f ${DESTDIR}/${SYSTEMD_UNIT_DIR}/autorandr.service # Rules for pmutils PM_SLEEPHOOKS_DIR:=$(shell pkg-config --variable=pm_sleephooks pm-utils 2>/dev/null) ifneq (,$(PM_SLEEPHOOKS_DIR)) ifeq (,$(SYSTEMD_UNIT_DIR)) DEFAULT_TARGETS+=pmutils endif endif install_pmutils: $(if $(PM_SLEEPHOOKS_DIR),,$(error PM_SLEEPHOOKS_DIR is not defined)) install -D -m 755 contrib/pm-utils/40autorandr ${DESTDIR}/${PM_SLEEPHOOKS_DIR}/40autorandr ifneq ($(PREFIX),/usr/) sed -i -re 's#/usr/bin/autorandr#$(subst #,\#,${PREFIX})/bin/autorandr#g' ${DESTDIR}/${PM_SLEEPHOOKS_DIR}/40autorandr endif uninstall_pmutils: $(if $(PM_SLEEPHOOKS_DIR),,$(error PM_SLEEPHOOKS_DIR is not defined)) rm -f ${DESTDIR}/${PM_SLEEPHOOKS_DIR}/40autorandr # Rules for udev UDEV_RULES_DIR:=$(shell pkg-config --variable=udevdir udev 2>/dev/null)/rules.d ifneq (,$(UDEV_RULES_DIR),y) DEFAULT_TARGETS+=udev endif install_udev: $(if $(UDEV_RULES_DIR),,$(error UDEV_RULES_DIR is not defined)) mkdir -p ${DESTDIR}/${UDEV_RULES_DIR}/ echo 'ACTION=="change", SUBSYSTEM=="drm", RUN+="$(if $(findstring systemd, $(TARGETS)),/bin/systemctl start --no-block autorandr.service,${PREFIX}/bin/autorandr --batch --change --default default)"' > ${DESTDIR}/${UDEV_RULES_DIR}/40-monitor-hotplug.rules @echo @echo "To activate the udev rules, run this command as root:" @echo " udevadm control --reload-rules" @echo uninstall_udev: $(if $(UDEV_RULES_DIR),,$(error UDEV_RULES_DIR is not defined)) rm -f ${DESTDIR}/${UDEV_RULES_DIR}/40-monitor-hotplug.rules TARGETS=$(DEFAULT_TARGETS) install: $(patsubst %,install_%,$(TARGETS)) uninstall: $(patsubst %,uninstall_%,$(TARGETS)) deb: ./contrib/packaging/debian/make_deb.sh autorandr-1.4/README.md000066400000000000000000000204711321723116200146360ustar00rootroot00000000000000# autorandr 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. ## License information and authors autorandr is available under the terms of the GNU General Public License (version 3). Contributors to this version of autorandr are: * Adrián López * andersonjacob * Alexander Wirt * Chris Dunder * Christoph Gysin * Daniel Hahler * Maciej Sitarz * Mathias Svensson * Matthew R Johnson * Nazar Mokrynskyi * Phillip Berndt * Rasmus Wriedt Larsen * Simon Wydooghe * Stefan Tomanek * stormc * tachylatus * Timo Bingmann * Timo Kaufmann * Tomasz Bogdal * Victor Häggqvist ## Installation/removal You can use the `autorandr.py` script as a stand-alone binary. If you'd like to install it as a system-wide application, there is a Makefile included that also places some configuration files in appropriate directories such that autorandr is invoked automatically when a monitor is connected or removed, the system wakes up from suspend, or a user logs into an X11 session. For Debian-based distributions (including Ubuntu) it is recommended to call `make deb` to obtain a package that can be installed and removed with `dpkg`. On Arch Linux, there is [an aur package available](https://aur.archlinux.org/packages/autorandr-git/). autorandr is also packaged in the [nix package manager](https://nixos.org/nix/) repositories. On other distributions you can install autorandr by calling `make install` and remove it by calling `make uninstall`. Run `make` without arguments to obtain a list of what exactly will be installed. We appreciate packaging scripts for other distributions, please file a pull request if you write one. If you prefer `pip` over your package manager, you can install autorandr with: sudo pip install "git+http://github.com/phillipberndt/autorandr#egg=autorandr" or simply sudo pip install autorandr if you prefer to use a stable version. Automatically generated packages versions are available from the [openSUSE build service](https://build.opensuse.org/package/show/home:phillipberndt/autorandr). ## How to use Save your current display configuration and setup with: autorandr --save mobile Connect an additional display, configure your setup and save it: autorandr --save docked Now autorandr can detect which hardware setup is active: $ autorandr mobile docked (detected) To automatically reload your setup: $ autorandr --change To manually load a profile: $ autorandr --load or simply: $ autorandr autorandr tries to avoid reloading an identical configuration. To force the (re)configuration: $ autorandr --load --force To prevent a profile from being loaded, place a script call _block_ in its directory. The script is evaluated before the screen setup is inspected, and in case of it returning a value of 0 the profile is skipped. This can be used to query the status of a docking station you are about to leave. If no suitable profile can be identified, the current configuration is kept. To change this behaviour and switch to a fallback configuration, specify `--default `. The system-wide installation of autorandr by default calls autorandr with a parameter `--default default`. There are three special, virtual configurations called `horizontal`, `vertical` and `common`. They automatically generate a configuration that incorporates all screens connected to the computer. You can symlink `default` to one of these 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. ## Hook scripts Three more scripts can be placed in the configuration directory (as (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): - `postswitch` is executed *after* a mode switch has taken place. This can be used to notify window managers or other applications about the switch. - `preswitch` is executed *before* a mode switch takes place. - `postsave` is executed after a profile was stored or altered. - `predetect` is executed before autorandr attempts to run xrandr. These scripts must be executable and can be placed directly in the configuration directory, where they will always be executed, or in the profile subdirectories, where they will only be executed on changes regarding that specific profile. Instead (or in addition) to these scripts, you can also place as many executable files as you like in subdirectories called `script_name.d` (e.g. `postswitch.d`). If a script with the same name occurs multiple times, user configuration takes precedence over system configuration (as specified by the [XDG spec](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html)) and profile configuration over general configuration. As a concrete example, suppose you have the files - `/etc/xdg/autorandr/postswitch` - `~/.config/autorandr/postswitch` - `~/.config/autorandr/postswitch.d/notify-herbstluftwm` - `~/.config/autorandr/docked/postswitch` and switch from `mobile` to `docked`. Then `~/.config/autorandr/docked/postswitch` is executed, since the profile specific configuration takes precedence, and `~/.config/autorandr/postswitch.d/notify-herbstluftwm` is executed, since it has a unique name. 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`. 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. Write e.g. `sleep 1` into that file to make autorandr wait a second before running `xrandr`. ## Changelog **autorandr 1.4** * *2017-12-22* Fixed broken virtual profile support * *2017-12-14* Added support for a settings file * *2017-12-14* Added a virtual profile `off`, which disables all screens **autorandr 1.3** * *2017-11-13* Add a short form for `--load` * *2017-11-21* Fix environment stealing in `--batch` mode (See #87) **autorandr 1.2** * *2017-07-16* Skip `--panning` unless it is required (See #72) * *2017-10-13* Add `clone-largest` virtual profile **autorandr 1.1** * *2017-06-07* Call systemctl with `--no-block` from udev rule (See #61) * *2017-01-20* New script hook, `predetect` * *2017-01-18* Accept comments (lines starting with `#`) in config/setup files **autorandr 1.0** * *2016-12-07* Tag the current code as version 1.0.0; see github issue #54 * *2016-10-03* Install a desktop file to `/etc/xdg/autostart` by default autorandr-1.4/autorandr.py000077500000000000000000001566361321723116200157500ustar00rootroot00000000000000#!/usr/bin/env python # encoding: utf-8 # # autorandr.py # Copyright (c) 2015, Phillip Berndt # # Autorandr rewrite in Python # # This script aims to be fully compatible with the original autorandr. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # from __future__ import print_function import binascii import copy import getopt import hashlib import os import posix import pwd import re import subprocess import sys import shutil import time from collections import OrderedDict from distutils.version import LooseVersion as Version from functools import reduce from itertools import chain if sys.version_info.major == 2: import ConfigParser as configparser else: import configparser try: input = raw_input except NameError: pass virtual_profiles = [ # (name, description, callback) ("off", "Disable all outputs", None), ("common", "Clone all connected outputs at the largest common resolution", None), ("clone-largest", "Clone all connected outputs with the largest resolution (scaled down if necessary)", None), ("horizontal", "Stack all connected outputs horizontally at their largest resolution", None), ("vertical", "Stack all connected outputs vertically at their largest resolution", None), ] help_text = """ Usage: autorandr [options] -h, --help get this small help -c, --change reload current setup -d, --default make profile the default profile -l, --load load profile -s, --save save your current setup to profile -r, --remove remove profile --batch run autorandr for all users with active X11 sessions --config dump your current xrandr setup --debug enable verbose output --dry-run don't change anything, only print the xrandr commands --fingerprint fingerprint your current hardware setup --force force (re)loading of a profile --skip-options