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:
xrandrThe output reveals:
- Output Names: Identifiers assigned by the graphics
driver, such as
eDP-1(internal laptop screen),HDMI-1, orDP-1(DisplayPort). - Connection Status: Whether a port is
connectedordisconnected. - Primary Display: Marked with the
primarykeyword. - Available Modes: A list of supported resolutions
and refresh rates. An asterisk (
*) denotes the currently active mode, while a plus sign (+) indicates the monitor's preferred native resolution.
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.00This 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:
- Place a monitor to the right:
xrandr --output HDMI-1 --auto --right-of eDP-1 - Place a monitor to the left, above, or below: Use
--left-of,--above, or--belowrespectively. - Mirror displays:
xrandr --output HDMI-1 --auto --same-as eDP-1 - Designate the primary monitor:
xrandr --output eDP-1 --primary
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 1920x0Rotating 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 rightTo turn off an unused or disconnected display output and release graphics resources:
xrandr --output HDMI-1 --offAdding Custom Resolutions
If an attached display fails to report a supported resolution through its EDID, a custom mode can be manually generated and assigned:
- Generate the modeline values using the
cvtutility:cvt 2560 1440 60 - Create the new mode in
xrandrusing the output generated bycvt:xrandr --newmode "2560x1440_60.00" 312.25 2560 2752 3024 3488 1440 1443 1448 1493 -hsync +vsync - Associate the newly defined mode with the target output:
xrandr --addmode HDMI-1 "2560x1440_60.00" - 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.