Exploring the 'xrandr' Command for Screen Configuration (with examples)
- Linux
- December 17, 2024
The xrandr
command is a powerful utility used in Unix-like operating systems to set the size, orientation, and/or reflection of the outputs for a screen. This tool is part of the X.Org Server distribution and is widely used for configuring display settings on the fly without the need for a restart or logging out. It’s particularly useful for users who need to manage multiple displays, adjust resolutions, orientations, and other screen settings dynamically.
Use case 1: Display the current state of the system, including known screens and resolutions
Code:
xrandr --query
Motivation:
This command is fundamental when you first want to inspect the configurations of your current displays. Before making any changes, knowing the current state is crucial to avoid misconfigurations and to understand what outputs and modes are available.
Explanation:
xrandr
: Initiates the utility.--query
: This flag is used to query the current state of the system. It provides detailed information about available outputs, their connected state, resolutions they support, and current settings.
Example output:
Screen 0: minimum 320 x 200, current 1920 x 1080, maximum 8192 x 8192
DP1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 477mm x 268mm
1920x1080 60.00*+
1680x1050 59.95
1280x1024 60.02
HDMI2 disconnected (normal left inverted right x axis y axis)
VGA1 disconnected (normal left inverted right x axis y axis)
LVDS1 connected (normal left inverted right x axis y axis)
1366x768 60.00 +
Use case 2: Disable disconnected outputs and enable connected ones with default settings
Code:
xrandr --auto
Motivation:
This command is helpful for quickly resetting display settings to their default state — especially useful after connecting or disconnecting monitors without manually specifying the resolutions or positions for each display.
Explanation:
xrandr
: Begins the command to manipulate screen configurations.--auto
: Automatically enables outputs that are connected and disables outputs that are disconnected, applying the best possible settings for each.
Example output:
N/A – This command executes without producing direct command line output but should result in the displays being reset to their default settings as described.
Use case 3: Change the resolution and update frequency of DisplayPort 1 to 1920x1080, 60Hz
Code:
xrandr --output DP1 --mode 1920x1080 --rate 60
Motivation:
This use case is pertinent when needing to set a display’s resolution and refresh rate manually. It’s typically used when you want to optimize screen quality or avoid flickering issues that might not be resolved with automatic settings.
Explanation:
xrandr
: Invokes the tool to configure display settings.--output DP1
: Specifies the particular display output (DisplayPort 1 in this case) to configure.--mode 1920x1080
: Sets the resolution for the specified output to 1920x1080 pixels.--rate 60
: Sets the refresh rate of the display to 60Hz.
Example output:
N/A – As with many xrandr commands, changes are applied directly to the display settings rather than producing textual output.
Use case 4: Set the resolution of HDMI2 to 1280x1024 and put it on the right of DP1
Code:
xrandr --output HDMI2 --mode 1280x1024 --right-of DP1
Motivation:
This command is beneficial when setting up a dual-monitor arrangement where you need to specify the screen layout relative to each other.
Explanation:
xrandr
: Activates the display config utility.--output HDMI2
: Selects the HDMI2 output for configuration.--mode 1280x1024
: Changes the resolution of HDMI2 to 1280x1024 pixels.--right-of DP1
: Places the HDMI2 display to the right of DisplayPort 1.
Example output:
N/A – Configuration changes apply to the screens themselves with no direct terminal output.
Use case 5: Disable the VGA1 output
Code:
xrandr --output VGA1 --off
Motivation:
Disabling a specific display output is crucial when troubleshooting display issues or when a monitor is physically disconnected but still being erroneously detected by the system.
Explanation:
xrandr
: Initiates the screen configuration tool.--output VGA1
: Targets the VGA1 output for changes.--off
: Disables the specified display output.
Example output:
N/A – The impact is seen in the display configuration, with no textual output confirming the change.
Use case 6: Set the brightness for LVDS1 to 50%
Code:
xrandr --output LVDS1 --brightness 0.5
Motivation:
Adjusting brightness is key in different lighting conditions or for reducing eye strain. This command is often utilized on laptops where the brightness needs to be managed without using dedicated hardware buttons.
Explanation:
xrandr
: Calls the tool for configuring display outputs.--output LVDS1
: Selects the LVDS1 output, typically used for laptop displays.--brightness 0.5
: Adjusts the brightness level to 50% of its maximum.
Example output:
N/A – Brightness adjustments are implemented directly on the screen with no feedback in the terminal.
Use case 7: Display the current state of any X server
Code:
xrandr --display :0 --query
Motivation:
This use case allows users to query a specific X server’s display setup. This can be crucial in multi-user or complex environments where multiple X servers might be running, providing insight into a particular server’s display state.
Explanation:
xrandr
: Engages the tool for querying or setting display configurations.--display :0
: Specifies which X server’s display to query.--query
: Asks for the current configuration of the specified X server.
Example output:
Screen 0: minimum 320 x 200, current 1920 x 1080, maximum 8192 x 8192
DP1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 477mm x 268mm
1920x1080 60.00*+
1680x1050 59.95
1280x1024 60.02
Conclusion:
The xrandr
tool is an invaluable asset for managing and configuring screens on systems running the X Window System. Its versatility allows customization of display settings through simple command-line inputs, enhancing user experiences across a range of use cases from resolution adjustments to output management and beyond. Understanding these different commands ensures users can effectively optimize their display environments for comfort and functionality.