How to set default xrandr settings?

I'm trying to enable dual monitors in Ubuntu. This is working fine, but every time I do it, desktop effects is disabled. I think I've found the reason why, though:

https://wiki.ubuntu.com/X/Config/Multihead/

As with the GNOME XRandR configuration method, setting Virtual to too large a value may result in a loss of hardware acceleration, and thus an inability to use Compiz and its desktop effects.

When I use the GNOME monitor applet, or the Monitors configuration in the System menu, the default xrandr settings puts the second monitor to the right of the first, and, as I found with this bug, for most monitors this creates a virtual desktop larger than the maximum 2048 horizontal resolution needed for hardware acceleration on my netbook hardware.

So, it seems like if I can modify xrandr's default settings so that it places the new desktop above or below (north or south of) the main LVDS display, then hardware acceleration, and therefore compiz will continue to work. Can anyone tell me, what is the easiest way to achieve this?

UPDATE:

I have confirmed that multihead support with desktop effects and hardware acceleration works when I move the external monitor display north of the main LVDS display. Right now this involves the following process: plugging in the external monitor, starting the Monitors configuration menu, desktop effects are disabled automatically (and all of the windows on my workspaces are moved to the first workspace), repositioning the external display so that it is north of LVDS display and clicking apply, and then navigating to the Appearance menu and telling it to reenable desktop effects. Is there a simpler way do this?

UPDATE 2:

OK, so I thought that perhaps the GNOME Monitors configuration screen was trying to be clever, and might be disbling desktop effects. So, I just tried using the xrandr command-line client instead, as follows:

xrandr --output VGA1 --above LVDS1

When I do that, desktop effects are still disabled, and I need to manually reenable them. This, despite the fact that hardware acceleration works, and there is never a point where hardware acceleration stops working because the horizontal dimension of the virtual display is too large. So what program is trying to be clever, and is turning off desktop effects when it doesn't need to? And how do I make it stop?

If there were a way to re-enable desktop effects from the command line, which I could then put into a script along with the proper xrandr invocation, I would accept that as a workaround.

UPDATE 3:

OK, here's my script to enable a second monitor with desktop effects. It might be evil, I'm not sure:

second-monitor.sh

xrandr --output VGA1 --above LVDS1
sleep 3
compiz --replace &

The sleep statement might not be necessary.

If there's a better way to do this, please let me know.

UPDATE 4:

This is a Dell Mini Inspiron 1012.

Here are my system specifications:

lspci -vv

00:02.0 VGA compatible controller: Intel Corporation N10 Family Integrated Graphics Controller
    Subsystem: Dell Device 041a
    Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx+
    Status: Cap+ 66MHz- UDF- FastB2B+ ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
    Latency: 0
    Interrupt: pin A routed to IRQ 29
    Region 0: Memory at f0b00000 (32-bit, non-prefetchable) [size=512K]
    Region 1: I/O ports at 18d0 [size=8]
    Region 2: Memory at d0000000 (32-bit, prefetchable) [size=256M]
    Region 3: Memory at f0900000 (32-bit, non-prefetchable) [size=1M]
    Capabilities: <access denied>
    Kernel driver in use: i915
    Kernel modules: i915

00:02.1 Display controller: Intel Corporation N10 Family Integrated Graphics Controller
    Subsystem: Dell Device 041a
    Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx-
    Status: Cap+ 66MHz- UDF- FastB2B+ ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
    Latency: 0
    Region 0: Memory at f0b80000 (32-bit, non-prefetchable) [size=512K]
    Capabilities: <access denied>

lsmod | grep i915

i915                  287458  2 
drm_kms_helper         29329  1 i915
drm                   162409  3 i915,drm_kms_helper
intel_agp              24375  2 i915
i2c_algo_bit            5028  1 i915
video                  17375  1 i915

Solution 1:

Laying them out left-to-right is not the xrandr default, but the gnome-settings-daemon default. From gnome-settings-daemon 2.32 onwards, the last configuration should just be loaded from monitors.xml; so if you've done the vertical layout once, then next time it would automatically pick that up without kicking out Compiz.

So are you running 10.04 Lucid by any chance? In that case, you can follow these instructions to enable this feature in gnome-settings-daemon 2.30.1.

1) open a terminal

2) get the source:

mkdir src
cd src
apt-get source gnome-settings-daemon

3) edit src/gnome-settings-daemon-2.30.1/plugins/xrandr/gsd-xrandr-manager.c, at line 1349, change

#if 1

to

#if 0

4) in the terminal, install build dependencies:

sudo apt-get install build-dep gnome-settings-daemon

5) give your package a new version number:

dch -i "enable monitor.xml default values"

6) build and install your package:

debuild
cd ..
sudo dpkg -i gnome-settings-daemon*.deb

Please let me know if this works for you, I reproduced the steps from memory. Also, let me know if you had to do extra steps, so that I can update this answer.

Solution 2:

Or you can just get the compiz fusion icon, it allows you to easily click your way to reloading compiz. Thanks so much, had the same issues, never thought to reload compiz, just thought I was going to have to live with that in dual-mode. Just tried it with fusion icon, voila! Cube, everything normal again.