...making Linux just a little more fun!

<-- 2c Tips | TAG Index | 1 | 2 | 3 | 4 | Knowledge Base | News Bytes -->

The Answer Gang

By Jim Dennis, Karl-Heinz Herrmann, Breen, Chris, and... (meet the Gang) ... the Editors of Linux Gazette... and You!

(?) Experimenting with window managers

From Ben Okopnik

Answered By: Thomas Adam, Ben Okopnik, Jay R. Ashworth, Heather Stern

One of the things that often puzzles new Linux users is the broad range of available window managers (WMs). After all, MS Wind0ws only has one (although several Linux WMs have been ported to The Dark Side)... what's a WM *for,* anyway?

(!) [Heather] Actually, in earlier versions of mswin, there was an occasional shareware offering or product that replaced the common widget set - one gave 3d-appearance - but it's rare as all heck, and since it replaced the common controls dialog, fraught with app incompatibility too. Most replacements (e.g. Norton Desktop for Windows, HP's NewWave) only changed out the Program Manager (in win3.x) and the current crop mostly replace only Explorer (in win9x). There is LiteStep (http://www.litestep.net), and at least one other whose name I don't recall.
Since I haven't used LiteStep myself, I don't know whether it replaces both aspects, or just Explorer. From the user's point of view it basically counts, since it changes the launching and theme mechanisms, which are the main visible aspects of a window manager.

(?) To quote Wikipedia http://wikipedia.org :

"A window manager is
software that controls the placement and appearance of application
windows under the X Window System". Most (but not all) WMs share a
common base of ideas - e.g., each window will usually have a top bar,
which will commonly have close/minimize/maximize buttons as well as a
menu button.  However, all WMs have different approaches to the task
described above - and some may fit your preferences and work habits far
better than others."

So, here's an easy way to experiment:

1) Make sure your system does not start X automatically. The easy way to do this is by setting the default runlevel in "/etc/inittab" to a "console-only" level - this is level 2 for most distros.

(!) [Jay] Note that while that characterization of runlevel 2 is correct, it's somewhat incomplete: the functional equivalent, in most distros, to runlevel 5 with X is runlevel 3, without, but with all the other network stuff which would usually be running.

(?) 2) Create a ".xinitrc" file in your home directory; this is a shell script that allows you to customize how X works - including the choice of window manager. Here's a template that you can adapt however you'd like later:

See attached template-xinitrc.sh.txt

You'll want to change the last two commands to start whatever WM you normally use, so that the default invocation of "startx" will use that. If, however, you wish to experiment with another WM, the process becomes very simple: just set the "WM" variable to the name of the manager you want (you do, of course, have to have it installed) and - voila, you're off and running. E.g., to try running X with "fvwm" as a WM, just type

WM=fvwm startx
at the console. Note that I launch two xterms (command windows) by default; this is obviously not a requirement, but I find them to be very useful in general.
(!) [Thomas] One other thing that users might like is the fact that you can also experiment with window managers, X stuff using 'Xnest'. Something I use is:

See attached xnesting-wm.bash.txt

Which then gives me an 800x600 Xserver within an Xserver. Incorporating your WM-selector means that it is invoked in the same manner as yours:
WM=fvwm innerwm
Then things change slightly to look at how X loads. -- Thomas Adam

