One of the best things about a Linux system is its flexibility. Even though I’ve been a heavy Linux user for years, I still come across features in the OS a related applications that surprise me. A while back I learned to run multiple desktop environments at the same time, using nothing but the features of the software already built in to my distribution, and it’s been very useful for me. It may not sound like much, but it can be VERY useful to be able to run Gnome, KDE, Window Maker, and any other desktops all at the same time. You can flip from Gnome to Window Maker in seconds without having to log out or stop applications or use any kind of virtualization software. X already has everything you need.
To make sure there’s no confusion, I’m NOT talking about multiple monitors. The idea behind this article is that we’ll have multiple desktop environments running on the same computer at the same time, and we’ll be using keyboard shortcuts to switch between them.
For anyone who’s not sure what I mean when I talk about “X”, that’s the shorthand name for the X Window System. Most modern distributions use X.org to handle all their graphical needs. Basically, any time you’re seeing graphics (not just plain text), you’re probably looking at X. It manages the display for Linux and controls what’s on your screen and how it’s handled.
X keeps track of things by screens or displays. Right now, if you’re reading this article in Linux, you’re probably on the default screen number 0. You can access the different screens with key combinations. To try it out right now, try hitting Alt+Ctrl+F1. That’ll take you to your first console screen. To get back to the graphical screen, hit Alt+Ctrl+F7. Many people use this as a way to drop to a fullscreen terminal without having to close X.
At this point, you may be thinking “Why F1 and F7?”. Well I’m glad you asked, even though you didn’t really ask. When holding Alt+Ctrl, keys F1 through F6 are your console screens. They’re commonly called virtual terminals. Each one has a separate instance of the console running on it, and you can flip back and forth between them using Alt+Ctrl+(F1 through F6).
Once you get past F6, you’re in X’s territory. Much like the virtual terminals, each screen starting with F7 is a separate instance of X, which can have its own programs running, independent of the other screens. So what we’re going to do now is set things up to launch your other desktop environment in the next screen over.
Setting up the second screen
For starters, we’ll want to install whatever window manager or desktop environment you’d like to have running on your second display. In a move that will surprise no one, I’ll recommend Window Maker. For the remainder of this article, I’ll assume that you’re running Ubuntu in the default configuration and that the desktop environment you want to use is Window Maker.
Once you’ve installed Window Maker (or whatever other desktop you’d prefer) the first thing we need to do is open/create the file .xinitrc in your home. When X is launched from the command line, it reads this file to decide what needs to be run when X starts. So open or create the file .xinitrc in your home directory, and add the line:
Running the second desktop
Now we’re at the main event. Open your command prompt and enter:
startx -- :1
That will tell X to start and to use display number 1 (instead of the default of 0 which you’re probably using as your main desktop). If all went well, you’ll find yourself looking at the default (and kinda ugly) base Window Maker desktop. To switch back to your main desktop, use Alt+Ctrl+F7. Back to Window Maker is Alt+Ctrl+F8. If things didn’t go so well, see the Troubleshooting section below.
Alt + Ctrl + F7 = Gnome desktop
Alt + Ctrl + F8 = Window Maker desktop
X: user not authorized to run the X server, aborting.
This one is a config issue, and one that’s easily remedied. Open the following file as root:
sudo gedit /etc/X11/Xwrapper.config
I can’t claim to know enough about X’s programming to be able to make any educated statements about potential security problems this may or may not present, but it fixes the problem.
X: client 1 rejected from local host
Another simple fix, just delete any files in your home directory that has a filename starting with .Xauthority
You can repeat this process to add any other desktop environments you may happen to want, just change the 1 in
startx -- :1
to 2, 3, etc. There are plenty of function keys left!