From: cek@sdc.boeing.com (Conrad Kimball)
Newsgroups: comp.windows.x
Subject: Re: playing with window managers
Summary: script to switch/select window managers
Date: 29 Dec 92 07:54:01 GMT
Organization: Boeing Computer Services, Seattle, WA

In article <1992Dec28.025916.22596@spectrum.xerox.com> leisner@eso.mc.xerox.com writes:
>
>I normally exec a window manager at the end of my .xinitrc...
>
>But how do I easily select different window managers to try out 
>(I'm talking about twm, vtwm, tvtwm, and ctwm?)
>
>Another apporach is to have a xterm window and the end of the .xinitrc, and
>exiting this window will kill X -- but this I find kludgy..
>
>Should I just kill the X server on my server and everything will die?

I use the following "choosewm" script, which I execute as the last command
in my .xinitrc file.  It lets me switch among any of the window managers
available on our system, or to terminate my X session.

------------------------------------------------------------------------
#!/bin/sh

# Post a menu to pick a window manager, then execute that window manager.
#
# When the window manager terminates this script regains control.  If the
# window manager terminated with an error condition an error message window
# is popped up; if the window manager terminated normally (i.e. the user
# explicitly terminated it), the window manager menu is popped up and the
# process continues ad infinitum.
#
# The window manager menu includes an entry to quit this process.  If
# this script is run as the last command in your .xinitrc or .xsession
# file, this menu selection serves to terminate the entire X session.
#
# The optional single argument specifies the initial window manager.
#
# This script depends on the contributed tools:
#	xmenu
#	xmessage
#	xprompt

PROGRAM=`basename $0`

Answer=Retry
while test "${Answer}" = "Retry"; do

    if test -n "$1"; then
	Wm=$1
	shift 1
    else
	Wm=`xmenu							\
	    -title "${PROGRAM}"						\
	    -name "${PROGRAM}-xmenu"					\
	    -heading "Choose a window manager"				\
	    "TWM"=twm							\
	    "CTWM"=ctwm							\
	    "TVTWM"=tvtwm						\
	    "VTWM"=vtwm							\
	    "MWM"=mwm							\
	    "GWM"=gwm							\
	    -line							\
	    "Quit X"=quit						\
	    `
    fi

    case "${Wm}" in
	twm)	WmCmd=twm;;
	ctwm)	WmCmd=ctwm;;
	tvtwm)	WmCmd=tvtwm;;
	vtwm)	WmCmd=vtwm;;
	mwm)	WmCmd=mwm;;
	gwm)	WmCmd=gwm;;
	quit)	exit;;
	*)	WmCmd="${Wm}";;
    esac
    
    # execute ${WmCmd} so we capture its exit code in a shell variable,
    # and a copy of its stderr on a file, while all stdout and stderr
    # information goes wherever it is currently directed, unscathed.

    StdErr="${TMPDIR:-/tmp}/choosewm.stderr.$$"
    trap 'rm -fr ${StdErr}' 0 1 2 3 15 18
    rm -f ${StdErr}
    exec 3>&1
    ErrorCode=`exec 4>&1; (eval ${WmCmd} 2>&1 1>&3 3>&-; echo $? >&4) | tee ${StdErr} 1>&2`
    exec 3>&-
    ErrorMessage=`cat ${StdErr}`
    rm -f ${StdErr}
    Answer=Retry
    
    if test ${ErrorCode} -ne 0; then
    
	Answer=`xmessage						\
	    -title "${PROGRAM} error:"					\
	    -name "${PROGRAM}-xmessage"					\
	    -buttons Quit,Retry -print -message				\
"${Wm} failed - error code: ${ErrorCode}

Command was:
${WmCmd}
    
Error message(s):
${ErrorMessage}
"`
    
    elif test -n "${ErrorMessage}"; then

	${LOCAL_BINPATH_xmessage}					\
	    -title "${PROGRAM} warning:"				\
	    -name "${PROGRAM}-xmessage"					\
	    -buttons OK -message					\
"${PROGRAM} warning - ${Wm} warning:

Command was:
${WmCmd}

Warning message(s):
${ErrorMessage}
" &

    fi		# end of test ${ErrorCode} -ne 0
    
    if test "${Answer}" = "Quit"; then
	exit ${ErrorCode};
    fi
    
done
-- 
--
Conrad Kimball       | Client Server Tech Services, Boeing Computer Services
cek@sdc.boeing.com   | P.O. Box 24346, MS 7A-35
(206) 865-6410       | Seattle, WA  98124-0346
Newsgroups: comp.windows.x