https://wiki.archlinux.org/api.php?action=feedcontributions&user=Slaxor&feedformat=atomArchWiki - User contributions [en]2024-03-28T16:07:33ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=Xrandr&diff=306242Xrandr2014-03-21T13:32:31Z<p>Slaxor: </p>
<hr />
<div>{{Lowercase title}}<br />
[[Category:X Server]]<br />
[[zh-CN:Xrandr]]<br />
{{Article summary start}}<br />
{{Article summary text|Describes an official configuration utility to the [[Wikipedia:RandR|RandR]] extension.}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|Xorg}}<br />
{{Article summary wiki|Multihead}}<br />
{{Article summary end}}<br />
''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. See [[Multihead]] for general informations.<br />
<br />
== Installation ==<br />
<br />
[[pacman|Install]] the {{Pkg|xorg-xrandr}} package from the [[official repositories]].<br />
<br />
=== Graphical frontends ===<br />
<br />
There are some graphical frontends available for ''xrandr'':<br />
<br />
*{{App|ARandR|Simple and convenient visual front end.|http://christian.amsuess.com/tools/arandr/|{{Pkg|arandr}}}}<br />
<br />
*{{App|LXrandR|The default monitor configuration tool for the [[LXDE]] desktop environment.|http://lxde.org/|{{Pkg|lxrandr}}}}<br />
<br />
== Testing configuration ==<br />
<br />
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:<br />
<br />
{{hc|xrandr|<br />
Screen 0: minimum 320 x 200, current 1440 x 900, maximum 8192 x 8192<br />
VGA disconnected (normal left inverted right x axis y axis)<br />
LVDS connected (normal left inverted right x axis y axis)<br />
1440x900 59.9*+<br />
1280x854 59.9 <br />
1280x800 59.8 <br />
...<br />
}}<br />
<br />
You can use ''xrandr'' to set different resolution (must be present in the above list) on some output:<br />
<br />
$ xrandr --output LVDS --mode 1280x800<br />
<br />
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:<br />
<br />
$ xrandr --output LVDS --mode 1280x800 --rate 75<br />
<br />
The {{ic|--auto}} option will turn the specified output on if it is off and set the preferred (maximum) resolution:<br />
<br />
$ xrandr --output LVDS --auto<br />
<br />
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:<br />
<br />
$ xrandr --output LVDS --off --output HDMI-0 --auto<br />
<br />
{{Note|<br />
* Changes you make using ''xrandr'' will only last through the current session.<br />
* ''xrandr'' has a lot more capabilities - see {{ic|man xrandr}} for details.<br />
}}<br />
<br />
== Configuration ==<br />
<br />
''xrandr'' is just a simple interface to the RandR extension and has no configuration file. However, there are multiple ways of achieving persistent configuration:<br />
<br />
# The RandR extension can be configured via [[Xorg#Configuration|X configuration files]], see [[Multihead#RandR]] for details. This method provides only static configuration.<br />
# 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.<br />
# 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.<br />
<br />
{{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}}. This method requires root access and mucking around in system config files, but will take effect earlier in the startup process than using xprofile.}}<br />
<br />
=== Scripts ===<br />
<br />
==== Example 1 ====<br />
<br />
This script toggles between external monitor (specified by {{ic|$EXT}}) and default monitor (specified by {{ic|$IN}}), so that only one monitor is active at a time.<br />
<br />
The default monitor (specified by {{ic|$IN}}) should be connected when running the script, which is always true for a laptop.<br />
<br />
{{bc|<nowiki><br />
#!/bin/bash<br />
<br />
IN="LVDS1"<br />
EXT="VGA1"<br />
<br />
if (xrandr | grep "$EXT disconnected"); then<br />
xrandr --output $EXT --off --output $IN --auto<br />
else<br />
xrandr --output $IN --off --output $EXT --auto<br />
fi<br />
</nowiki>}}<br />
<br />
==== Example 2 ====<br />
<br />
This script toggles only external monitor (specified by {{ic|$EXT}}), leaves the default monitor (specified by {{ic|$IN}}) on.<br />
<br />
The default monitor (specified by {{ic|$IN}}) should be connected when running the script, which is always true for a laptop.<br />
<br />
{{bc|<nowiki><br />
#!/bin/bash<br />
<br />
IN="LVDS1"<br />
EXT="VGA1"<br />
<br />
if (xrandr | grep "$EXT disconnected"); then<br />
xrandr --output $IN --auto --output $EXT --off <br />
else<br />
xrandr --output $IN --auto --primary --output $EXT --auto --right-of $IN<br />
fi<br />
</nowiki>}}<br />
<br />
==== Example 3 ====<br />
<br />
This script iterates through connected monitors, selects currently active (primary) monitor, turns next one on and the others off:<br />
<br />
{{bc|<nowiki><br />
# get info from xrandr<br />
connectedOutputs=$(xrandr | grep " connected" | sed -e "s/\([A-Z0-9]\+\) connected.*/\1/")<br />
activeOutput=$(xrandr | grep -e " connected [^(]" | sed -e "s/\([A-Z0-9]\+\) connected.*/\1/") <br />
connected=$(echo $connectedOutputs | wc -w)<br />
<br />
# initialize variables<br />
execute="xrandr "<br />
default="xrandr "<br />
i=1<br />
switch=0<br />
<br />
for display in $connectedOutputs<br />
do<br />
# build default configuration<br />
if [ $i -eq 1 ]<br />
then<br />
default=$default"--output $display --auto "<br />
else<br />
default=$default"--output $display --off "<br />
fi<br />
<br />
# build "switching" configuration<br />
if [ $switch -eq 1 ]<br />
then<br />
execute=$execute"--output $display --auto "<br />
switch=0<br />
else<br />
execute=$execute"--output $display --off "<br />
fi<br />
<br />
# check whether the next output should be switched on<br />
if [ $display = $activeOutput ]<br />
then<br />
switch=1<br />
fi<br />
<br />
i=$(( $i + 1 ))<br />
done<br />
<br />
# check if the default setup needs to be executed then run it<br />
echo "Resulting Configuration:"<br />
if [ -z "$(echo $execute | grep "auto")" ]<br />
then<br />
echo "Command: $default"<br />
`$default`<br />
else<br />
echo "Command: $execute"<br />
`$execute`<br />
fi<br />
echo -e "\n$(xrandr)"<br />
</nowiki>}}<br />
<br />
<br />
<br />
<br />
==== Example 3a ====<br />
<br />
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.<br />
I am using it with "srandrd" in my "i3wm" like so<br />
<br />
~/.xprofile<br />
---- <br />
<br />
srandrd ~/.i3/detect_displays.sh<br />
<br />
----<br />
<br />
(Example 3 didn't work for me for some reason or other)<br />
<br />
{{bc|<nowiki><br />
#!/bin/bash<br />
#<br />
# Copyright (C) 2014 Sascha Teske <sascha.teske@gmail.com><br />
#<br />
# This program is free software; you can redistribute it and/or modify<br />
# it under the terms of the GNU General Public License as published by<br />
# the Free Software Foundation; either version 2 of the License, or<br />
# (at your option) any later version.<br />
#<br />
# This program is distributed in the hope that it will be useful,<br />
# but WITHOUT ANY WARRANTY; without even the implied warranty of<br />
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br />
# GNU General Public License for more details.<br />
# <br />
<br />
XRANDR="xrandr"<br />
CMD="${XRANDR}"<br />
declare -A VOUTS<br />
eval VOUTS=$(${XRANDR}|awk 'BEGIN {printf("(")} /^\S.*connected/{printf("[%s]=%s ", $1, $2)} END{printf(")")}')<br />
declare -A POS<br />
#XPOS=0<br />
#YPOS=0<br />
#POS="${XPOS}x${YPOS}"<br />
<br />
POS=([X]=0 [Y]=0)<br />
<br />
find_mode() {<br />
echo $(${XRANDR} |grep ${1} -A1|awk '{FS="[ x]"} /^\s/{printf("WIDTH=%s\nHEIGHT=%s", $4,$5)}')<br />
}<br />
<br />
xrandr_params_for() {<br />
if [ "${2}" == 'connected' ]<br />
then<br />
eval $(find_mode ${1}) #sets ${WIDTH} and ${HEIGHT}<br />
MODE="${WIDTH}x${HEIGHT}"<br />
CMD="${CMD} --output ${1} --mode ${MODE} --pos ${POS[X]}x${POS[Y]}"<br />
POS[X]=$((${POS[X]}+${WIDTH}))<br />
return 0<br />
else<br />
CMD="${CMD} --output ${1} --off"<br />
return 1<br />
fi<br />
}<br />
<br />
<br />
for VOUT in ${!VOUTS[*]}<br />
do<br />
xrandr_params_for ${VOUT} ${VOUTS[${VOUT}]}<br />
done<br />
set -x<br />
${CMD}<br />
set +x<br />
</nowiki>}}<br />
<br />
<br />
== Using xrandr with VNC ==<br />
<br />
{{Out of date|the {{ic|-s}} option is for version 1.1}}<br />
{{Poor writing|duplicates [[#Adding undetected resolutions]]}}<br />
<br />
If you are using a VNC server that supports xrandr, you can change the vnc resolution on the fly, for example by running {{ic|xrandr -s 1920x1200}}. ''tigervnc'' is an example of a client that supports xrandr.<br />
<br />
If you run {{ic|xrandr}} from a VNC session, you will get a list of currently configured modes. Each of these modes can be activated with the {{ic|xrandr -s <width>x<height>}} command; however, if the mode you want does not exist in the list, you must first add it. As an example, we will add resolution {{ic|1024x600}}:<br />
<br />
First run {{ic|cvt}} to get the correct modeline for the resolution you want to add:<br />
<br />
{{hc|$ cvt 1024 600|<br />
# 1024x600 59.85 Hz (CVT) hsync: 37.35 kHz; pclk: 49.00 MHz<br />
Modeline "1024x600_60.00" 49.00 1024 1072 1168 1312 600 603 613 624 -hsync +vsync<br />
}}<br />
<br />
Use that modeline output to run the commands below:<br />
<br />
$ xrandr --newmode "1024x600" 49.00 1024 1072 1168 1312 600 603 613 624 -hsync +vsync<br />
$ xrandr --addmode default "1024x600"<br />
<br />
Doing the above will give you the ability to change to {{ic|1024x600}} by running {{ic|xrandr -s 1024x600}}, but it will only last for the current x session. To ensure that you can use the newly added resolution each time you start vncserver, add the above commands to {{ic|~/.vnc/xstartup}}.<br />
<br />
== Troubleshooting ==<br />
<br />
=== Adding undetected resolutions ===<br />
<br />
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.<br />
<br />
First we run {{ic|gtf}} or {{ic|cvt}} to get the '''Modeline''' for the resolution we want:<br />
<br />
For some LCD screens (samsung 2343NW), the command "cvt -r" (= with reduced blanking) is to be used.<br />
<br />
{{hc|$ cvt 1280 1024|<br />
# 1280x1024 59.89 Hz (CVT 1.31M4) hsync: 63.67 kHz; pclk: 109.00 MHz<br />
Modeline "1280x1024_60.00" 109.00 1280 1368 1496 1712 1024 1027 1034 1063 -hsync +vsync<br />
}}<br />
<br />
{{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:<br />
[ 45.063] (II) intel(0): clock: 241.5 MHz Image Size: 597 x 336 mm<br />
[ 45.063] (II) intel(0): h_active: 2560 h_sync: 2600 h_sync_end 2632 h_blank_end 2720 h_border: 0<br />
[ 45.063] (II) intel(0): v_active: 1440 v_sync: 1443 v_sync_end 1448 v_blanking: 1481 v_border: 0<br />
<br />
xrandr --newmode "2560x1440" 241.50 2560 2600 2632 2720 1440 1443 1448 1481 -hsync +vsync<br />
}}<br />
<br />
Then we create a new xrandr mode. Note that the Modeline keyword needs to be ommited.<br />
<br />
$ xrandr --newmode "1280x1024_60.00" 109.00 1280 1368 1496 1712 1024 1027 1034 1063 -hsync +vsync<br />
<br />
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.<br />
<br />
$ xrandr --addmode VGA1 1280x1024_60.00<br />
<br />
Now we change the resolution of the screen to the one we just added:<br />
<br />
$ xrandr --output VGA1 --mode 1280x1024_60.00<br />
<br />
Note that these settings only take effect during this session. <br />
<br />
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 : <br />
<br />
$ 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<br />
<br />
Also, change {{ic|VGA1}} to corret output name.<br />
<br />
=== Resolution lower than expected ===<br />
<br />
{{Tip|Try [[#Adding undetected resolutions]] first, if it doesn't work, you may try this method.}}<br />
<br />
If you video card is recognized but the resolution is lower than you expect, you may try this.<br />
<br />
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.<br />
<br />
Change xorg.conf<br />
{{hc|/etc/X11/xorg.conf|<br />
Section "Screen"<br />
...<br />
SubSection "Display"<br />
Virtual 3600 1200<br />
EndSubSection<br />
EndSection<br />
}}<br />
<br />
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).<br />
<br />
== See also ==<br />
* https://wiki.ubuntu.com/X/Config/Resolution<br />
* [http://wiki.debian.org/XStrikeForce/HowToRandR12 RandR 1.2 tutorial]<br />
* [http://www.thinkwiki.org/wiki/Xorg_RandR_1.2 Xorg RandR 1.2 on ThinkWiki]<br />
* [http://www.x.org/wiki/FAQVideoModes#ObtainingmodelinesfromWindowsprogramPowerStrip FAQVideoModes - more information about modelines]</div>Slaxorhttps://wiki.archlinux.org/index.php?title=Xrandr&diff=306213Xrandr2014-03-21T09:14:55Z<p>Slaxor: </p>
<hr />
<div>{{Lowercase title}}<br />
[[Category:X Server]]<br />
[[zh-CN:Xrandr]]<br />
{{Article summary start}}<br />
{{Article summary text|Describes an official configuration utility to the [[Wikipedia:RandR|RandR]] extension.}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|Xorg}}<br />
{{Article summary wiki|Multihead}}<br />
{{Article summary end}}<br />
''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. See [[Multihead]] for general informations.<br />
<br />
== Installation ==<br />
<br />
[[pacman|Install]] the {{Pkg|xorg-xrandr}} package from the [[official repositories]].<br />
<br />
=== Graphical frontends ===<br />
<br />
There are some graphical frontends available for ''xrandr'':<br />
<br />
*{{App|ARandR|Simple and convenient visual front end.|http://christian.amsuess.com/tools/arandr/|{{Pkg|arandr}}}}<br />
<br />
*{{App|LXrandR|The default monitor configuration tool for the [[LXDE]] desktop environment.|http://lxde.org/|{{Pkg|lxrandr}}}}<br />
<br />
== Testing configuration ==<br />
<br />
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:<br />
<br />
{{hc|xrandr|<br />
Screen 0: minimum 320 x 200, current 1440 x 900, maximum 8192 x 8192<br />
VGA disconnected (normal left inverted right x axis y axis)<br />
LVDS connected (normal left inverted right x axis y axis)<br />
1440x900 59.9*+<br />
1280x854 59.9 <br />
1280x800 59.8 <br />
...<br />
}}<br />
<br />
You can use ''xrandr'' to set different resolution (must be present in the above list) on some output:<br />
<br />
$ xrandr --output LVDS --mode 1280x800<br />
<br />
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:<br />
<br />
$ xrandr --output LVDS --mode 1280x800 --rate 75<br />
<br />
The {{ic|--auto}} option will turn the specified output on if it is off and set the preferred (maximum) resolution:<br />
<br />
$ xrandr --output LVDS --auto<br />
<br />
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:<br />
<br />
$ xrandr --output LVDS --off --output HDMI-0 --auto<br />
<br />
{{Note|<br />
* Changes you make using ''xrandr'' will only last through the current session.<br />
* ''xrandr'' has a lot more capabilities - see {{ic|man xrandr}} for details.<br />
}}<br />
<br />
== Configuration ==<br />
<br />
''xrandr'' is just a simple interface to the RandR extension and has no configuration file. However, there are multiple ways of achieving persistent configuration:<br />
<br />
# The RandR extension can be configured via [[Xorg#Configuration|X configuration files]], see [[Multihead#RandR]] for details. This method provides only static configuration.<br />
# 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.<br />
# 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.<br />
<br />
{{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}}. This method requires root access and mucking around in system config files, but will take effect earlier in the startup process than using xprofile.}}<br />
<br />
=== Scripts ===<br />
<br />
==== Example 1 ====<br />
<br />
This script toggles between external monitor (specified by {{ic|$EXT}}) and default monitor (specified by {{ic|$IN}}), so that only one monitor is active at a time.<br />
<br />
The default monitor (specified by {{ic|$IN}}) should be connected when running the script, which is always true for a laptop.<br />
<br />
{{bc|<nowiki><br />
#!/bin/bash<br />
<br />
IN="LVDS1"<br />
EXT="VGA1"<br />
<br />
if (xrandr | grep "$EXT disconnected"); then<br />
xrandr --output $EXT --off --output $IN --auto<br />
else<br />
xrandr --output $IN --off --output $EXT --auto<br />
fi<br />
</nowiki>}}<br />
<br />
==== Example 2 ====<br />
<br />
This script toggles only external monitor (specified by {{ic|$EXT}}), leaves the default monitor (specified by {{ic|$IN}}) on.<br />
<br />
The default monitor (specified by {{ic|$IN}}) should be connected when running the script, which is always true for a laptop.<br />
<br />
{{bc|<nowiki><br />
#!/bin/bash<br />
<br />
IN="LVDS1"<br />
EXT="VGA1"<br />
<br />
if (xrandr | grep "$EXT disconnected"); then<br />
xrandr --output $IN --auto --output $EXT --off <br />
else<br />
xrandr --output $IN --auto --primary --output $EXT --auto --right-of $IN<br />
fi<br />
</nowiki>}}<br />
<br />
==== Example 3 ====<br />
<br />
This script iterates through connected monitors, selects currently active (primary) monitor, turns next one on and the others off:<br />
<br />
{{bc|<nowiki><br />
# get info from xrandr<br />
connectedOutputs=$(xrandr | grep " connected" | sed -e "s/\([A-Z0-9]\+\) connected.*/\1/")<br />
activeOutput=$(xrandr | grep -e " connected [^(]" | sed -e "s/\([A-Z0-9]\+\) connected.*/\1/") <br />
connected=$(echo $connectedOutputs | wc -w)<br />
<br />
# initialize variables<br />
execute="xrandr "<br />
default="xrandr "<br />
i=1<br />
switch=0<br />
<br />
for display in $connectedOutputs<br />
do<br />
# build default configuration<br />
if [ $i -eq 1 ]<br />
then<br />
default=$default"--output $display --auto "<br />
else<br />
default=$default"--output $display --off "<br />
fi<br />
<br />
# build "switching" configuration<br />
if [ $switch -eq 1 ]<br />
then<br />
execute=$execute"--output $display --auto "<br />
switch=0<br />
else<br />
execute=$execute"--output $display --off "<br />
fi<br />
<br />
# check whether the next output should be switched on<br />
if [ $display = $activeOutput ]<br />
then<br />
switch=1<br />
fi<br />
<br />
i=$(( $i + 1 ))<br />
done<br />
<br />
# check if the default setup needs to be executed then run it<br />
echo "Resulting Configuration:"<br />
if [ -z "$(echo $execute | grep "auto")" ]<br />
then<br />
echo "Command: $default"<br />
`$default`<br />
else<br />
echo "Command: $execute"<br />
`$execute`<br />
fi<br />
echo -e "\n$(xrandr)"<br />
</nowiki>}}<br />
<br />
<br />
<br />
<br />
==== Example 3a ====<br />
<br />
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.<br />
I am using it with "srandrd" in my "i3wm" like so<br />
<br />
# ~/.xprofile<br />
---- 8< ----<br />
srandrd /path/to/detect_displays.sh<br />
---- >8 ----<br />
<br />
(Example 3 didn't work for me for some reason or other)<br />
<br />
{{bc|<nowiki><br />
#!/bin/bash<br />
#<br />
# Copyright (C) 2014 Sascha Teske <sascha.teske@gmail.com><br />
#<br />
# This program is free software; you can redistribute it and/or modify<br />
# it under the terms of the GNU General Public License as published by<br />
# the Free Software Foundation; either version 2 of the License, or<br />
# (at your option) any later version.<br />
#<br />
# This program is distributed in the hope that it will be useful,<br />
# but WITHOUT ANY WARRANTY; without even the implied warranty of<br />
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br />
# GNU General Public License for more details.<br />
# <br />
<br />
XRANDR="xrandr"<br />
CMD="${XRANDR}"<br />
declare -A VOUTS<br />
eval VOUTS=$(${XRANDR}|awk 'BEGIN {printf("(")} /^\S.*connected/{printf("[%s]=%s ", $1, $2)} END{printf(")")}')<br />
declare -A POS<br />
#XPOS=0<br />
#YPOS=0<br />
#POS="${XPOS}x${YPOS}"<br />
<br />
POS=([X]=0 [Y]=0)<br />
<br />
find_mode() {<br />
echo $(${XRANDR} |grep ${1} -A1|awk '{FS="[ x]"} /^\s/{printf("WIDTH=%s\nHEIGHT=%s", $4,$5)}')<br />
}<br />
<br />
xrandr_params_for() {<br />
if [ "${2}" == 'connected' ]<br />
then<br />
eval $(find_mode ${1}) #sets ${WIDTH} and ${HEIGHT}<br />
MODE="${WIDTH}x${HEIGHT}"<br />
CMD="${CMD} --output ${1} --mode ${MODE} --pos ${POS[X]}x${POS[Y]}"<br />
POS[X]=$((${POS[X]}+${WIDTH}))<br />
return 0<br />
else<br />
CMD="${CMD} --output ${1} --off"<br />
return 1<br />
fi<br />
}<br />
<br />
<br />
for VOUT in ${!VOUTS[*]}<br />
do<br />
xrandr_params_for ${VOUT} ${VOUTS[${VOUT}]}<br />
done<br />
set -x<br />
${CMD}<br />
set +x<br />
</nowiki>}}<br />
<br />
<br />
== Using xrandr with VNC ==<br />
<br />
{{Out of date|the {{ic|-s}} option is for version 1.1}}<br />
{{Poor writing|duplicates [[#Adding undetected resolutions]]}}<br />
<br />
If you are using a VNC server that supports xrandr, you can change the vnc resolution on the fly, for example by running {{ic|xrandr -s 1920x1200}}. ''tigervnc'' is an example of a client that supports xrandr.<br />
<br />
If you run {{ic|xrandr}} from a VNC session, you will get a list of currently configured modes. Each of these modes can be activated with the {{ic|xrandr -s <width>x<height>}} command; however, if the mode you want does not exist in the list, you must first add it. As an example, we will add resolution {{ic|1024x600}}:<br />
<br />
First run {{ic|cvt}} to get the correct modeline for the resolution you want to add:<br />
<br />
{{hc|$ cvt 1024 600|<br />
# 1024x600 59.85 Hz (CVT) hsync: 37.35 kHz; pclk: 49.00 MHz<br />
Modeline "1024x600_60.00" 49.00 1024 1072 1168 1312 600 603 613 624 -hsync +vsync<br />
}}<br />
<br />
Use that modeline output to run the commands below:<br />
<br />
$ xrandr --newmode "1024x600" 49.00 1024 1072 1168 1312 600 603 613 624 -hsync +vsync<br />
$ xrandr --addmode default "1024x600"<br />
<br />
Doing the above will give you the ability to change to {{ic|1024x600}} by running {{ic|xrandr -s 1024x600}}, but it will only last for the current x session. To ensure that you can use the newly added resolution each time you start vncserver, add the above commands to {{ic|~/.vnc/xstartup}}.<br />
<br />
== Troubleshooting ==<br />
<br />
=== Adding undetected resolutions ===<br />
<br />
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.<br />
<br />
First we run {{ic|gtf}} or {{ic|cvt}} to get the '''Modeline''' for the resolution we want:<br />
<br />
For some LCD screens (samsung 2343NW), the command "cvt -r" (= with reduced blanking) is to be used.<br />
<br />
{{hc|$ cvt 1280 1024|<br />
# 1280x1024 59.89 Hz (CVT 1.31M4) hsync: 63.67 kHz; pclk: 109.00 MHz<br />
Modeline "1280x1024_60.00" 109.00 1280 1368 1496 1712 1024 1027 1034 1063 -hsync +vsync<br />
}}<br />
<br />
{{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:<br />
[ 45.063] (II) intel(0): clock: 241.5 MHz Image Size: 597 x 336 mm<br />
[ 45.063] (II) intel(0): h_active: 2560 h_sync: 2600 h_sync_end 2632 h_blank_end 2720 h_border: 0<br />
[ 45.063] (II) intel(0): v_active: 1440 v_sync: 1443 v_sync_end 1448 v_blanking: 1481 v_border: 0<br />
<br />
xrandr --newmode "2560x1440" 241.50 2560 2600 2632 2720 1440 1443 1448 1481 -hsync +vsync<br />
}}<br />
<br />
Then we create a new xrandr mode. Note that the Modeline keyword needs to be ommited.<br />
<br />
$ xrandr --newmode "1280x1024_60.00" 109.00 1280 1368 1496 1712 1024 1027 1034 1063 -hsync +vsync<br />
<br />
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.<br />
<br />
$ xrandr --addmode VGA1 1280x1024_60.00<br />
<br />
Now we change the resolution of the screen to the one we just added:<br />
<br />
$ xrandr --output VGA1 --mode 1280x1024_60.00<br />
<br />
Note that these settings only take effect during this session. <br />
<br />
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 : <br />
<br />
$ 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<br />
<br />
Also, change {{ic|VGA1}} to corret output name.<br />
<br />
=== Resolution lower than expected ===<br />
<br />
{{Tip|Try [[#Adding undetected resolutions]] first, if it doesn't work, you may try this method.}}<br />
<br />
If you video card is recognized but the resolution is lower than you expect, you may try this.<br />
<br />
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.<br />
<br />
Change xorg.conf<br />
{{hc|/etc/X11/xorg.conf|<br />
Section "Screen"<br />
...<br />
SubSection "Display"<br />
Virtual 3600 1200<br />
EndSubSection<br />
EndSection<br />
}}<br />
<br />
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).<br />
<br />
== See also ==<br />
* https://wiki.ubuntu.com/X/Config/Resolution<br />
* [http://wiki.debian.org/XStrikeForce/HowToRandR12 RandR 1.2 tutorial]<br />
* [http://www.thinkwiki.org/wiki/Xorg_RandR_1.2 Xorg RandR 1.2 on ThinkWiki]<br />
* [http://www.x.org/wiki/FAQVideoModes#ObtainingmodelinesfromWindowsprogramPowerStrip FAQVideoModes - more information about modelines]</div>Slaxor