Dual head with xrandr 1.2 revisited

In this post, I discussed "clone" mode of dual head with xrandr 1.2. Now I got an extra monitor, and would like to use "xinerama" mode, wherein the built-in laptop LCD and the external monitor share a single virtual screen. To set this up, I changed my /etc/X11/xorg.conf to add a monitor section for the external monitor:
Section "Device"
  Identifier "Intel 965GM"
  Driver   "intel"
  BusID     "PCI:0:2:0"
  Screen   0
  Option      "XAANoOffscreenPixmaps" "true"
  Option      "DRI" "true"
  Option      "monitor-LVDS" "Builtin"
  Option      "monitor-VGA" "External"
EndSection

Section "Monitor"
  Identifier "Builtin"
  Option   "DPMS" "true"
  DisplaySize 246 184
EndSection

Section "Monitor"
  Identifier "External"
  Option   "DPMS" "true"
  Option   "RightOf" "Builtin"
EndSection

Section "Screen"
  Identifier "Default Screen"
  Device "Intel 965GM"
  Monitor "Builtin"
  DefaultDepth 24
  SubSection "Display"
    Depth 24
    Modes "1024x768" "800x600" "640x480"
    Virtual 2048 768
  EndSubSection
EndSection
The "Virtual" directive tells X server to create a 2048x768 virtual screen, which is twice as wide as my laptop's built-in LCD's maximum resolution (1024x768). I am putting my external monitor to the right of the LCD. Of course, xrandr 1.2 can do that with "--pos" option. In my case,
xrandr --output VGA --pos 1024x0
moves the viewpoint of external monitor to the right half of the virtual screen. I would like to switch between "clone" and "xinerama" modes without restarting X server, and with a hotkey (I chose Fn+F8 here, for general hotkey setup, see this post). So I bind xrandr commands to ACPI hotkey event handler by editing /usr/lib/powersave/scripts/thinkpad_acpi_events:
...
# configuration file of kxdocker
KXDOCKER_CONF=/home/huahaiy/.kde/share/apps/kxdocker/kxdocker_conf.xml

4103)  
  HOTKEY="Fn+F7"
  ACTION="toggle external display"
  if run_on_xserver "xrandr -q" | grep "VGA connected"; then
    if run_on_xserver "xrandr -q" | grep "VGA connected [0-9]\+"; then
      run_on_xserver "echo 'Turn OFF External VGA Display' | $OSD" &;
      run_on_xserver "xrandr --output VGA --off"
    else
      run_on_xserver "echo 'Turn ON External VGA Display' | $OSD" &;
      run_on_xserver "xrandr --output VGA --mode 1024x768"
    fi
  else
    run_on_xserver "echo 'External VGA Display is DISCONNECTED' | $OSD" &;
    # stop kxdocker
    run_on_xserver "dcop kxdocker MainApplication-Interface quit"
    # tell X server VGA is unplugged
    run_on_xserver "xrandr --output VGA --off"
    # change kxdocker's configuration, so it starts with correct position
    sed -i -e 's/LeftForce="-512"/LeftForce="0"/' $KXDOCKER_CONF
    # start kxdocker again
    run_on_xserver "kxdocker"
  fi
  ;;
4104)  
  HOTKEY="Fn+F8"
  ACTION="toggle monitor layout"
  run_on_xserver "dcop kxdocker MainApplication-Interface quit"
  if run_on_xserver "xrandr -q" | grep "VGA connected"; then
    if run_on_xserver "xrandr -q" | grep "VGA connected 1024x768+1024"; then
      run_on_xserver "echo 'Switch to Clone Mode' | $OSD" &;
      run_on_xserver "xrandr --output VGA --pos 0x0 --fb 2048x768"
    else
      run_on_xserver "echo 'Switch to Xinerama Mode' | $OSD" &;
      run_on_xserver "xrandr --output VGA --pos 1024x0 --fb 2048x768"
    fi
    sed -i -e 's/LeftForce="0"/LeftForce="-512"/' $KXDOCKER_CONF
  else
    run_on_xserver "echo 'External VGA Display is DISCONNECTED' | $OSD" &;
    run_on_xserver "xrandr --output VGA --off"
    sed -i -e 's/LeftForce="-512"/LeftForce="0"/' $KXDOCKER_CONF
  fi
  run_on_xserver "kxdocker"
  ;;
...
I use kxdocker as my application launcher and taskbar, it looks great and works great too. To make it work with "kinerama" mode correctly, i.e. to keep it in the middle bottom portion of LCD, we need to restart it with different positions when display mode is changed. The above code does that.

Comments

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account associated with the e-mail address you provide, it will be used to display your avatar.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <div> <h1><h2><h3><sub><sup><b><i><u><font><img>
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Lines and paragraphs break automatically.

More information about formatting options

To prevent automated spam submissions leave this field empty.
Nice place