autorandr icon indicating copy to clipboard operation
autorandr copied to clipboard

Temporarily disable autorandr until next reboot

Open metov opened this issue 3 years ago • 7 comments
trafficstars

I have a set up where I frequently change monitors (think connect and disconnect a second screen repeatedly). Autorandr happily deal with this situation in a sensible manner - new screens are activated when connected, and deactivated when disconnected.

However, sometimes I want to suspend autorandr, because I'm doing something where it is more convenient to not have the screens automatically switch. I still want to have autorandr work normally at other times - I just want to disable it until the next boot.

Is there a way to do this? I can imagine some obvious ways:

  • Stopping a systemd service, but not disabling it, would mean it gets started at next boot. Cool, but I couldn't find any services in my systemd.
  • Setting an environment variable, without adding it to the shell profile, would presumably accomplish this (but what about different shells?). I don't know if there is such a variable though.

metov avatar Nov 21 '22 21:11 metov

How about a predetect script that checks for a file in /var/run or another ephemeral directory?

phillipberndt avatar Nov 22 '22 09:11 phillipberndt

@phillipberndt how can autorandr be disabled in general? systemctl stop autorandr doesn't do anything for me. It still runs

sarmong avatar Dec 07 '22 16:12 sarmong

I believe the reason you don't see a systemd service is that autorandr uses desktop file to autostart, not systemd: https://github.com/phillipberndt/autorandr/blob/master/Makefile#L63

DawidJanczak avatar Dec 12 '22 05:12 DawidJanczak

The reason why systemctl stop autorandr doesn't stop it is because the Makefile creates a udev rule that will trigger the systemd service everytime an external monitor is hot {un,}plugged.

Here's a oneliner (that must be run as root) that will allow you to stop it temporarly until you hit enter :

wget https://raw.githubusercontent.com/phillipberndt/autorandr/master/Makefile && make uninstall_udev && echo -en "autorandr has been temporarily disabled, press Enter to enable it again..." && read && make install_udev && rm Makefile

Note that this oneliner is quite dirty, instead, you should probably write shell script available in your PATH and trap the cleanup function (e.g. in case CTRL+C is hit instead of pressing enter)

EDIT:

Not tested, but this should do it :

#!/bin/bash
set -e

udev_rules_dir="$(pkg-config --variable=udevdir udev)/rules.d"
udev_rule="$udev_rules_dir/40-monitor-hotplug.rules"

if [ "$EUID" -ne 0 ]
then 
    echo "This script requires root privigleges"
    exit 1
fi

remove_udev_rule() {
    rm -f "$udev_rule"
}

reinstall_udev_rule() {
    echo 'ACTION=="change", SUBSYSTEM=="drm", RUN+="/bin/systemctl start --no-block autorandr.service"' > "$udev_rule"
}

main() {
    remove_udev_rule
    trap reinstall_udev_rule EXIT
    echo -ne "autorandr has been paused, press Enter to resume it..."
    read -r
}

main "$@"

ShellCode33 avatar Dec 12 '22 21:12 ShellCode33

Thanks, I will try that.

But I don't understand what's the point of triggering systemd from udev? Why not just trigger a script directly from udev?

sarmong avatar Dec 13 '22 08:12 sarmong

Good question, I guess it's for maintainability reasons, if they update the systemd unit file (e.g. a change of CLI parameters), it will propagate to the udev rule as well. But from what I see, the Makefile is also able to install autorandr without using systemd

ShellCode33 avatar Dec 13 '22 10:12 ShellCode33

How about a predetect script that checks for a file in /var/run or another ephemeral directory?

I suppose that would work. Although it seems a bit obscure.

metov avatar Dec 25 '22 02:12 metov