Difference between revisions of "Xrandr"

From ArchWiki
Jump to: navigation, search
m
(Testing configuration: man template)
 
(90 intermediate revisions by 25 users not shown)
Line 1: Line 1:
[[Category:X Server]]
+
{{Lowercase title}}
 +
[[Category:X server]]
 +
[[ru:Xrandr]]
 +
[[ja:Xrandr]]
 
[[zh-CN:Xrandr]]
 
[[zh-CN:Xrandr]]
== Dynamically testing different resolutions ==
+
{{Related articles start}}
 +
{{Related|Xorg}}
 +
{{Related|Multihead}}
 +
{{Related articles end}}
  
{{Ic|xrandr}} shows you the names of different outputs available on your system (LVDS, VGA-0, etc.) and resolutions available on each:
+
''xrandr'' is an official configuration utility to the [[Wikipedia:RandR|RandR]] [[Wikipedia:X Window System|X Window System]] extension. It can be used to set the size, orientation or reflection of the outputs for a screen. For configuring multiple monitors see the [[Multihead]] page.
  
Screen 0: minimum 320 x 200, current 1400 x 1050, maximum 1400 x 1400
+
== Installation ==
VGA disconnected (normal left inverted right x axis y axis)
+
LVDS connected 1400x1050+0+0 (normal left inverted right x axis y axis) 286mm x 214mm
+
    1400x1050      60.0*+  50.0 
+
[...]
+
  
You can direct xrandr to set a different resolution like this:
+
[[Install]] {{Pkg|xorg-xrandr}}. A graphical front end such as {{Pkg|arandr}} or {{Pkg|lxrandr}} is also available.
  
  xrandr --output LVDS --mode 1024x768
+
== Testing configuration ==
  
The refresh rate may also be changed, either at the same time or independently:
+
When run without any option, ''xrandr'' shows the names of different outputs available on the system ({{ic|LVDS}}, {{ic|VGA-0}}, etc.) and resolutions available on each:
  
  xrandr --output LVDS --mode 1024x768 --rate 75
+
{{hc|xrandr|
 +
Screen 0: minimum 320 x 200, current 1440 x 900, maximum 8192 x 8192
 +
VGA disconnected (normal left inverted right x axis y axis)
 +
LVDS connected (normal left inverted right x axis y axis)
 +
  1440x900      59.9*+
 +
  1280x854      59.9 
 +
  1280x800      59.8 
 +
...
 +
}}
  
{{Note|Changes you make using {{Ic|xrandr}} only last through the current session. xrandr has a lot more capabilities - see {{Ic|man xrandr}} for details.}}
+
You can use ''xrandr'' to set different resolution (must be present in the above list) on some output:
  
== Adding undetected resolutions ==
+
$ xrandr --output LVDS --mode 1280x800
  
Due to buggy hardware or drivers, your monitor's correct resolutions may not always be detected by xrandr. For example, the EDID data block queried from the monitor may be incorrect. However, we can add the desired resolutions to xrandr.
+
When multiple refresh rates are present in the list ('''not''' in the example above), it may be changed by the {{ic|--rate}} option, either at the same time or independently. For example:
  
First we run {{ic|gtf}} or {{ic|cvt}} to get the '''Modeline''' for the resolution we want:
+
$ xrandr --output LVDS --mode 1280x800 --rate 75
  
For some LCD screens (samsung 2343NW), the command "cvt -r" (= with reduced blanking) is to be used.
+
The {{ic|--auto}} option will turn the specified output on if it is off and set the preferred (maximum) resolution:
  
  $ cvt 1280 1024
+
  $ xrandr --output LVDS --auto
 
+
  # 1280x1024 59.89 Hz (CVT 1.31M4) hsync: 63.67 kHz; pclk: 109.00 MHz
+
  Modeline "1280x1024_60.00" 109.00  1280 1368 1496 1712  1024 1027 1034 1063 -hsync +vsync
+
  
Then we create a new xrandr mode. Note that the Modeline keyword needs to be ommited.
+
It is possible to specify multiple outputs in one command, e.g. to turn off {{ic|LVDS}} and turn on {{ic|HDMI-0}} with preferred resolution:
  
    xrandr --newmode "1280x1024_60.00"  109.00  1280 1368 1496 1712  1024 1027 1034 1063 -hsync +vsync
+
$ xrandr --output LVDS --off --output HDMI-0 --auto
  
