Virtually every release of XFree86 includes a nest X server, called Xnest. This is simply an X server that is simultaneously an X client. In most instances, this is completely useless. Why would you want to run an X server inside of an X server on Linux? Debugging. Why would you do it in OS X? You do it so you can run KDE in a window.
Read the rest of the hint for the how-to...
For every window manager that you want to be able to run, you need a separate .xinitrc file. For KDE, I have a file in my home directory called .xinitrc.kde that only contains the following line:
exec /sw/bin/startkde
Note that I do not actually have a file in my home directory called .xinitrc, as I am using Apple's quartz-wm to control these windows. The tricky part is to get the new x-session open. The xinit script makes this quite simple:
xinit ~/.xinitrc.kde -- /usr/X11R6/bin/Xnest :3 -geometry 800x600
The ~/.xinitrc.kde represents the script we have written that launches kde. Anything that immediately follows this gets passed to the script.The first item that follows -- represents the name of the X server. We want this to be /usr/X11R6/bin/Xnest because that's where Xnest should be. Everything after this counts as arguments to the Xnest command (man Xnest for more info).
The default X server (XDarwin or Apple's X11) uses display :0 as the default, so you must pick a number higher than that. Also, if you want to be able to launch more than one Xnest session, each of these will need to have a different display number. The -geometry argument just tells Xnest how big of a window you want.
Give it a shot as described above. If you like being able to run KDE or other window managers in a window, you can set them up for easy launching as aliases in your .tcshrc file or as applications in the X11 "Applications" menu.
For extra fun, you can also launch these Xnest sessions on remote machines through ssh (HOWTOs available elsewhere). Have fun!

