autorandr

repository·master·Indexed 25 days ago

https://github.com/phillipberndt/autorandr

A tool that automatically selects and applies display configurations, such as monitor layouts and resolutions, based on connected hardware devices. It supports saving and loading profiles, configuring fallback defaults, using hook scripts for automation, and wildcard EDID matching for monitors.

Tokens
1.2K
Snippets
6
Records
8
Agent score
33%

What's inside autorandr

  1. Use hook scripts for automation

    master

    You can execute scripts during different stages of the profile switching process. Scripts can be placed in the main configuration directory (e.g., ~/.config/autorandr/) or within specific profile subdirectories.

    Available hook types:

    • postswitch: Executed after a mode switch.
    • preswitch: Executed before a mode switch.
    • postsave: Executed after a profile is stored or altered.
    • predetect: Executed before autorandr runs xrandr (useful for adding delays with sleep).

    Execution Order and Precedence:

    1. Profile-specific scripts (e.g., ~/.config/autorandr/docked/postswitch) have the highest precedence.
    2. User configuration (~/.config/autorandr/) takes precedence over system configuration (/etc/xdg/autorandr/).
    3. Scripts in .d directories (e.g., postswitch.d/) are executed by filename (e.g., 10-wallpaper, 20-restart-wm).

    Environment Variables: Use these variables within your scripts:

    • AUTORANDR_CURRENT_PROFILE: The profile being activated (Note: during preswitch, this reports the upcoming profile).
    • AUTORANDR_CURRENT_PROFILES: List of current profiles.
    • AUTORANDR_PROFILE_FOLDER: Path to the profile folder.
    • AUTORANDR_MONITORS: Monitor information.

    Example: Notify via desktop notification:

    notify-send -i display "Display profile" "$AUTORANDR_CURRENT_PROFILE"
    notify-send -i display "Display profile" "$AUTORANDR_CURRENT_PROFILE"
  2. Save and load display profiles

    master

    Use autorandr to capture and apply specific monitor configurations.

    Save a profile: Capture your current setup and name it (e.g., mobile or docked):

    autorandr --save <profile_name>

    Detect active profile: List available profiles and indicate which one is currently detected:

    autorandr

    Apply a profile: Automatically switch to the detected profile:

    autorandr --change

    Manually load a specific profile:

    autorandr <profile_name>
    # OR
    autorandr --load <profile_name>

    Force reconfiguration: If the configuration is identical to the current one, autorandr will skip it. To force a reload:

    autorandr --load <profile_name> --force
    autorandr --save mobile
    autorandr --save docked
    autorandr --change
    autorandr <profile>
    autorandr --load <profile> --force
  3. Install autorandr

    master

    You can install autorandr as a system-wide application using a Makefile, which also sets up automatic invocation for monitor connections, system wake-ups, and X11 logins. Alternatively, use your distribution's package manager or pip.

    To install via Makefile (requires root):

    make install

    To install via pip (latest from git):

    sudo pip install "git+http://github.com/phillipberndt/autorandr#egg=autorandr"

    To install a stable version via pip:

    sudo pip install autorandr
    sudo pip install "git+http://github.com/phillipberndt/autorandr#egg=autorandr"
  4. Run autorandr in Wayland

    master

    By default, autorandr checks for the WAYLAND_DISPLAY environment variable to avoid running xrandr in Wayland environments.

    To force autorandr to run in a Wayland session, unset the WAYLAND_DISPLAY variable:

    WAYLAND_DISPLAY= autorandr
    WAYLAND_DISPLAY= autorandr
  5. Configure NVidia udev triggers

    master

    To ensure udev correctly detects drm events from the native NVidia driver, you must enable nvidia-drm.modeset.

    Create a file at /etc/modprobe.d/nvidia-drm-modeset.conf with the following content:

    options nvidia_drm modeset=1
    options nvidia_drm modeset=1
  6. Configure default settings via settings.ini

    master

    You can store default values for any option in an INI file located at ~/.config/autorandr/settings.ini. Options are placed under a [config] section using the format option-name=option-argument.

    Example: Skipping gamma settings (useful if using redshift):

    [config]
    skip-options=gamma
    [config]
    skip-options=gamma
  7. Configure fallback and default profiles

    master

    If no suitable profile is identified, autorandr keeps the current configuration. To switch to a fallback instead, use the --default flag.

    Using the --default flag:

    autorandr --default <profile>

    Virtual configurations: There are three special virtual configurations that automatically incorporate all connected screens:

    • horizontal
    • vertical
    • common

    You can symlink default to one of these names in your configuration directory to use them as the system-wide default.

  8. Match monitors using Wildcard EDID

    master
    In the setup files located within your profile directories (e.g., ~/.config/autorandr/*/setup), you can use an asterisk (*) in the EDID strings. This enables wildcard matching against connected monitors using standard file name globbing rules, allowing a single profile to match multiple or any monitors.