I bought a new monitor at home and added a second monitor in the office, so I had a lot to do with the graphics of my Linux setup.
What do you use in these cases? My preferred tool for all these operations is certainly xrandr .
In particular I’m used to use it from the command line version and after doing some tests using the syntax that i’ve found in the startup of the graphic environment.
In this article we will see some common use case.
The X Resize, Rotate and Reflect Extension (RandR) allows clients to dynamically change X screens, so as to resize, rotate and reflect the root window of a screen. The initial X11 design did not anticipate the need for dynamic resizing and it was necessary to restart the X server to bring about the changes. However, changing the screen resolution on the fly without changing the desktop size had been available under XFree86 since the beginning. RandR extension framework brought the ability to change display characteristics without restarting the X session. The extension framework allows laptops and handheld computers to change their screen size to drive external monitors at different resolutions than their built in screens.
If one’s desktop environment doesn’t provide a graphical tool for interfacing with this functionality, the xrandr command line tool may be used.
Most Linux distributions have the xrandr package in their repository, so you can install it using your package manager for ubuntu:
aptitude install libxrandr2
First check what version you are using:
#xrandr -v xrandr program version 1.3.3 Server reports RandR version 1.3
In my example I will always use the version 1.3, some features may not work on former version.
To find out what monitors are connected you can use the query command with the following:
#xrandr -q Screen 0: minimum 320 x 200, current 1440 x 900, maximum 4096 x 4096 VGA-0 connected 1440x900+0+0 (normal left inverted right x axis y axis) 476mm x 268mm 1920x1080 60.0 + 1600x1200 65.0 60.0 1680x1050 69.9 60.0 1600x1024 60.2 1400x1050 74.8 70.0 60.0 60.0 1280x1024 75.0 60.0 1440x900 75.0* 59.9 1280x960 60.0 1360x768 60.0 59.8 1280x800 74.9 59.8 1152x864 75.0 75.0 70.0 60.0 1280x768 74.9 59.9 1024x768 75.1 75.0 70.1 60.0 832x624 74.6 800x600 72.2 75.0 60.3 56.2 848x480 60.0 640x480 72.8 75.0 72.8 75.0 66.7 60.0 59.9 59.9 720x400 70.1 DVI-0 connected 1440x900+0+0 (normal left inverted right x axis y axis) 476mm x 268mm 1920x1080 60.0 + 1600x1200 65.0 60.0 1680x1050 69.9 60.0 1600x1024 60.2 1400x1050 74.8 70.0 60.0 60.0 1280x1024 75.0 60.0 1440x900 75.0* 59.9 1280x960 60.0 1360x768 60.0 59.8 1280x800 74.9 59.8 1152x864 75.0 75.0 70.0 60.0 1280x768 74.9 59.9 1024x768 75.1 75.0 70.1 60.0 832x624 74.6 800x600 72.2 75.0 60.3 56.2 848x480 60.0 640x480 72.8 75.0 72.8 75.0 66.7 60.0 59.9 59.9 720x400 70.1 LVDS connected (normal left inverted right x axis y axis) 1024x768 60.0 + 60.0 1360x768 59.8 800x600 60.3 59.9 848x480 59.7 720x480 59.7 640x480 59.9 59.4 S-video disconnected (normal left inverted right x axis y axis)
In my output you can see that I connected both VGA and DVI (I am still doing tests with my new monitor) and that LVDS (laptop screen) is switched off and the S-video is not connected.
You can also see that with this simple command you can see all the resolution and refresh rate supported by the screens.
Basic use with screens
The basic use to give command to screens is
xrandr --output SCREEN COMANDO, so for example to turn off the VGA screen you can use:
xrandr --output VGA-0 --off
Turning off an output media is useful sometimes, for example i’ve at work a screen with resolution 1600×1200 while my laptop screen is 1680×1050, i use the laptop in a docking station with the lid closed so turning off LVDS help in getting a good resolution on the screen.
Change the resolution of a screen
To change resolution size, you can use xrandr and the –mode option:
xrandr --output DVI-0 --mode 1440x900 --refresh 75
With this command you’ll switch your DVI screen at 1440×900 resolution and with a refresh rate of 75.
Cloning a screen
Assumed to attach a VGA output to your laptop and you want to clone your main screen, so what appears on the laptop screen is also shown on the external screen, nothing more easy with xrandr:
xrandr --output LVDS --auto --output VGA --auto --same-as LVDS
In general use
$ xrandr -q to discover the appropriate output names for your configuration. The –auto option will select the preferred resolution for each output, this is identified with a plus (+) in the
$ xrandr -q listing and is normally the best resolution available.
2 screen side by side
it’s possible to create a virtual desktop putting 2 screen side by side, it is possible to set screen locations as –left-of, –right-of, –above and –below. Assuming displays sizes of the LVDS 1024×768 and the VGA 1200×1600 you can use one of these 2 commands:
$ xrandr --output LVDS --auto --output VGA --auto --right-of LVDS and $ xrandr --output LVDS --mode 1024x768 --pos 0x0 --output VGA --mode 1600x1200 --pos 1024x0
They will give the same result, so i suggest using the first version, –right-of it’s much more easy to rembember and to use.
Automate it on login
You can automate your xrandr operation putting them in the directory /etc/X11/Xsession.d/, so for example you could add a file: /etc/X11/Xsession.d/45custom_xrandr-settings
# If an external monitor is connected, place it with xrandr # External output may be "VGA" or "VGA-0" or "DVI-0" or "TMDS-1" EXTERNAL_OUTPUT="VGA" INTERNAL_OUTPUT="LVDS" # EXTERNAL_LOCATION may be one of: left, right, above, or below EXTERNAL_LOCATION="right" case "$EXTERNAL_LOCATION" in left|LEFT) EXTERNAL_LOCATION="--left-of $INTERNAL_OUTPUT" ;; right|RIGHT) EXTERNAL_LOCATION="--right-of $INTERNAL_OUTPUT" ;; top|TOP|above|ABOVE) EXTERNAL_LOCATION="--above $INTERNAL_OUTPUT" ;; bottom|BOTTOM|below|BELOW) EXTERNAL_LOCATION="--below $INTERNAL_OUTPUT" ;; *) EXTERNAL_LOCATION="--left-of $INTERNAL_OUTPUT" ;; esac xrandr |grep $EXTERNAL_OUTPUT | grep " connected " if [ $? -eq 0 ]; then xrandr --output $INTERNAL_OUTPUT --auto --output $EXTERNAL_OUTPUT --auto $EXTERNAL_LOCATION # Alternative command in case of trouble: # (sleep 2; xrandr --output $INTERNAL_OUTPUT --auto --output $EXTERNAL_OUTPUT --auto $EXTERNAL_LOCATION) & else xrandr --output $INTERNAL_OUTPUT --auto --output $EXTERNAL_OUTPUT --off fi
Several graphical frontends are available for xrandr (all using GTK):
- Zarfy — A GUI to libxrandr. It presents the user with visual representaion of active displays on an interactive map of the screen memory. Features free postioning, configuration saving, scripting for R&R and an alternate gui for switching between monitors.
- arkOS: build your Cloud with a Raspberry Pi
- Review and repair a Linux SWAP Partition
- Linux Games: Faster Than Light
- Introduction to Vagrant – Part 1
- Linux Terminal: Poor Man’s Spotify
Find me on Google+