After creating it we need an extra step to add this new mode to our current output (VGA1). We use just the name of the mode, since the parameters have been set previously.
+
{{Note|
 
+
* Changes you make using ''xrandr'' will only last through the current session.
    xrandr --addmode VGA1 1280x1024_60.00
+
* ''xrandr'' has a lot more capabilities - see {{man|1|xrandr|url=https://www.x.org/archive/X11R7.5/doc/man/man1/xrandr.1.html}} for details.
 
+
Now we change the resolution of the screen to the one we just added:
+
 
+
    xrandr --output VGA1 --mode 1280x1024_60.00
+
 
+
Note that these settings only take effect during this session.  
+
 
+
If you are not sure about the resolution you will test, you may add a "sleep 5" and a safe resolution command line following, like this :
+
 
+
    xrandr --output VGA1 --mode 1280x1024_60.00 && sleep 5 && xrandr --newmode "1024x768-safe" 65.00 1024 1048 1184 1344 768 771 777 806 -HSync -VSync && xrandr --addmode VGA1 1024x768-safe && xrandr --output VGA1 --mode 1024x768-safe
+
 
+
Also, change the output to the real one : VGA1 or DVI-I-1, ...
+
 
+
== Making xrandr changes persistent ==
+
 
+
There are several ways to make xrandr customizations permanent from session to session:
+
* {{ic|xorg.conf}} ( Preferred)
+
* {{ic|.xprofile}}
+
* kdm/gdm
+
 
+
=== Setting resolution changes in xorg.conf (Preferred) ===
+
 
+
While {{Ic|xorg.conf}} is largely empty these days, it can still be used for setting up resolutions. For example:
+
 
+
{{hc|/etc/X11/xorg.conf|
+
Section "Monitor"
+
    Identifier      "External DVI"
+
    Modeline        "1280x1024_60.00"  108.88  1280 1360 1496 1712  1024 1025 1028 1060  -HSync +Vsync
+
    Option          "PreferredMode" "1280x1024_60.00"
+
EndSection
+
Section "Device"
+
    Identifier      "ATI Technologies, Inc. M22 [Radeon Mobility M300]"
+
    Driver          "ati"
+
    Option          "Monitor-DVI-0" "External DVI"
+
EndSection
+
Section "Screen"
+
    Identifier      "Primary Screen"
+
    Device          "ATI Technologies, Inc. M22 [Radeon Mobility M300]"
+
    DefaultDepth    24
+
    SubSection "Display"
+
        Depth          24
+
        Modes  "1280x1024" "1024x768" "640x480"
+
    EndSubSection
+
EndSection
+
 
+
Section "ServerLayout"
+
        Identifier      "Default Layout"
+
        Screen          "Primary Screen"
+
EndSection
+
 
}}
 
}}
  
See {{Ic|man xorg.conf}} for full details on how to craft an {{ic|xorg.conf}} file.
+
== Configuration ==
  
=== Setting xrandr commands in xprofile ===
+
''xrandr'' is just a simple interface to the RandR extension and has no configuration file. However, there are multiple ways of achieving persistent configuration:
  
See [[Execute commands after X start]].
+
# The RandR extension can be configured via [[Xorg#Configuration|X configuration files]], see [[Multihead#RandR]] for details. This method provides only static configuration.
 +
# If you need dynamic configuration, you need to execute ''xrandr'' commands each time X server starts. See [[Autostarting#Graphical]] for details. This method has the disadvantage of occurring fairly late in the startup process, thus it will not alter the resolution of the [[display manager]] if you use one.
 +
# Custom scripts calling ''xrandr'' can be bound to events (for example when external monitor is plugged in), see [[acpid]] for details. The [[#Scripts]] section provides you with some example scripts that might be useful for this purpose.
  
This method has the disadvantage of occurring fairly late in the startup process thus it will not alter the resolution of the [[Display Manager]] if you use one.
+
{{Tip|Both KDM and GDM have startup scripts that are executed when X is initiated. For GDM, these are in {{ic|/etc/gdm/}}, while for KDM this is done at {{ic|/usr/share/config/kdm/Xsetup}} and for SDDM at {{ic|/usr/share/sddm/scripts/Xsetup}}. This method requires root access and mucking around in system config files, but will take effect earlier in the startup process than using xprofile.}}
  
=== Setting xrandr commands in kdm/gdm startup scripts ===
+
=== Scripts ===
  
Both KDM and GDM have startup scripts that are executed when X is initiated. For GDM, these are in {{ic|/etc/gdm/}} , while for KDM this is done at {{ic|/usr/share/config/kdm/Xsetup}}.
+
==== Toggle external monitor ====
  
This process requires root access and mucking around in system config files, but will take effect earlier in the startup process than using xprofile.
+
This script toggles between an external monitor (specified by {{ic|$EXT}}) and a default monitor (specified by {{ic|$IN}}), so that only one monitor is active at a time.
  
== Graphical frontends ==
+
The default monitor (specified by {{ic|$IN}}) should be connected when running the script, which is always true for a laptop.
There are some graphical frontends available for {{ic|xrandr}}:
+
  
=== ARandR ===
+
{{bc|<nowiki>
ARandR provides a simple and convenient visual front end.
+
 
+
The package can be found in the community repository: {{Pkg|arandr}}
+
 
+
=== LXrandR ===
+
The default monitor configuration tool for the [[LXDE]] desktop environment.
+
 
+
This package is part of the community repository: {{Pkg|lxrandr}}
+
 
+
== Troubleshooting ==
+
 
+
=== Resolution lower than expected ===
+
 
+
==== Try this first ====
+
 
+
If you video card is recognized but the resolution is lower than you expect, you may try this.
+
 
+
Background: ATI X1550 based video card and two LCD monitors DELL 2408(up to 1920x1200) and Samsung 206BW(up to 1680x1050). Upon first login after installation, the resolution default to 1152x864. xrandr does not list any resolution higher than 1152x864. You may want to try editing /etc/X11/xorg.conf, add a section about virtual screen, logout, login and see if this helps. If not then read on.
+
 
+
Change xorg.conf
+
{{hc|/etc/X11/xorg.conf|
+
Section "Screen"
+
        ...
+
        SubSection "Display"
+
                Virtual 3600 1200
+
        EndSubSection
+
EndSection
+
}}
+
 
+
About the numbers: DELL on the left and Samsung on the right. So the virtual width is of sum of both LCD width 3600=1920+1680; Height then is figured as the max of them, which is max(1200,1050)=1200. If you put one LCD above the other, use this calculation instead: (max(width1, width2), height1+height2).
+
 
+
==== Use cvt/xrandr tool to add the highest mode the LCD can do ====
+
 
+
The actual order was different, as I tried to add new mode to one LCD at a time. Below is the combined/all-in-one quote
+
$ cvt 1920 1200 60
+
# 1920x1200 59.88 Hz (CVT 2.30MA) hsync: 74.56 kHz; pclk: 193.25 MHz
+
Modeline "1920x1200_60.00"  193.25  1920 2056 2256 2592  1200 1203 1209 1245 -hsync +vsync
+
$ cvt 1680 1050 60
+
# 1680x1050 59.95 Hz (CVT 1.76MA) hsync: 65.29 kHz; pclk: 146.25 MHz
+
Modeline "1680x1050_60.00"  146.25  1680 1784 1960 2240  1050 1053 1059 1089 -hsync +vsync
+
$ xrandr --newmode "1920x1200_60.00"  193.25  1920 2056 2256 2592  1200 1203 1209 1245 -hsync +vsync
+
$ xrandr --newmode "1680x1050_60.00"  146.25  1680 1784 1960 2240  1050 1053 1059 1089 -hsync +vsync
+
$ xrandr --addmode DVI-1 "1920x1200_60.00"
+
$ xrandr --addmode DVI-0 "1680x1050_60.00"
+
 
+
== Obtaining modelines from Windows program PowerStrip ==
+
 
+
[http://www.x.org/wiki/FAQVideoModes#ObtainingmodelinesfromWindowsprogramPowerStrip Obtaining modelines from Windows program PowerStrip].
+
 
+
== Scripts ==
+
 
+
Toggle only secondary monitor, leave the default display on:
+
{{hc|~/bin/xdisplay|2=<nowiki>
+
 
#!/bin/bash
 
#!/bin/bash
#
+
intern=LVDS1
# This script toggles the extended monitor outputs if something is connected
+
extern=VGA1
#
+
  
# all available outputs
+
if xrandr | grep "$extern disconnected"; then
OUTPUTS=$(xrandr |awk '$2 ~ /connected/ {print $1}')
+
    xrandr --output "$extern" --off --output "$intern" --auto
 +
else
 +
    xrandr --output "$intern" --off --output "$extern" --auto
 +
fi
 +
</nowiki>}}
  
# your notebook LVDS monitor
+
{{Note|To leave the external monitor enabled, replace the ''else'' clause with {{ic|xrandr --output "$intern" --primary --auto --output "$extern" --right-of "$intern" --auto}}.}}
DEFAULT_OUTPUT=$(sed -ne 's/.*(LVDS[^ ]*).*/1/p' <<<$OUTPUTS)
+
  
# get info from xrandr
+
==== Example 3 ====
XRANDR=`xrandr`
+
  
EXECUTE=""
+
{{Accuracy|1=Basic shell mistakes: relying on quoting errors to relay arguments (instead of using arrays), convoluted grep+sed pipes (instead of awk), echo -e (instead of printf), ancient backtick format (instead of {{ic|$()}})}}
  
for CURRENT in $OUTPUTS
+
This script iterates through connected monitors, selects currently active monitor, turns next one on and the others off:
do
+
        if [[ $XRANDR == *$CURRENT\ connected*  ]] # is connected
+
        then
+
                if [[ $XRANDR == *$CURRENT\ connected\ \(* ]] # is disabled
+
                then
+
                        EXECUTE+="--output $CURRENT --auto --above $DEFAULT_OUTPUT "
+
                else
+
                        EXECUTE+="--output $CURRENT --off "
+
                fi
+
        else # make sure disconnected outputs are off
+
                EXECUTE+="--output $CURRENT --off "
+
        fi
+
done
+
 
+
xrandr --output $DEFAULT_OUTPUT --auto $EXECUTE
+
</nowiki>}}
+
 
+
Switches display, turning the others off:
+
 
+
{{hc|/usr/local/bin/toggle-display|2=<nowiki>
+
#!/bin/bash
+
#
+
# toggle-display.sh
+
#
+
# Iterates through connected monitors in xrander and switched to the next one
+
# each time it is run.
+
#
+
  
 +
{{bc|<nowiki>
 
# get info from xrandr
 
# get info from xrandr
xStatus=`xrandr`
+
connectedOutputs=$(xrandr | grep " connected" | sed -e "s/\([A-Z0-9]\+\) connected.*/\1/")
connectedOutputs=$(echo "$xStatus" | grep " connected" | sed -e "s/\([A-Z0-9]\+\) connected.*/\1/")
+
activeOutput=$(xrandr | grep -E " connected (primary )?[1-9]+" | sed -e "s/\([A-Z0-9]\+\) connected.*/\1/")
activeOutput=$(echo "$xStatus" | grep -e " connected [^(]" | sed -e "s/\([A-Z0-9]\+\) connected.*/\1/")
+
connected=$(echo $connectedOutputs | wc -w)
+
  
 
# initialize variables
 
# initialize variables
Line 222: Line 101:
 
for display in $connectedOutputs
 
for display in $connectedOutputs
 
do
 
do
 
 
# build default configuration
 
# build default configuration
 
if [ $i -eq 1 ]
 
if [ $i -eq 1 ]
Line 247: Line 125:
  
 
i=$(( $i + 1 ))
 
i=$(( $i + 1 ))
 
 
done
 
done
  
Line 263: Line 140:
 
</nowiki>}}
 
</nowiki>}}
  
You can also use xrr-events (from [https://aur.archlinux.org/packages/xrr-events-git/ AUR]), a daemon which listens to XrandR events and executes a script if a monitor has been plugged or unplugged. For more information and examples see man page.
+
==== Example 3a ====
  
== Using xrandr with VNC ==
+
{{Accuracy|1=Copy-paste of the previous example with even more mistakes added: unsafe usage of eval (xrandr output is not escaped or quoted), useless indirection (CMD=XRANDR, XRANDR=xrandr, ...), useless braces (do not replace quotes), uppercased variables (should be lowercased to avoid conflicts)}}
If you are using a VNC server that supports xrandr you can change the vnc resolution on the fly by using "xrandr -s <width>x<height>". tigervnc is an example of a client that supports xrandr
+
  
Example:
+
This script iterates over all xrandr outputs. If anything is connected it tries to figure out the best possible resolution places that right-of the previous display.
  
xrandr -s 1920x1200
+
The following uses it with {{AUR|srandrd}} and {{Pkg|i3-wm}}:
  
After you VNC in, if you open a console and type "xrandr" you will get a list of currently configured modes. Each of these modes can be activated with the xrandr -s option; however, if the mode you want does not exist in the list, you can add it by doing the following:
+
{{hc|~/.xprofile|
 +
srandrd ~/.i3/detect_displays.sh
 +
}}
  
Example: Say I want to add 1024x600 (a common netbook resolution)
+
{{bc|<nowiki>
 +
#!/bin/bash
  
First run CVT to get the correct modeline for the resolution you want to add
+
XRANDR="xrandr"
 +
CMD="${XRANDR}"
 +
declare -A VOUTS
 +
eval VOUTS=$(${XRANDR}|awk 'BEGIN {printf("(")} /^\S.*connected/{printf("[%s]=%s ", $1, $2)} END{printf(")")}')
 +
declare -A POS
 +
#XPOS=0
 +
#YPOS=0
 +
#POS="${XPOS}x${YPOS}"
  
$ cvt 1024 600
+
POS=([X]=0 [Y]=0)
  
You will get something like the following output
+
find_mode() {
 +
  echo $(${XRANDR} |grep ${1} -A1|awk '{FS="[ x]"} /^\s/{printf("WIDTH=%s\nHEIGHT=%s", $4,$5)}')
 +
}
 +
 
 +
xrandr_params_for() {
 +
  if [ "${2}" == 'connected' ]
 +
  then
 +
    eval $(find_mode ${1})  #sets ${WIDTH} and ${HEIGHT}
 +
    MODE="${WIDTH}x${HEIGHT}"
 +
    CMD="${CMD} --output ${1} --mode ${MODE} --pos ${POS[X]}x${POS[Y]}"
 +
    POS[X]=$((${POS[X]}+${WIDTH}))
 +
    return 0
 +
  else
 +
    CMD="${CMD} --output ${1} --off"
 +
    return 1
 +
  fi
 +
}
 +
 
 +
for VOUT in ${!VOUTS[*]}
 +
do
 +
  xrandr_params_for ${VOUT} ${VOUTS[${VOUT}]}
 +
done
 +
set -x
 +
${CMD}
 +
set +x
 +
</nowiki>}}
 +
 
 +
==== Avoid X crash with xrasengan ====
 +
 
 +
Use this workaround to turn on connected outputs that may be in suspend mode and hence shown as disconnected, as is often the case of DisplayPort monitors:
 +
 
 +
{{bc|<nowiki>
 +
declare -i count=2
 +
declare -i seconds=1
 +
 
 +
while ((count)); do
 +
    xrandr >/dev/null
 +
    sleep $seconds
 +
    ((count--))
 +
done
 +
</nowiki>}}
 +
 
 +
[https://github.com/geyslan/xrasengan xrasengan] is an xrandr wrapper with this workaround built in.
 +
 
 +
$ xrasengan --force -on DisplayPort-0 -off HDMI-0
 +
 
 +
With the {{ic|--force}} option, ''xrasengan'' will update status of all outputs before HDMI-0 is turned off, avoiding an X crash if they were the only connected/active outputs.
 +
 
 +
To force reload current settings, ''xrasengan'' provides a {{ic|--try-reload-active-layout}} option, which uses {{ic|--force}} and ''unxrandr'' from the {{Pkg|arandr}} package to assemble the command line:
 +
 
 +
$ xrasengan --try-reload-active-layout
 +
 
 +
This can be used in systemd unit or in a keyboard binding to avoid blank screen when resuming DisplayPort monitors from suspend.
 +
 
 +
== Troubleshooting ==
 +
 
 +
=== Adding undetected resolutions ===
 +
 
 +
Due to buggy hardware or drivers, your monitor's correct resolutions may not always be detected by xrandr. For example, the EDID data block queried from the monitor may be incorrect. However, we can add the desired resolutions to xrandr.
 +
 
 +
First we run {{ic|gtf}} or {{ic|cvt}} to get the '''Modeline''' for the resolution we want:
 +
 
 +
For some LCD screens (samsung 2343NW), the command "cvt -r" (= with reduced blanking) is to be used.
 +
 
 +
{{hc|$ cvt 1280 1024|
 +
# 1280x1024 59.89 Hz (CVT 1.31M4) hsync: 63.67 kHz; pclk: 109.00 MHz
 +
Modeline "1280x1024_60.00"  109.00  1280 1368 1496 1712  1024 1027 1034 1063 -hsync +vsync
 +
}}
 +
 
 +
{{Note|If the Intel video driver {{pkg|xf86-video-intel}} is used, it may report the desired resolution along with its properties in {{ic|/var/log/Xorg.0.log}} — use that first if it is different from the output of {{ic|gtf}} or {{ic|cvt}}. For instance, the log and its use with xrandr:
 +
[    45.063] (II) intel(0): clock: 241.5 MHz  Image Size:  597 x 336 mm
 +
[    45.063] (II) intel(0): h_active: 2560  h_sync: 2600  h_sync_end 2632 h_blank_end 2720 h_border: 0
 +
[    45.063] (II) intel(0): v_active: 1440  v_sync: 1443  v_sync_end 1448 v_blanking: 1481 v_border: 0
 +
 
 +
xrandr --newmode "2560x1440" 241.50 2560 2600 2632 2720 1440 1443 1448 1481 -hsync +vsync
 +
}}
 +
 
 +
Then we create a new xrandr mode. Note that the Modeline keyword needs to be ommited.
 +
 
 +
$ xrandr --newmode "1280x1024_60.00"  109.00  1280 1368 1496 1712  1024 1027 1034 1063 -hsync +vsync
 +
 
 +
After creating it we need an extra step to add this new mode to our current output (VGA1). We use just the name of the mode, since the parameters have been set previously.
 +
 
 +
$ xrandr --addmode VGA1 1280x1024_60.00
 +
 
 +
Now we change the resolution of the screen to the one we just added:
 +
 
 +
$ xrandr --output VGA1 --mode 1280x1024_60.00
 +
 
 +
Note that these settings only take effect during this session.
 +
 
 +
If you are not sure about the resolution you will test, you may add a {{ic|sleep 5}} and a safe resolution command line following, like this:
 +
 
 +
$ xrandr --output VGA1 --mode 1280x1024_60.00 && sleep 5 && xrandr --newmode "1024x768-safe" 65.00 1024 1048 1184 1344 768 771 777 806 -HSync -VSync && xrandr --addmode VGA1 1024x768-safe && xrandr --output VGA1 --mode 1024x768-safe
 +
 
 +
Also, change {{ic|VGA1}} to correct output name.
 +
 
 +
==== EDID checksum is invalid ====
 +
 
 +
If the previous method results in an {{ic|*ERROR* EDID checksum is invalid}} error during boot, see [[KMS#Forcing modes and EDID]] and [http://askubuntu.com/questions/201081/how-can-i-make-linux-behave-better-when-edid-is-unavailable].
 +
 
 +
Or {{ic|xrandr --addmode}} might give you the error {{ic|X Error of failed request: BadMatch}}. NVIDIA users should read [[NVIDIA/Troubleshooting#xrandr BadMatch]]. {{ic|BadMatch}} could indicate an invalid EDID checksum. To verify that this is the case, run X in verbose mode (e.g. {{ic|startx -- -logverbose 6}}) and check your Xorg log for messages about a bad EDID.
 +
 
 +
==== Screen resolution reverts back after a blink ====
 +
 
 +
If you use [[GNOME]] and your monitor doesn't have an EDID, above [[#Adding undetected resolutions]] might not work, with your screen just blinking once, after {{ic|xrandr --output}}.
 +
 
 +
Poke around with {{ic|~/.config/monitors.xml}}, or delete the file completely, and then reboot.
 +
 
 +
It is better explained in [http://unix.stackexchange.com/questions/184941/gnome-prevents-high-resolution-vga-without-edid-info-over-vga this] article.
 +
 
 +
=== Permanently adding undetected resolutions ===
 +
 
 +
Once a suitable resolution is found using {{ic|xrandr}}, the mode can be permanently added by creating an entry in {{ic|/etc/X11/xorg.conf.d/}}:
 +
 
 +
{{hc|/etc/X11/xorg.conf.d/10-monitor.conf|
 +
Section "Monitor"
 +
    Identifier "VGA1"
 +
    Modeline "1280x1024_60.00"  109.00  1280 1368 1496 1712  1024 1027 1034 1063 -hsync +vsync
 +
    Option "PreferredMode" "1280x1024_60.00"
 +
EndSection
 +
 
 +
Section "Screen"
 +
    Identifier "Screen0"
 +
    Monitor "VGA1"
 +
    DefaultDepth 24
 +
    SubSection "Display"
 +
        Modes "1280x1024_60.00"
 +
    EndSubSection
 +
EndSection
 +
 
 +
Section "Device"
 +
    Identifier "Device0"
 +
    Driver "intel"
 +
EndSection}}
 +
 
 +
Replace {{ic|intel}} with the right driver, e.g. {{ic|nvidia}}.
 +
 
 +
=== Resolution lower than expected ===
 +
 
 +
{{Tip|Try [[#Adding undetected resolutions]] first, if it doesn't work, you may try this method.}}
 +
 
 +
If you video card is recognized but the resolution is lower than you expect, you may try this.
 +
 
 +
Background: ATI X1550 based video card and two LCD monitors DELL 2408(up to 1920x1200) and Samsung 206BW(up to 1680x1050). Upon first login after installation, the resolution default to 1152x864. xrandr does not list any resolution higher than 1152x864. You may want to try editing /etc/X11/xorg.conf, add a section about virtual screen, logout, login and see if this helps. If not then read on.
 +
 
 +
Change xorg.conf
 +
{{hc|/etc/X11/xorg.conf|
 +
Section "Screen"
 +
        ...
 +
        SubSection "Display"
 +
                Virtual 3600 1200
 +
        EndSubSection
 +
EndSection
 +
}}
 +
 
 +
About the numbers: DELL on the left and Samsung on the right. So the virtual width is of sum of both LCD width 3600=1920+1680; Height then is figured as the max of them, which is max(1200,1050)=1200. If you put one LCD above the other, use this calculation instead: (max(width1, width2), height1+height2).
  
# 1024x600 59.85 Hz (CVT) hsync: 37.35 kHz; pclk: 49.00 MHz
+
=== Full RGB in HDMI ===
Modeline "1024x600_60.00"  49.00  1024 1072 1168 1312  600 603 613 624 -hsync +vsync
+
  
Use that modeline output to run the commands below
+
It may occur that the [[Intel]] driver will not configure correctly the output of the HDMI monitor. It will set a limited color range (16-235) using the [https://patchwork.kernel.org/patch/1972181/ Broadcast RGB property], and the black will not look black, it will be grey.
  
xrandr --newmode "1024x600"  49.00  1024 1072 1168 1312  600 603 613 624 -hsync +vsync
+
To see if it is your case:
xrandr --addmode default "1024x600"
+
  
Doing the above will give you the ability to change to 1024x600 by typing xrandr -s 1024x600, but it will only last for the current x session. To insure that you can use the newly added resolution each time you start vncserver, add the following to ~/.vnc/xstartup
+
  $ xrandr --output HDMI1 --set "Broadcast RGB" "Full"
+
  xrandr --newmode "1024x600"   49.00  1024 1072 1168 1312  600 603 613 624 -hsync +vsync
+
xrandr --addmode default "1024x600"r
+
  
 
== See also ==
 
== See also ==
* [[DualScreen]] Arch wiki page. How to get dual screens with Xrandr
 
 
* https://wiki.ubuntu.com/X/Config/Resolution
 
* https://wiki.ubuntu.com/X/Config/Resolution
* https://bbs.archlinux.org/viewtopic.php?pid=652861
+
* [http://wiki.debian.org/XStrikeForce/HowToRandR12 RandR 1.2 tutorial]
* http://nouveau.freedesktop.org/wiki/Randr12Howto
+
* [http://www.thinkwiki.org/wiki/Xorg_RandR_1.2 Xorg RandR 1.2 on ThinkWiki]
* http://wiki.debian.org/XStrikeForce/HowToRandR12
+
* [http://www.x.org/wiki/FAQVideoModes#ObtainingmodelinesfromWindowsprogramPowerStrip FAQVideoModes - more information about modelines]
* man xrandr
+

Latest revision as of 16:02, 26 August 2016

Related articles

xrandr is an official configuration utility to the RandR X Window System extension. It can be used to set the size, orientation or reflection of the outputs for a screen. For configuring multiple monitors see the Multihead page.

Installation

Install xorg-xrandr. A graphical front end such as arandr or lxrandr is also available.

Testing configuration

When run without any option, xrandr shows the names of different outputs available on the system (LVDS, VGA-0, etc.) and resolutions available on each:

xrandr
Screen 0: minimum 320 x 200, current 1440 x 900, maximum 8192 x 8192
VGA disconnected (normal left inverted right x axis y axis)
LVDS connected (normal left inverted right x axis y axis)
   1440x900       59.9*+
   1280x854       59.9  
   1280x800       59.8  
...

You can use xrandr to set different resolution (must be present in the above list) on some output:

$ xrandr --output LVDS --mode 1280x800

When multiple refresh rates are present in the list (not in the example above), it may be changed by the --rate option, either at the same time or independently. For example:

$ xrandr --output LVDS --mode 1280x800 --rate 75

The --auto option will turn the specified output on if it is off and set the preferred (maximum) resolution:

$ xrandr --output LVDS --auto

It is possible to specify multiple outputs in one command, e.g. to turn off LVDS and turn on HDMI-0 with preferred resolution:

$ xrandr --output LVDS --off --output HDMI-0 --auto
Note:
  • Changes you make using xrandr will only last through the current session.
  • xrandr has a lot more capabilities - see xrandr(1) for details.

Configuration

xrandr is just a simple interface to the RandR extension and has no configuration file. However, there are multiple ways of achieving persistent configuration:

  1. The RandR extension can be configured via X configuration files, see Multihead#RandR for details. This method provides only static configuration.
  2. If you need dynamic configuration, you need to execute xrandr commands each time X server starts. See Autostarting#Graphical for details. This method has the disadvantage of occurring fairly late in the startup process, thus it will not alter the resolution of the display manager if you use one.
  3. Custom scripts calling xrandr can be bound to events (for example when external monitor is plugged in), see acpid for details. The #Scripts section provides you with some example scripts that might be useful for this purpose.
Tip: Both KDM and GDM have startup scripts that are executed when X is initiated. For GDM, these are in /etc/gdm/, while for KDM this is done at /usr/share/config/kdm/Xsetup and for SDDM at /usr/share/sddm/scripts/Xsetup. This method requires root access and mucking around in system config files, but will take effect earlier in the startup process than using xprofile.

Scripts

Toggle external monitor

This script toggles between an external monitor (specified by $EXT) and a default monitor (specified by $IN), so that only one monitor is active at a time.

The default monitor (specified by $IN) should be connected when running the script, which is always true for a laptop.

#!/bin/bash
intern=LVDS1
extern=VGA1

if xrandr | grep "$extern disconnected"; then
    xrandr --output "$extern" --off --output "$intern" --auto
else
    xrandr --output "$intern" --off --output "$extern" --auto
fi
Note: To leave the external monitor enabled, replace the else clause with xrandr --output "$intern" --primary --auto --output "$extern" --right-of "$intern" --auto.

Example 3

Tango-inaccurate.pngThe factual accuracy of this article or section is disputed.Tango-inaccurate.png

Reason: Basic shell mistakes: relying on quoting errors to relay arguments (instead of using arrays), convoluted grep+sed pipes (instead of awk), echo -e (instead of printf), ancient backtick format (instead of $()) (Discuss in Talk:Xrandr#)

This script iterates through connected monitors, selects currently active monitor, turns next one on and the others off:

# get info from xrandr
connectedOutputs=$(xrandr | grep " connected" | sed -e "s/\([A-Z0-9]\+\) connected.*/\1/")
activeOutput=$(xrandr | grep -E " connected (primary )?[1-9]+" | sed -e "s/\([A-Z0-9]\+\) connected.*/\1/")

# initialize variables
execute="xrandr "
default="xrandr "
i=1
switch=0

for display in $connectedOutputs
do
	# build default configuration
	if [ $i -eq 1 ]
	then
		default=$default"--output $display --auto "
	else
		default=$default"--output $display --off "
	fi

	# build "switching" configuration
	if [ $switch -eq 1 ]
	then
		execute=$execute"--output $display --auto "
		switch=0
	else
		execute=$execute"--output $display --off "
	fi

	# check whether the next output should be switched on
	if [ $display = $activeOutput ]
	then
		switch=1
	fi

	i=$(( $i + 1 ))
done

# check if the default setup needs to be executed then run it
echo "Resulting Configuration:"
if [ -z "$(echo $execute | grep "auto")" ]
then
	echo "Command: $default"
	`$default`
else
	echo "Command: $execute"
	`$execute`
fi
echo -e "\n$(xrandr)"

Example 3a

Tango-inaccurate.pngThe factual accuracy of this article or section is disputed.Tango-inaccurate.png

Reason: Copy-paste of the previous example with even more mistakes added: unsafe usage of eval (xrandr output is not escaped or quoted), useless indirection (CMD=XRANDR, XRANDR=xrandr, ...), useless braces (do not replace quotes), uppercased variables (should be lowercased to avoid conflicts) (Discuss in Talk:Xrandr#)

This script iterates over all xrandr outputs. If anything is connected it tries to figure out the best possible resolution places that right-of the previous display.

The following uses it with srandrdAUR and i3-wm:

~/.xprofile
srandrd ~/.i3/detect_displays.sh
#!/bin/bash

XRANDR="xrandr"
CMD="${XRANDR}"
declare -A VOUTS
eval VOUTS=$(${XRANDR}|awk 'BEGIN {printf("(")} /^\S.*connected/{printf("[%s]=%s ", $1, $2)} END{printf(")")}')
declare -A POS
#XPOS=0
#YPOS=0
#POS="${XPOS}x${YPOS}"

POS=([X]=0 [Y]=0)

find_mode() {
  echo $(${XRANDR} |grep ${1} -A1|awk '{FS="[ x]"} /^\s/{printf("WIDTH=%s\nHEIGHT=%s", $4,$5)}')
}

xrandr_params_for() {
  if [ "${2}" == 'connected' ]
  then
    eval $(find_mode ${1})  #sets ${WIDTH} and ${HEIGHT}
    MODE="${WIDTH}x${HEIGHT}"
    CMD="${CMD} --output ${1} --mode ${MODE} --pos ${POS[X]}x${POS[Y]}"
    POS[X]=$((${POS[X]}+${WIDTH}))
    return 0
  else
    CMD="${CMD} --output ${1} --off"
    return 1
  fi
}

for VOUT in ${!VOUTS[*]}
do
  xrandr_params_for ${VOUT} ${VOUTS[${VOUT}]}
done
set -x
${CMD}
set +x

Avoid X crash with xrasengan

Use this workaround to turn on connected outputs that may be in suspend mode and hence shown as disconnected, as is often the case of DisplayPort monitors:

declare -i count=2
declare -i seconds=1

while ((count)); do
    xrandr >/dev/null
    sleep $seconds
    ((count--))
done

xrasengan is an xrandr wrapper with this workaround built in.

$ xrasengan --force -on DisplayPort-0 -off HDMI-0

With the --force option, xrasengan will update status of all outputs before HDMI-0 is turned off, avoiding an X crash if they were the only connected/active outputs.

To force reload current settings, xrasengan provides a --try-reload-active-layout option, which uses --force and unxrandr from the arandr package to assemble the command line:

$ xrasengan --try-reload-active-layout

This can be used in systemd unit or in a keyboard binding to avoid blank screen when resuming DisplayPort monitors from suspend.

Troubleshooting

Adding undetected resolutions

Due to buggy hardware or drivers, your monitor's correct resolutions may not always be detected by xrandr. For example, the EDID data block queried from the monitor may be incorrect. However, we can add the desired resolutions to xrandr.

First we run gtf or cvt to get the Modeline for the resolution we want:

For some LCD screens (samsung 2343NW), the command "cvt -r" (= with reduced blanking) is to be used.

$ cvt 1280 1024
# 1280x1024 59.89 Hz (CVT 1.31M4) hsync: 63.67 kHz; pclk: 109.00 MHz
Modeline "1280x1024_60.00"  109.00  1280 1368 1496 1712  1024 1027 1034 1063 -hsync +vsync
Note: If the Intel video driver xf86-video-intel is used, it may report the desired resolution along with its properties in /var/log/Xorg.0.log — use that first if it is different from the output of gtf or cvt. For instance, the log and its use with xrandr:
[    45.063] (II) intel(0): clock: 241.5 MHz   Image Size:  597 x 336 mm
[    45.063] (II) intel(0): h_active: 2560  h_sync: 2600  h_sync_end 2632 h_blank_end 2720 h_border: 0
[    45.063] (II) intel(0): v_active: 1440  v_sync: 1443  v_sync_end 1448 v_blanking: 1481 v_border: 0
xrandr --newmode "2560x1440" 241.50 2560 2600 2632 2720 1440 1443 1448 1481 -hsync +vsync

Then we create a new xrandr mode. Note that the Modeline keyword needs to be ommited.

$ xrandr --newmode "1280x1024_60.00"  109.00  1280 1368 1496 1712  1024 1027 1034 1063 -hsync +vsync

After creating it we need an extra step to add this new mode to our current output (VGA1). We use just the name of the mode, since the parameters have been set previously.

$ xrandr --addmode VGA1 1280x1024_60.00

Now we change the resolution of the screen to the one we just added:

$ xrandr --output VGA1 --mode 1280x1024_60.00

Note that these settings only take effect during this session.

If you are not sure about the resolution you will test, you may add a sleep 5 and a safe resolution command line following, like this:

$ xrandr --output VGA1 --mode 1280x1024_60.00 && sleep 5 && xrandr --newmode "1024x768-safe" 65.00 1024 1048 1184 1344 768 771 777 806 -HSync -VSync && xrandr --addmode VGA1 1024x768-safe && xrandr --output VGA1 --mode 1024x768-safe

Also, change VGA1 to correct output name.

EDID checksum is invalid

If the previous method results in an *ERROR* EDID checksum is invalid error during boot, see KMS#Forcing modes and EDID and [1].

Or xrandr --addmode might give you the error X Error of failed request: BadMatch. NVIDIA users should read NVIDIA/Troubleshooting#xrandr BadMatch. BadMatch could indicate an invalid EDID checksum. To verify that this is the case, run X in verbose mode (e.g. startx -- -logverbose 6) and check your Xorg log for messages about a bad EDID.

Screen resolution reverts back after a blink

If you use GNOME and your monitor doesn't have an EDID, above #Adding undetected resolutions might not work, with your screen just blinking once, after xrandr --output.

Poke around with ~/.config/monitors.xml, or delete the file completely, and then reboot.

It is better explained in this article.

Permanently adding undetected resolutions

Once a suitable resolution is found using xrandr, the mode can be permanently added by creating an entry in /etc/X11/xorg.conf.d/:

/etc/X11/xorg.conf.d/10-monitor.conf
Section "Monitor"
    Identifier "VGA1"
    Modeline "1280x1024_60.00"  109.00  1280 1368 1496 1712  1024 1027 1034 1063 -hsync +vsync
    Option "PreferredMode" "1280x1024_60.00"
EndSection

Section "Screen"
    Identifier "Screen0"
    Monitor "VGA1"
    DefaultDepth 24
    SubSection "Display"
        Modes "1280x1024_60.00"
    EndSubSection
EndSection

Section "Device"
    Identifier "Device0"
    Driver "intel"
EndSection

Replace intel with the right driver, e.g. nvidia.

Resolution lower than expected

Tip: Try #Adding undetected resolutions first, if it doesn't work, you may try this method.

If you video card is recognized but the resolution is lower than you expect, you may try this.

Background: ATI X1550 based video card and two LCD monitors DELL 2408(up to 1920x1200) and Samsung 206BW(up to 1680x1050). Upon first login after installation, the resolution default to 1152x864. xrandr does not list any resolution higher than 1152x864. You may want to try editing /etc/X11/xorg.conf, add a section about virtual screen, logout, login and see if this helps. If not then read on.

Change xorg.conf

/etc/X11/xorg.conf
Section "Screen"
        ...
        SubSection "Display"
                Virtual 3600 1200
        EndSubSection
EndSection

About the numbers: DELL on the left and Samsung on the right. So the virtual width is of sum of both LCD width 3600=1920+1680; Height then is figured as the max of them, which is max(1200,1050)=1200. If you put one LCD above the other, use this calculation instead: (max(width1, width2), height1+height2).

Full RGB in HDMI

It may occur that the Intel driver will not configure correctly the output of the HDMI monitor. It will set a limited color range (16-235) using the Broadcast RGB property, and the black will not look black, it will be grey.

To see if it is your case:

$ xrandr --output HDMI1 --set "Broadcast RGB" "Full"

See also