Team LiB
Previous Section Next Section

Hack 19. Get Multiple Desktops the Macho Way

Power users don't need no stinkin' graphical login managers, so here's the command-line way.

This hack assumes you're not the type who likes to have graphical login screens running all the time. You want your computer to boot to a text login prompt, after which you're perfectly capable of getting a graphical desktop running. You might still want the ability to have a second person log in and start another desktop. So, here's how.

I'll assume you're the power user who avoids GDM, KDM, and XDM. When your computer finishes booting, it leaves you in a virtual console (virtual terminal 1) with a text login prompt. You log in, and then you start your favorite window manager or desktop using whatever command is most familiar to you. Perhaps you type startkde to start the KDE environment. You could type xinit /usr/bin/wmaker to start WindowMaker. You could also type startx alone to start your default window manager. The default window manager could be defined in various ways, depending on the Linux distribution you're using. In most cases, power users configure the ~/.xinitrc file to define the default window manager, among other things (~/.xinitrc also lets you define other programs to start automatically, etc.).

If you want another user, such as your power-user daughter, to log in and start up a separate desktop, press Ctrl-Alt-F2 to get to the second text console with a login prompt. When she logs in, she can start a new WindowMaker desktop without disturbing your desktop by typing either of the following two commands:

xinit /usr/bin/wmaker -- :1
$ startx /usr/bin/wmaker -- :1

In this case, you add a space, a double-dash followed by a space, then a colon, and then a 1. This tells your system to run WindowMaker on the second virtual console allocated for graphical desktops (the default is 0, so the next available graphical console is 1).

This is a rather inconvenient way to do things because you must be sure display 1 is not in use, and you must know the exact path to the window manager or desktop environment you want to start. Neither of the following simpler commands works, because they do not include the full path to the executables:

$ xinit wmaker -- :1
$ startx wmaker -- :1

The following script makes this whole process much easier. All you need to know is the name of the executable file that starts your preferred window manager or desktop. Log in as root, or use sudo to fire up your favorite text editor, and type in the following script:


for screen in 0 1 2 3 4 5 nomore
    if [ "$screen" = "nomore" ]
        echo "No more available screens."
        exit 1
      [ ! -e /tmp/.X${screen}-lock ] && break

if [ -x "`which ${1} 2>/dev/null`"  ]
    windowmanager="`which ${1} 2>/dev/null`" 
    echo $windowmanager
    xinit $windowmanager -- -br :$screen
    xinit -- -br :$screen

Save it as /usr/local/bin/mstartx. (I used the name mstartx because it is short for multiple-startx, but you can name your script anything you want.) Then change the script to be executable with this command:

# chmod +x /usr/local/bin/mstartx

Now all you have to type to start WindowMaker is this:

# mstartx wmaker

The script performs two important tasks. First, it finds the first available graphical console. If two people are already using graphical desktops, the script will detect this and automatically run the next session on the third graphical desktop. Second, it automatically locates the full path to the executable file for the window manager you want to start (/usr/bin/wmaker in this example). As an added bonus, this script changes the default startup background from a gray mesh to solid black. [Hack #22] provides an alternate way to blacken your startup background.

Table 3-1 lists the executable filenames for the most popular window managers.

Table 3-1. Window manager executable filenames

Window manager or desktop environment

Executable filename









XFce 4









fluxbox or startfluxbox






fvwm or fvwm2

XFce 3




No matter which method you choose for launching a second or third user desktop session, you probably want to keep your current session protected. Configure the screensaver for your favorite desktop environment or window manager to lock the screen and require a password to get back to work. When someone else wants to log in with a separate desktop session, start the screensaver (thus locking out anyone without your password) before you allow her to log in on the next virtual terminal.

    Team LiB
    Previous Section Next Section