Managing Displays and Monitors in Linux Using xrandr

The Linux operating system primarily manages screen resolutions, refresh rates, and multi-monitor layouts within the X11 display server via the X Resize and Rotate (RandR) extension. The primary command-line interface for this extension is xrandr, a utility that enables users and desktop environments to query connected video hardware, adjust display properties, reposition screens in a virtual space, and manage monitor states dynamically without restarting the graphical user interface.

The Role of RandR and xrandr in X11

Under the traditional X11 architecture, the X server creates a single root window that represents the entire desktop canvas. The RandR extension allows the server to change the size, orientation, and reflection of this canvas on the fly. Rather than hardcoding display outputs in configuration files like xorg.conf, xrandr interacts directly with the video drivers through the kernel mode setting (KMS) layer to read Extended Display Identification Data (EDID) from monitors, discovering supported capabilities automatically.

Detecting Connected Displays

Running the xrandr command without any arguments queries the display subsystem and returns the status of all available video outputs:

xrandr

The output reveals:

Modifying Screen Resolution and Refresh Rate

To change the resolution or refresh rate of a specific screen, use the --output, --mode, and optional --rate flags:

xrandr --output HDMI-1 --mode 1920x1080 --rate 60.00

This instruction commands the X server to apply the specified mode directly to the display output, adjusting the desktop viewport to match the selected dimensions.

Configuring Multi-Monitor Workspaces

When multiple displays are connected, xrandr maps each display onto a shared two-dimensional coordinate system. By default, secondary monitors may mirror the primary display. To extend the desktop, relative spatial flags are used to arrange the virtual canvas:

For precise layouts, absolute pixel offsets can be defined using the --pos flag:

xrandr --output eDP-1 --mode 1920x1080 --pos 0x0 --output HDMI-1 --mode 1920x1080 --pos 1920x0

Rotating and Disabling Displays

xrandr can rotate the display output to accommodate vertical monitors or flip orientations using the --rotate flag, which accepts normal, left, right, or inverted:

xrandr --output DP-1 --rotate right

To turn off an unused or disconnected display output and release graphics resources:

xrandr --output HDMI-1 --off

Adding Custom Resolutions

If an attached display fails to report a supported resolution through its EDID, a custom mode can be manually generated and assigned:

  1. Generate the modeline values using the cvt utility:
    cvt 2560 1440 60
  2. Create the new mode in xrandr using the output generated by cvt:
    xrandr --newmode "2560x1440_60.00" 312.25 2560 2752 3024 3488 1440 1443 1448 1493 -hsync +vsync
  3. Associate the newly defined mode with the target output:
    xrandr --addmode HDMI-1 "2560x1440_60.00"
  4. Apply the mode:
    xrandr --output HDMI-1 --mode "2560x1440_60.00"

Persisting Configurations Across Reboots

Changes made through the xrandr command-line tool apply immediately to the active graphical session, but they do not persist after a system restart. To make configurations permanent, the appropriate xrandr commands can be added to the user's startup initialization files (such as ~/.xprofile or ~/.xinitrc), or configured via display manager setup scripts (such as LightDM or SDDM) to run before the desktop environment loads. Modern desktop environments like GNOME and KDE handle these commands automatically in the background through graphical settings interfaces that write persistent configurations to XML or configuration files.