This merges pull request #62.
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 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-resume.service ${DESTDIR}/${SYSTEMD_UNIT_DIR}/autorandr-resume.service
-
-uninstall_systemd:
- $(if $(SYSTEMD_UNIT_DIR),,$(error SYSTEMD_UNIT_DIR is not defined))
- rm -f ${DESTDIR}/${SYSTEMD_UNIT_DIR}/autorandr-resume.service
# Rules for udev
UDEV_RULES_DIR:=$(shell pkg-config --variable=udevdir udev 2>/dev/null)/rules.d
install_udev:
$(if $(UDEV_RULES_DIR),,$(error UDEV_RULES_DIR is not defined))
- install -D -m 644 contrib/udev/40-monitor-hotplug.rules ${DESTDIR}/${UDEV_RULES_DIR}/40-monitor-hotplug.rules
-ifeq (${USER},root)
- udevadm control --reload-rules
-else
- @echo "Please run this command as root:"
+ mkdir -p ${DESTDIR}/${UDEV_RULES_DIR}/
+ echo 'ACTION=="change", SUBSYSTEM=="drm", RUN+="$(if $(findstring systemd, $(TARGETS)),/bin/systemctl start 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"
-endif
+ @echo
uninstall_udev:
$(if $(UDEV_RULES_DIR),,$(error UDEV_RULES_DIR is not defined))
takes place, and `postsave`, which is executed after a profile was
stored/altered.
+If you experience issues with xrandr being executed too early after connecting
+a new monitor, then you can create a script `predetect`, which will be executed
+before autorandr attempts to run xrandr. Place e.g. `sleep 1` into that file
+to make autorandr wait a second before running xrandr.
+
All scripts can also be placed in any of the `$XDG_CONFIG_DIRS`. In addition to
the script names themselves, any executables in subdirectories named
`script_name.d` (e.g. `postswitch.d`) are executed as well. In scripts, some of
## Changelog
* *2017-01-18* Accept comments (lines starting with `#`) in config/setup files
+* *2017-01-20* New script hook, `predetect`
**autorandr 1.0**
and system-wide configuration folders, named script_name or residing in
subdirectories named script_name.d.
+ If profile_path is None, only global scripts will be invoked.
+
meta_information is expected to be an dictionary. It will be passed to the block scripts
in the environment, as variables called AUTORANDR_<CAPITALIZED_KEY_HERE>.
if not os.path.isdir(user_profile_path):
user_profile_path = os.path.join(os.environ.get("XDG_CONFIG_HOME", os.path.expanduser("~/.config")), "autorandr")
- for folder in chain((profile_path, os.path.dirname(profile_path), user_profile_path),
- (os.path.join(x, "autorandr") for x in os.environ.get("XDG_CONFIG_DIRS", "/etc/xdg").split(":"))):
+ candidate_directories = chain((user_profile_path,), (os.path.join(x, "autorandr") for x in os.environ.get("XDG_CONFIG_DIRS", "/etc/xdg").split(":")))
+ if profile_path:
+ candidate_directories = chain((profile_path,), candidate_directories)
+
+ for folder in candidate_directories:
if script_name not in ran_scripts:
script = os.path.join(folder, script_name)
process_environ[name] = value
display = process_environ["DISPLAY"] if "DISPLAY" in process_environ else None
+ # To allow scripts to detect batch invocation (especially useful for predetect)
+ process_environ["AUTORANDR_BATCH_PID"] = os.getpid()
+
if display and display not in X11_displays_done:
try:
pwent = pwd.getpwuid(uid)
file=sys.stderr)
sys.exit(posix.EX_USAGE)
+ if "-h" in options or "--help" in options:
+ exit_help()
+
# Batch mode
if "--batch" in options:
if ("DISPLAY" not in os.environ or not os.environ["DISPLAY"]) and os.getuid() == 0:
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 "--fingerprint" in options:
raise AutorandrException("Failed to remove profile '%s'" % (options["--remove"],), e)
sys.exit(0)
- if "-h" in options or "--help" in options:
- exit_help()
-
detected_profiles = find_profiles(config, profiles)
load_profile = False
# Debian(ish) specific part
make -C "$P/../../../" \
DESTDIR="$D" \
- TARGETS="autorandr bash_completion autostart_config pmutils systemd udev" \
+ TARGETS="autorandr bash_completion autostart_config systemd udev" \
BASH_COMPLETION_DIR=/usr/share/bash-completion/completions \
SYSTEMD_UNIT_DIR=/lib/systemd/system \
PM_UTILS_DIR=/usr/lib/pm-utils/sleep.d \
case "$1" in
thaw|resume)
- autorandr --batch -c --default default
+ /usr/bin/autorandr --batch --change --default default
;;
esac
+++ /dev/null
-[Unit]
-Description=autorandr resume hook
-After=sleep.target
-
-[Service]
-ExecStart=/usr/bin/autorandr --batch -c --default default
-
-[Install]
-WantedBy=sleep.target
--- /dev/null
+[Unit]
+Description=autorandr execution hook
+After=sleep.target
+StartLimitInterval=5
+StartLimitBurst=1
+
+[Service]
+ExecStart=/usr/bin/autorandr --batch --change --default default
+Type=oneshot
+RemainAfterExit=false
+
+[Install]
+WantedBy=sleep.target
+++ /dev/null
-ACTION=="change", SUBSYSTEM=="drm", RUN+="/usr/bin/autorandr --batch -c --default default"