I have two screens connected to a powerful box. Mostly, I’m using these for coding and it’s running Xinerama with radeon (sssh don’t say anything).

Only sometimes however, I would like to share the machine with a second user.

There are several recommended ways for multiseat setup:

  • Configure the Xserver with seperate screens (not Xinerama). Start Xephyr/Xnest on each screen
  • Start two seperate Xserver (this requires seperate graphic cards or maybe this patch which I couldn’t get to work)

Furthermore, you need to fiddle with the login manager to do everything “right”.

As my setup is more temporary, I opted for a middle way. It remains not without rough edged though… The main login remains running on two screens, and in the case of wanting to share, I will set up a Xephyr instance on one monitor.

Because of Xinerama, Xephyr doesn’t work out of the box like that. So I chose a small hack: I open an empty xterm (which has the netwm ability to go to fullscreen) and embed the Xephyr in it:

uxterm -title Xephyr +sb -hold -e ''

move the xterm window to the second monitor and switch it to fullscreen… I am using Gnome and have assigned a keybinding for that. That way, Xephyr will be running “full screen” on just one monitor, something that it isn’t able to do on its own (Xephyrs fullscreen would expand over both monitors due to Xinerama)

Now we need to start the Xephyr and allow the login for the other account. Again, we have two possibilities. One is to use the xdmcp mode of gdm, and another to use gdmflexiserver — the Gnome user switcher.

Update: I can’t get the SCIM input method editor to work with xdmcp… anyone knows why? So I’ve resorted to the gdmflexiserver one for now.

For the xdmcp, we need to enable it. For example, in SuSE, set DISPLAYMANAGER_REMOTE_ACCESS="yes" in /etc/sysconfig/displaymanager. Then it is enough to use a wrapper script. For access to the input devices, root permission is required though.

For the gdmflexiserver approach on the other hand, it is necessary to replace /usr/bin/Xorg — since gdmflexiserver --xnest is “not implemented”…

The wrapper script or Xorg replacement thus works like this:

First, we define the devices which we want to give the Xephyr use:

#!/bin/zsh
mouse=Razer_Razer_1600dpi_3_button_optical_mouse
keybd=046a_0011

These are examples from my box, the Razer is a mouse and the strange keyboard is a cheap Cherry one — who knows why they can’t afford to brand its ID. Look in /dev/input/by-id after connecting your devices to find out their IDs. This approach is more flexible than using the “event#” devices, whose numbering might change if connected differently.

Now construct the real paths and add some checks to see if the devices are connected:

mouse=/dev/input/by-id/usb-${mouse}-event-mouse
keybd=/dev/input/by-id/usb-${keybd}-event-kbd
if [[ -h $keybd && -h $mouse ]] {

only in the Xorg case, we now loop over all available displays and find the first one which has a empty xterm window created as outlined above, to plant the Xephyr into:

   for ((disp=0;disp<$((${DISPLAY#*:}+0));++disp)) {

in the wrapper case, we set the dummy disp variable instead

   disp=$((${DISPLAY#*:}+0))

finally, we locate the empty window using xwininfo and the -title as specified on top:

   OIFS=$IFS; IFS=$'\n'
    winin=($(DISPLAY=:$disp xwininfo -name Xephyr -children)); IFS=$OIFS
    if [[ $winin[1] == 'xwininfo: Window id: '*' "Xephyr"' && \
        $winin[4] == '     1 child:' && \
        $winin[5] == *' (has no name): ()'* ]] {
        winid=($=winin[1])
        if [[ $winid[4] == 0x* ]] {
            fontsdir=(/usr/share/fonts/*(/))

Xephyr doesn’t seem to know about the default fonts, so we construct a fontsdir here, might need to adjust this to your local site font dirs. Now for the start command. In case of the Xorg replacement for use with gdmflexiserver, it is important to get rid of the -verbose flag which Xephyr does not understand. The -parent switch designs Xephyr to embed itself into another window:

exec env DISPLAY=:$disp Xephyr -zap -retro \
    -mouse evdev,,,device=$mouse \
    -keybd evdev,,device=$keybd,xkbmodel=evdev \
    -fp ${(j:,:)fontsdir} -parent $winid[4] \
    ${@:#-verbose}

for the wrapper script, we use the -query parameter for xdmcp query:

exec gnomesu -- Xephyr -zap -retro \
    -mouse evdev,,,device=$mouse \
    -keybd evdev,,device=$keybd,xkbmodel=evdev \
    -fp ${(j:,:)fontsdir} -parent $winid[4] \
    -once -query $@

just finish all the open blocks now…

       }
    }
}

however, in the Xorg replacement script, we will want to fall back to the real Xorg when we haven’t prepared any special window for Xephyr:

}
exec Xorg.old $@

As you can see, we moved /usr/bin/Xorg to /usr/bin/Xorg.old and put the replacement script up as /usr/bin/Xorg instead. That way, you can now prepare an xterm window as per above and execute gdmflexiserver without need for root.

With the wrapper script, just save it somewhere. You can then call it like this:

./xephyr-xdmcp 127.0.0.1 :3

Where 127.0.0.1 means your local host which you are going to query using xdmcp and :3 is a free display number for Xephyr to listen on.

An outstanding trouble I’m having in both cases is with the Gnome keyboard-properties tool which will set the keyboard layout upon login. Since it needs a different layout — evdev layout in the case of Xephyr, and local connected keyboard layout in the case of plain X, it will break the keyboard layout directly after login.

So far the only workaround is to rightclick on the desktop, “Open Terminal” and type in the command

setxkbmap -model evdev

before you can start working proper in the Xephyr instance. Maybe someone can come up with a better fix?

update for openSUSE 11.4

we loop over all gnome-sessions instead of all displays. we need an anchor to steal the environment:

   for gs (/proc/*/exe(@e.'[[ $REPLY:A == =gnome-session ]]'.:h:t)) {

we then proceed to read the environment of that session

       OIFS=$IFS; IFS=$'\0'
        for env ($(</proc/$gs/environ)) {
            if [[ $env == DISPLAY=* \
                || $env == XAUTHORITY=* \
                || $env == XAUTHLOCALHOSTNAME=* ]] {
                # save these environments for later
            }
        }

use these saved environments in the call to xwininfo and Xephyr, which would fail otherwise!

to fix some font oddities, we also hardcode the fontsdir to the same as the parent X server, as observed in /var/log/Xorg.0.log.