How to configure Xorg for a dynamic dual monitor setup

laptopmulti-monitorxorg

I have a laptop usually (!) connected to an external monitor. Now I want to configure (if possible without any scripts and/or xrandr) xorg such that

  • If the external monitor is connected AND the laptop lid open -> both displays extended
  • If the external monitor is connected AND laptop closed -> only external
  • If the external monitor is not connected -> laptop monitor.

Right now, my /etc/X11/xorg.conf.d/10-monitor.conf looks like the one proposed in the Arch wiki here. Now, I have the following issues:

  • after boot when the laptop lid is closed, still both monitors are active (even though I can't move the mouse out of the external one's desktop)
  • when I open the lid, the external monitor becomes black while I can move the mouse out of the laptops screen. Switching off and on the external monitor with xrandr makes it work again.
  • When I open the laptop, so that the external monitor becomes black and close the laptop again, X crashes and I have to reboot the laptop. (no keyboard combination works anymore and I see nothing but a non-moving mouse arrow on the external screen)

It is quite annoying that the monitors don't behave properly automatically. It's an intel chip (onboard) and the external monitor is connected via DisplayPort.

I don't really know what to look for in which logfile, so maybe you can help me out.

Best Answer

When I've done things like that in the past, the way I accomplished it was by having multiple /etc/X11/xorg.conf files. Then in /etc/rc.local (or equiv), detect your conditions upon starting up and copy the right file into place before the X server is started.

In the end, though, I no longer go this route. It's far easier to do the dynamic xrandr/gui-config hacks these days because they let you do it dynamically not just at boot time and even as you plug and unplug the monitors live. There isn't any xorg.conf settings that refer to dynamically changing connections, for instance.

[oh, and I generally recommend you don't run your laptop with the lid closed. It doesn't cool as well and in the long run you'll likely run into heat-damage issues]

Related Question