Managing monitors using the XRANDR command on Linux
My main development laptop uses Ubuntu 18.04 LTS, server edition, with a very light weight tiling window manager called i3. This window manager is primarily targeted at advanced users and developers. It’s a very efficient windowing manager but doesn’t come with very many bells and whistles.
Occasionally I need to attach my laptop to a large monitor, via HDMI, to present to a technical team. This article covers how to use the xrandr command on Linux to change the default monitor and set resolutions.
Start by installing xrandr:
sudo apt-get install xrandr
You can then list the attached monitors by running the following command:
xrandr --listmonitors Monitors: 2 0: +*LVDS-1 1360/344x768/194+0+0 LVDS-1 1: HDMI-1 1280/339x1002/265+0+0 HDMI-1
Sending output to a new monitor & define a resolution
Once you know the device name for the monitor you’re interested in controlling, then you can send the video signal to that monitor by using the output switch. You can also define the screen resolution to use by passing in the resolution dimensions using the mode switch. The screen resolution dimensions are passed using the width x height notation.
xrandr --output HDMI-1 --mode 1024x768
Turning off your laptops display
Once you have the video signal going to your newly plugged in monitor, you might choose to switch off the display on your laptop. You can do this by passing the device name to the output command line option. In this example, LVDS-1 is the device name of my laptops monitor.
xrandr --output LVDS-1 --off
Changing the brightness levels
Rather than switching off your laptops display, you can also decrease the brightness level. The brightness command line option takes a value from off (0) to full brightness (1). So for example, to reduce the brightness of your monitor to one quarter — you’d use a value of 0.25. To reduce the brightness by half you’d use 0.5
xrandr --output LVDS-1 --brightness 0.25