Kelson Martins

Screen Persistence on Linux with Autorandr

Introduction

Kelson

Kelson

Software engineer. Geek. Traveller. Wannabe athlete. Lifelong student. Works at IBM and hosts the @HardcodeCast.


LATEST POSTS

Binary Search Algorithms with Examples 07th June, 2022

Configuring Openshift Identity Providers 06th February, 2022

Linux

Screen Persistence on Linux with Autorandr

Posted on .

If you are using a Linux distribution with the X11 windowing system—like my current setup, Manjaro Xfce—you’ve likely faced the constant inconvenience of reconfiguring your screen positions. You connect to a dual-monitor setup at your desk, arrange everything perfectly, but the moment you unplug or reboot, your settings vanish.

While Wayland users have tools like kanshi, X11 users (which you can verify by running echo $XDG_SESSION_TYPE in your terminal) need a proper alternative. That alternative is autorandr.

1. Installation

autorandr is available in the official repositories of most major Linux distributions. Use the command that matches your system:

Manjaro / Arch Linux:

sudo pacman -S autorandr

Ubuntu / Debian / Linux Mint:

sudo apt update && sudo apt install autorandr

Fedora:

sudo dnf install autorandr

openSUSE:

sudo zypper install autorandr

2. Enable the Service

To ensure autorandr automatically detects hardware changes (like plugging in an HDMI cable), you must enable and start its systemd user service. Using the --user flag ensures the service runs specifically for your desktop session:

systemctl --user enable --now autorandr.service

3. Configure Your Dual-Screen Setup

Connect your external monitor. Use the Xfce Display Settings (or your specific desktop’s display tool) to arrange your screens exactly how you want them—for example, placing the external monitor above or to the right of your laptop.

4. Save the Dual Configuration

Once you are happy with the layout, save this profile:

autorandr --save dual

5. Configure Your Single-Screen Setup

Now, disconnect your external monitor. Your laptop screen should revert to its default state.

6. Save the Single Configuration

Save this state as your single-screen profile:

autorandr --save single

7. Verify Your Profiles

You can list all the profiles you have created to ensure they were saved correctly:

autorandr --list

You should see both dual and single in the output.

8. Testing the Setup

To test, reconnect your external monitor. The arrangement should be applied automatically. You can also manually force a profile change to verify everything is working as intended:

# Force the single screen profile
autorandr --change single

# Force the dual screen profile
autorandr --change dual

Where is the config stored?

If you ever need to manually tweak your profiles or back them up, autorandr stores its configuration files in:

~/.config/autorandr/

Each subdirectory represents a profile and contains the necessary configuration to recreate that specific layout.

Conclusion

By using autorandr, you take the hassle out of multi-monitor management. Whether you are docking at a desk or presenting in a boardroom, your Linux environment will now adapt to your hardware instantly. No more dragging windows or resetting resolutions—just plug in and play.

Kelson

Kelson

//iamkel.dev

Software engineer. Geek. Traveller. Wannabe athlete. Lifelong student. Works at IBM and hosts the @HardcodeCast.

Navigation