From: cek@sdc.boeing.com (Conrad Kimball)
Newsgroups: fj.mail-lists.x-window
Subject: Re: X client that sits & waits SUMMARY
Date: 20 Dec 92 17:19:20 GMT
Distribution: fj
Organization: Boeing Computer Services (ESP), Seattle, WA

Date: 19 Dec 92 08:21:34 GMT
Message-Id: <7656@fury.BOEING.COM>
Newsgroups: comp.windows.x

In article <1992Dec14.131654.21870@fwi.uva.nl> wijkstra@fwi.uva.nl (Marcel Wijkstra (AIO)) writes:
>
>SUMMARY
>-------
>Recently, I posted a request for an X client that just sits and waits
>(until it gets killed). The reason for this, was that I wanted this client
>to be the last one executed in my .xinitrc, so that I would be able to
>kill my window manager (which normally is the last line in .xinitrc) without
>terminating X.  This would allow me to start a different window manager.
>Finally, killing the small X client would end my X session.

[ deleted summary of replies ]

>MY OWN SOLUTION
>---------------
>With the help of all above mentioned advises, and vdlinden@fwi.uva.nl, I
>created some solution myself:
>
>I use a script 'wm' to start and switch the different window managers:
>
>	#!/bin/csh -f
>	
>	 switch ($1)
>	  case mwm:
>		goto MWM
>	  case twm:
>		goto TWM
>	  default:
>		exit
>	 endsw
>	
>	MWM:
>	 mwm
>	TWM:
>	 twm
>	 goto MWM
>
>This script simple calls it first argument - which must be the desired
>initial window manager (e.g. 'wm mwm'). When this one exits, the next
>one is started.
>If you need more than 2 window managers, you may need some other mechanism
>than this simple loop. But I'm sure you Xperts can write a fancy menu-driven
>window manager selector if you need one...

And here is the one I use :-)


#!/bin/sh

# Post a menu to pick a window manager.  When that window manager
# terminates, repost the menu to pick another window manager.  The
# optional first argument is the initial window manager selection.
# The menu includes an entry that quits this script which in turn
# causes X to terminate (assuming this script is the final program
# executed in .xinitrc or .xsession).
#
# Depends on additional contrib tools "xmenu" (for posting the
# menu) and "xmessage" (for posting error and warning messages). 

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=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="/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 there is an error, tell the user
    
    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}
"`
    
	if test "${Answer}" = "Quit"; then
	    exit ${ErrorCode};
	fi

    # no error, but if there is any output on stderr (warnings), tell the user
    
    elif test -n "${ErrorMessage}"; then

	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
    
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