(!) [Thomas] It's worthy of note that ~/.xinitrc is only read by startx, whereas ~/.xsession is read by graphical display managers, and startx when no ~/.xinitrc exists. But this out of context to your tip. :)
(!) [Ben] Explicitly so, since simply modifying ~/.xsession will not do anything useful here (and may, in fact, produce quite a train wreck.) And trying to actually change (or add) a WM to the [xkg]dm system is a bloody nightmare, for which I hope some evil bastard rots in hell. There are no instructions anywhere that I could find; the X startup mechanism itself involves at least twenty different shell scripts and sourced files, scattered through /etc/X11 and /usr/lib (I gave up after parsing the arcane syntax of that many); neither "/etc/alternatives/x-window-manager" nor "/etc/X11/default-display-manager" have any actual use or meaning; adding the name to 'SessionTypes' in "/etc/kde2/kdmrc", *where the WM choices are listed*, doesn't work... /und so weiter/, right to the point of the screaming meemies.
(!) [Thomas] Actually, they do. If we take xdm as the example here (although all DMs go through the same process), what happens is as soon as you press enter to login, the file /etc/X11/xdm/Xsession is sourced (sourced, for obvious reasons, as you are fully aware, Ben :))). This actually calls the main file /etc/X11/Xsession. The job of this file is to kickstart X, and sources the files in /etc/X11/Xsession.d
The files in this directory are structured similarly to how init files are -- they have a number prefix which denotes the order that they're to be sourced. Now, the debian bit that comes into play here (and which confuses many) is the part about "update-alternatives". Since it is at this point, that the alternative "x-termianl-emulator" is looked for, and launched. By default, this is an xterm.
Next to run, is a script that sets up ones xrdb database, so that any xresources that might have been defined for applications are sourced. Although if you're going to define your own, you must still add the following line to ~/.x{session,initrc}:
xrdb -merge ~/.Xdefaults
Following that, is the wrapper script that looks for a user-defined configuration file (~/.xsession), or whether we have to default back to a global one. They key to note here is that user-defined is looked for before global. If it is found, then a variable (STARTUP) is set accordingly, else the default is used.
When that has been done (I'll skip the boring stuff such as Xprint server running), the last scriot to run is an exec call is made to $STARTUP.
As to how "x-window-manager" is used, that is defaulted to for $STARTUP when a user config file is not found.
(!) [Ben] [snip] Thanks for detailing it (would be nice if this was in the docs somewhere), but - yep, been through all that. Lots of times. Trying to set it up to allow a choice of WMs just doesn't work for yours truly; there may be someone for whom it does, but that someone isn't me.
(!) [Thomas] Well, KDM and GDM are separate entities in themselves. Being the bloated pile of jelly they are, not only do they consume the PC, but they also like to do thing Their Way -- to the extent that GDM actually ignores ~/.xsession . And I have no idea how the hell KDM operates -- that's just a nightmare.
So I use xdm when I have to (really I only use it for the Xchooser part), otherwise it's startx all the way.
(!) [Ben] [Nod] I was conflating the three of them, but yeah - "xdm" isn't quite as bad as the others, and GDM has not actually eaten any small children while I was watching (although I've heard rumors.) KDM, now - that thing should not be let out on the streets, or should at least be heavily medicated, have a transmitter strapped to its ankle, and be continuously monitored by professionals armed with tasers and nets.
(!) [Thomas] And xdm does honour ~./.xsession, that much I assure you. If it ever gets ignored, the tip I can always suggest is that you treat it exactly as a shell-script -- actually give it a she-bang line, and chmod +x it.
(!) [Ben] Given *that,* I can just imagine some GNUbie trying to tweak this... they'd go running in blind terror - right back to their "comfortable" MSW environment, which may crash, burn, explode, and destroy their work with malicious intent but never requires them to hunt through dozens of files just to change one simple thing.
(!) [Thomas] Which is why I get them to create a ~/.xsession file, anyway.
(!) [Ben] If I actually wanted to choose a different WM every time, or at least have a choice presented to me, I'd launch "selectwm" and do it from there. Nice, simple, easy to configure and modify. In fact, when I have a range of similar WMs and want to compare them (as I recall, I did it when I was looking at ratpoison, larswm, ion, and some others), that's what I do.
(!) [Thomas] Yup. "selectwm" has been damned useful. One thing I used to do to xdm, was assign the function keys to various window managers. I still do, in fact. So that, rather than pressing enter, I'd press CTRL-F2 and have it launch 'twm', CTRL-F3, and have it launch 'fvwm', or whatever. Note that 'F1' by itself in xdm defaults to an xterm -- so-called "failsafe".

This page edited and maintained by the Editors of Linux Gazette
HTML script maintained by Heather Stern of Starshine Technical Services, http://www.starshine.org/

Each TAG thread Copyright © its authors, 2004

Published in issue 105 of Linux Gazette August 2004

<-- 2c Tips | TAG Index | 1 | 2 | 3 | 4 | Knowledge Base | News Bytes -->