I have been playing with my monitor setup again on my Dell D530 laptop. The internal monitor of the laptop is 1400x1050 pixels, but I usually use a 19" external monitor set to 1280x1024. With Etch this worked flawlessly. When the external monitor was hooked up and the lid on my laptop was closed, then my desktop would be 1280x1024. When I booted with the lid open and no monitor attached, the desktop would be 1400x1050. When I upgraded to Lenny this stopped working. I had to change the resolution each time I changed from external screen to internal screen and back. I reported a bug about this but the answer came down to “It’s not a bug but a feature. Use XRandR to change your displays if you don’t like it.”
So, I dove into XRandR. I wanted this to work for all users, so simply sticking some XRandR commands in the gnome session startup wasn’t going to suffice. At the same time I also got interested in trying a dual-head setup instead of only an external monitor when one was connected. I was going to need completely different layouts depending on the external monitor. It took a while before I figured out how to do it, it took a little longer to fight GNOME into submission, but here is how to make it work.
Figure out the correct XRandR settings
I'm not going in to the gory details of XRandR. The Debian wiki has an excellent explanation of XRandR 1.2. It is possible to set XRandR configurations in the xorg.conf file but I didn’t do that. Such a setup does not allow me to specify things like “If monitor X is attached, do Y else do Z”. Here are the XRandR settings/commands that I want. LVDS is my internal monitor and VGA is the external 19" monitor.
When an external monitor is present, set up a dual head configuration. Note that I have placed the screens above each other instead of side-by-side and that they overlap by 26 pixels. That is because the Intel 945 chipset/driver only support a total combined size of 2048x2048 pixels. If you use any other driver or chipset (like an ATI or Intel 965) then you can use a bigger combined size, like 2560x1024 for two 19" monitors side-by-side.
- xrandr --output VGA --mode 1280x1024 --pos 0x0 --output LVSD --mode 1400x1050 --pos 0x998
If you want to use only the external monitor then you would use this instead:
- xrandr --output VGA --mode 1280x1024 --output LVDS --off
And this is the setting I want when there is no external monitor connected:
- xrandr --output LVDS --mode 1400x1050 --output VGA --off
Applying the XRandR settings at login time
I want these settings to apply when I log in. Like I said, I do not put anything in the xorg.conf. When the laptop boots with an external monitor attached then the GDM login screen will be shown on all monitors. After logging in the dual head setup will be configured. To do that I created a file called 45custom_xrandr in /etc/X11/Xsession.d/. That script will be executed when an Xsession starts (after logging in to GNOME, KDE or any other desktop environment.
- xrandr | grep VGA | grep " connected "
- if [$? -eq 0]; then
- # External monitor is connected
- xrandr --output VGA --mode 1280x1024 --pos 0x0 --output LVDS --mode 1400x1050 --pos 0x998
- if [$? -ne 0]; then
- # Something went wrong. Autoconfigure the internal monitor and disable the external one
- xrandr --output LVDS --mode auto --output VGA --off
- fi
- else
- # External monitor is not connected
- xrandr --output LVDS --mode 1400x1050 --output VGA --off
- fi
Now if you log in, the correct settings should be applied. Only it doesn’t work on GNOME…
Stopping GNOME from overriding your XRandR configuration
As it turns out, GNOME tries to guess the best XRandR settings for you based on your connected monitors and the display configuration you set. But the GNOME 2.20/2.22 mix on Debian Lenny does not support a dual-head configuration. That option only became available in GNOME 2.24 and thus is not available in Debian Lenny. You need to turn off the XRandR plugin for the gnome-settings-daemon. Open up a terminal and start gconf-editor. Now browse to /apps/gnome-settings-daemon/plugins/xrandr and uncheck the "active" entry.
Now GNOME will simply adapt to whatever XRandR layout configuration already exists. Many thanks to jm_ and enouf on #debian to help debug this issue. I hope this helps any of you!
Comments
#1 Anonymous Coward
> xrandr --output VGA --mode 1280x1024 --pos 0x0 --output LVSD --mode 1400x1050 --pos 0x998
> xrandr --output VGA --mode 1280x1024 --output LVDS --off
Additionally what type of setup is needed in xorg.conf — you seem to not need any? No various 'screen' sections? Is this dependent on a 3d-capable driver? I have an ATI 3450 card with dual outputs (analog, digital, or s-video) and I've been trying to figure this out to clone the monitor onto the tele with s-video; the radeonhd driver doesn't have many capabilities yet for my card, and the fglrx driver is just a headache...
well perhaps i should be reading the xrandr wiki on debian's pages...
#2 Sander Marechal (http://www.jejik.com)
This depends on your driver. It will always name the devices the same way. In my case my Intel driver always refers to the internal display as LVDS and to the external display as VGA.
You only need a very bare bones xorg.conf file. A modern X server can autodetect pretty much anything, so you only need to meddle with the configuration file when you think that Xorg detected something wrong. Here are the relevant snippets from my xorg.conf:
The only changes I made were adding the Monitor-LVDS and Monitor-VGA options in the Devices section, and adding the Virtual option in Screen->Display. See my second reference to http://www.thinkwiki.org/wiki/Xorg_RandR_1.2 for more information about that.
#3 Anonymous Coward
Just incase someone were to copy and paste.
#4 Sander Marechal (http://www.jejik.com)
#5 Familia
Have you found this problems, does anyone know how to workaround them?
#6 Sander Marechal (http://www.jejik.com)
I do not know of a solution to the square desktop problem. I did lay out my monitors in such a way that I do not lose icons though. Gnome always tries to add icons on the bottom first. If you have two screens side-by-side, simply make sure that the one with the highest vertical resolution (in your case the 1280x1024) is the left most screen.
#7 Kumar
#8 Sander Marechal (http://www.jejik.com)
What does `xrandr -q` say? Does it list the resolutions that you want? If not, then you may want to add a few modelines to your xorg.conf so that xrandr can pick the correct resolution.
#9 emk2203
Actually, I am going via the acpi event of the closed lid to switch between two monitors, avoiding the virtual screen altogether. I hope I can get it working, maybe I return for a question if you don't mind...
#10 Anonymous Coward
grep -q -w closed /proc/acpi/button/lid/LID/state && xrandr --output LVDS --off --output TMDS-1 --auto --output VGA --auto --output TV --auto
Only when the lid is closed when X starts, the internal panel gets switched off and whatever is connected gets autoconfigured.
#11 Amitz Sekali
Is this problem related to the gnome version of Lenny since I'm using XFCE instead of Gnome? How to check whether gnome libraries I use don't somehow make xrandr problematic? Thank you in advance, will really appreciate your pointer.
#12 Sander Marechal (http://www.jejik.com)
@emk2203: There's a bug in my login script. I am hunting it down now. If you type in the correct username and password then it works, but if you enter the wrong password then something goes wrong and you get an Apache 500 internal server error instead of a nice error message telling you that you entered the wrong password.
#13 Sander Marechal (http://www.jejik.com)
#14 Giorgos S
#15 Anonymous Coward
But I still have one problem that my Internal Monitor now treated as "Virtual Screen" , and the Extend Monitor is now become my Primary screen, and I can't switch it other way round, I've tried the following without any luck:
> xrandr --output LVDS --left-of VGA
> xrandr --output LVDS --right-of VGA
> xrandr --output VGA --left-of LVDS
> xrandr --output VGA --right-of LVDS
> xrandr --output VGA --right-of LVDS --mode=1024x768
My OS is Ubuntu 8.04
Any suggestions will be highly appreciated.
#16 Bryan
and my "LVDS" has been recognized as the "External/Extend Monitor"
Is there a way to configure the xorg.conf or xrandr to choose the "LVDS" as the "Internal/Main Monitor"?
#17 Sander Marechal (http://www.jejik.com)
If you're using Gnome then you can simply drag your toolbars and panels to the other monitor and be done with it.
#18 Motin (http://motin.eu)
But this is exactly what we want to not have to do. I connect the laptop every afternoon, and dragging those toolbars doesn't get more amuzing over time...
Does anyone know maybe a way to tell Gnome what monitor is the primary one?
#19 Sander Marechal (http://www.jejik.com)
There does seem to be a workaround but it's kind of a nasty trick...
#20 Dourado
However, I just installed the "grandr" package and then went to System->Administration->Multiple screens
This tool made it quite easy for me to make this work as desired.
#21 PapaJ
Here's how my "45custom_xrandr" looks now:
xrandr | grep "TMDS-1 connected"
if [ $? != 0 ]; then
xrandr --output LVDS --mode 1280x800 --pos 0x26 --output TMDS-1 --mode 1920x1200 --pos 1280x0
if [ $? -ne 0 ]; then
xrandr --output LVDS --mode auto --output TMDS-1 --off
fi
#debug echo "'if [ 1 != 0 ]; then' worked"
else
xrandr --output LVDS --mode 1280x800 --output TMDS-1 --off
#debug echo "'if [ 1 != 0 ]; then' did not work"
fi
#2 .. Looking forward to implementing the close-lid-script ...
#3 And yes, grandr rocks too.
#22 PapaJ
BTW, occasionally a couple of horizontal pixel-lines are written to the wrong place on the screen(s). I monkey with settings and after a reboot it looks OK, but then comes back after some other reboot. My most recent tweak attempt is to set both monitors to "--rate 60", and once again the bad lines are gone. I thought since the MacBook screen might [inappropriately] be going into its 59.9 rate, then perhaps forcing it into its 60 rate (which the external 1920x1200 screen also reports) might make stuff just work.
(Just another example of why most people *buy* operating systems.)
#23 Anonymous Coward
I thought I'd hit the jackpot when I found this page and the xrandr gnome plugin configuration, but no luck. I restarted X, but do I have to reboot?
I am fine with Xfce except that even with UXA and DRI2, 2d rendering of GTK+ apps suck. Xterms leave a transient trail of destruction as you drag them across Firefox, and Google spreadsheets are horribly sluggish. The situation seems a little better in Gnome which is why I want to switch.
Many thanks for any tips.
#24 Sander Marechal (http://www.jejik.com)
Perhaps you should try Gnome's built-in XRandR tool grandr. There's almost two years between Jaunty's Gnome and the Gnome version in Lenny that this article is about. It should work a lot better now.
#25 Tonypm
http://www.phoronix.com/scan.php?page=news_item&px=NzAzMQ
Which says the new version of xrandr now has a --primary option. So on fedora 13 this worked to switch my primary screen.
xrandr --output DVI-I-2 --primary
#26 Amit
#27 Anonymous Coward
#28 CPG
#29 merwok
Cheers
#30 merwok
#31 merwok
#32 frank
I have a ThinkPad T420 an HD300 Intel Card OS archlinux with no corg.conf and my Laptop is connected in a Dockingstation per Display Port.
The Problem is when i boot archlinux the resolution in the console is as big as the Laptop Window 1600x900 my NEC PA241W has 1920x1200.
i have in my .xinitrc
#!/bin/sh
#
# ~/.xinitrc
#
# Executed by startx (run your window manager from here)
xrandr --output DP2 --mode 1920x1200 --output LVDS --off
#xrandr --output DP2 --auto --output LVDS --right-of LVDS
#xrandr --output DP1 --auto --output LVDS --auto --same-as DP1
#xrandr -d DP2 -s 1920x1200
if [ -d /etc/X11/xinit/xinitrc.d ]; then
for f in /etc/X11/xinit/xinitrc.d/*; do
[ -x "$f" ] && . "$f"
done
unset f
fi
# exec gnome-session
# exec startkde
# exec startxfce4
# ...or the Window Manager of your choice
exec openbox-session
when i type startx as user my NEC shows me the 1920x1200 but when i will resize a window to Full Size it wont work and when i switch in a console and type for examble dmesg they will be not shown all the output to the NEC at the end of the Monitor so ca 4-5 cm are crop
what can i do? do i need an xorg if yes what has to be inside the conf?
#33 Sander Marechal (http://www.jejik.com)
You also need to make sure that your desktop isn't overriding youd XRandR settings again. Gnome 2.x did that. I don't know if Gnome 3 or KDE 4 do something similar.
#34 Junkman
#35 Anonymous Coward
I created a 45custom_xrandr.sh file in /etc/X11/Xsession.d with the following lines
1 xrandr | grep VGA1 | grep " connected "
2 if [$? -eq 0]; then
3 # External monitor is connected
4 xrandr --newmode "1368x768_60.00" 85.25 1368 1440 1576 1784 768 771 781 798 -hsync +vsync
5 xrandr --addmode VGA1 1368x768_60.00
6 xrandr --output VGA1 --mode 1368x768_60.00
7 if [$? -ne 0]; then
8 # Something went wrong. Autoconfigure the internal monitor and disable the external one
9 xrandr --output LVDS1 --mode auto --output VGA1 --off
10 fi
11 else
12 # External monitor is not connected
13 xrandr --output LVDS1 --mode 1366x768 --output VGA1 --off
14 fi
saved it and then tried to run it as ./45custom_xrandr.sh . All i get is
VGA1 connected (normal left inverted right x axis y axis)
./45custom_xrandr.sh: line 2: [0: command not found
It seems that it cannot run the if command...Why?
#36 Sander Marechal (http://www.jejik.com)
#37 Jhonas Nascimento
#38 Jhonas Nascimento
I do a condition while to search my 'monitor number' then I used a part his code to set the configuration of my monitors. Here's my code case anyone want test.
Thanks bro' You've my inspiration to try make this works, and sorry for my bad English.
#39 milgrad
- my problem is that both laptop monitor and external one are activated at start (and I only need the external one)
- the separate commands of script work in console, however, the script either gets overridden by smthg or doesn't work on restart
- after I manually change monitor settings and log-off, settings get saved on log on, but once I restart the problem comes back
Happy to hear your thoughts
I'm using Ubuntu 13.10 Unity.
#40 Sander Marechal (http://www.jejik.com)
Comments have been retired for this article.