How to Set Up Dual Monitors with xrandr on Arch Linux

How to Set Up Dual Monitors with xrandr on Arch Linux

Using dual monitors can significantly improve your productivity, especially for tasks that benefit from additional screen space—like programming, video editing, system administration, or even multitasking with communication tools and browsers. On Arch Linux, a lightweight and flexible distribution, setting up dual monitors manually using the xrandr utility is a straightforward and powerful solution.

This guide will walk you through the process of configuring dual monitors using xrandr, providing step-by-step instructions, tips for troubleshooting, and methods to make your configuration persistent across reboots.


What is xrandr?

xrandr (short for X Resize, Rotate and Reflect) is a command-line tool used for managing screen resolutions, orientations, and multiple displays in X11-based systems. It’s a part of the xorg-xrandr package and is incredibly useful when you need to configure monitor layouts on systems that do not rely on full-fledged desktop environments with built-in display managers.


Prerequisites

Before we begin, make sure the following conditions are met:

  1. You are using X11: xrandr only works in Xorg/X11 environments.

  2. You have two or more monitors physically connected.

  3. The xorg-xrandr package is installed:

    sudo pacman -S xorg-xrandr
    
  4. Graphics drivers are properly installed: Ensure you have the correct drivers for your GPU (e.g., xf86-video-intel, nvidia, amdgpu, etc.).


Step 1: Identify Connected Displays

Start by identifying your currently connected monitors. Open a terminal and run:

xrandr

You’ll get output like:

Screen 0: minimum 320 x 200, current 1920 x 1080, maximum 16384 x 16384
HDMI-1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 510mm x 290mm
   1920x1080     60.00*+
DP-1 connected 1280x1024+1920+0 (normal left inverted right x axis y axis) 376mm x 301mm
   1280x1024     60.02*+

In this case, HDMI-1 and DP-1 are the names of the connected displays. These names will be used in subsequent xrandr commands.


Step 2: Basic Dual Monitor Configuration

Let’s assume:

  • HDMI-1 is your primary monitor.
  • DP-1 is the secondary monitor.
  • You want to place the secondary monitor to the right of the primary.

Run:

xrandr --output HDMI-1 --primary --auto --output DP-1 --auto --right-of HDMI-1

Breakdown

  • --output HDMI-1: Specifies the first monitor.
  • --primary: Sets it as the primary display.
  • --auto: Automatically sets the best resolution.
  • --output DP-1 --auto: Enables the second monitor.
  • --right-of HDMI-1: Places the second monitor to the right of the first.

You can also use --left-of, --above, --below, or --same-as for other layouts.


Step 3: Custom Resolutions and Scaling

If one of your monitors has a lower or higher resolution and you want to scale it to match the other, you can use:

xrandr --output DP-1 --scale 1.5x1.5

This scales the output by a factor of 1.5. It’s particularly helpful when using a HiDPI monitor with a standard one.

For adding custom resolutions:

  1. Generate modeline using cvt:

    cvt 1920 1080
    

    Output:

    Modeline "1920x1080_60.00"  173.00  1920 2048 2248 2576  1080 1083 1088 1120 -hsync +vsync
    
  2. Add the new mode:

    xrandr --newmode "1920x1080_60.00" 173.00 1920 2048 2248 2576 1080 1083 1088 1120 -hsync +vsync
    xrandr --addmode DP-1 "1920x1080_60.00"
    xrandr --output DP-1 --mode "1920x1080_60.00"
    

Step 4: Creating a Startup Script

Since xrandr configurations are not persistent, you’ll need to save them in a script and set it to run at login.

  1. Create a shell script:

    nano ~/.xrandr-setup.sh
    
  2. Add your configuration:

    #!/bin/bash
    xrandr --output HDMI-1 --primary --auto --output DP-1 --auto --right-of HDMI-1
    
  3. Make it executable:

    chmod +x ~/.xrandr-setup.sh
    
  4. Add it to your .xinitrc if you use startx:

    echo "~/.xrandr-setup.sh" >> ~/.xinitrc
    

    Or, for a display manager (like LightDM), configure an autostart entry:

    mkdir -p ~/.config/autostart
    nano ~/.config/autostart/xrandr.desktop
    

    Add the following:

    [Desktop Entry]
    Type=Application
    Exec=/home/yourusername/.xrandr-setup.sh
    Hidden=false
    NoDisplay=false
    X-GNOME-Autostart-enabled=true
    Name=Display Setup
    Comment=Setup dual monitors with xrandr
    

Step 5: Troubleshooting

1. Monitor not detected

If a monitor does not appear in xrandr, try reconnecting cables or restarting the display server. You may also need to check GPU driver installation.

2. Resolution issues

If a resolution isn’t available, create a custom mode using cvt or gtf.

3. Black screen on one monitor

Try disabling and re-enabling the output:

xrandr --output DP-1 --off
xrandr --output DP-1 --auto --right-of HDMI-1

4. Cursor confined to one screen

Make sure the screens are not mirrored or overlapping. Use --right-of or --left-of appropriately.


Optional: Use arandr for a GUI

If you prefer a graphical tool to generate the script, install arandr:

sudo pacman -S arandr

Configure your screens, then save the layout to a script from the GUI. You can then use that script in your .xinitrc or autostart.


Conclusion

Setting up dual monitors with xrandr on Arch Linux gives you a high level of control over your display layout. While it requires a bit more effort compared to GUI-based configuration tools in desktop environments, it is extremely flexible and lightweight—perfectly aligning with the Arch Linux philosophy.

Once set up properly, your dual-monitor system can enhance your workflow, making tasks more efficient and enjoyable. With tools like arandr or simple shell scripts, you can automate the process and enjoy a seamless experience each time you boot into your system.


Quick Reference

TaskCommand
List displaysxrandr
Set up dual monitorsxrandr --output HDMI-1 --auto --output DP-1 --auto --right-of HDMI-1
Set primary monitorxrandr --output HDMI-1 --primary
Turn off a monitorxrandr --output DP-1 --off
Scale outputxrandr --output DP-1 --scale 1.5x1.5
Add custom resolutionxrandr --newmode ... && xrandr --addmode ...