#!/bin/csh -f
# Global xsession file
# Accepts one optional argument "nocalls" (i.e., use no user files)
# $Author: epeisach $
# $Source: /paris/source/4.3/athena.lib/init/RCS/xsession,v $
# $Header: /paris/source/4.3/athena.lib/init/RCS/xsession,v 1.7 89/08/14 21:44:20 epeisach Exp $

# Note: This shell script deliberately uses the -f flag.
set home=/afs/sipb.mit.edu/user/cjsmith
set initdir=/usr/athena/lib/init

# Determine whether to use user customizations:  use no customization files
# ONLY if the single argument "nocalls" was provided to xsession (e.g., if
# the user selected the SYSTEM option from the initial xlogin menu).

switch ($#argv)
    case 0:
        breaksw
    case 1:
        if (($1 == nocalls) || ($1 == -nocalls)) then
            echo -n "xsession: Running standard xsession "
            echo "with NO user configuration files..."
            setenv NOCALLS
        else
            set bad_args
        endif
        breaksw
    default:
        set bad_args
endsw

if ($?bad_args) then
        echo "xsession: Arguments ($argv) not recognized."
        echo "Running standard xsession with user configuration files..."
        unsetenv NOCALLS
        unset bad_args
endif


# Do not echo status messages if noninteractive shell.  For interactive shells,
# echo messages unless user has ~/.hushlogin file AND the session was not 
# started using the xlogin "SYSTEM" option.

	if ((! -r ~/.hushlogin) || ($?NOCALLS)) set verbose_login


# *******************   ENVIRONMENT SETUP   *******************


# Identify this as a window session.

setenv XSESSION


# The ~/.cshrc file sets environment variables, attaches lockers, and sets
# the command search path.

if ($?verbose_login) echo "Setting up environment..."

if ($?NOCALLS) then
	if (-r ${initdir}/cshrc) source ${initdir}/cshrc
else
	if (-r ~/.cshrc) then
		source ~/.cshrc
	else 
		if (-r ${initdir}/cshrc) source ${initdir}/cshrc
	endif
endif



# *******************   DEVICE SETUP   *******************


# Load user X resources.

if ((! $?NOCALLS) && (-r ~/.Xresources)) /usr/bin/X11/xrdb -merge ~/.Xresources


# Start window manager.  To change your default window manager, set the 
# WINDOW_MANAGER environment variable in your ~/.environment file.

if (! $?WINDOW_MANAGER) setenv WINDOW_MANAGER uwm
if ($?verbose_login) echo "Starting $WINDOW_MANAGER window manager..."
($WINDOW_MANAGER &)



# *******************   ACTIVITY STARTUP   *******************

# Run standard system/user startup activities


# Start default initial xterm window.  To skip this, put the command
# "set skip_initial_xterm" in your ~/.environment file.

# BE CAREFUL:  If you skip this, make sure that your ~/.startup.X file
# provides a way for you to exit your session (e.g., an xterm from which
# you can type "logout"). 

if (! $?skip_initial_xterm) then
	if ($?verbose_login) echo "Creating initial xterm window..."
	(xterm -rv -geometry 80x56+0+0 &)
endif

# Run default system startup activities.  To skip these, put the command
# "set skip_x_startup" in your ~/.environment file.

if (! $?skip_x_startup) then
	if ($?verbose_login) echo "Running standard startup activities..."
	/usr/etc/zwgc					# Start Zephyr client
	# If zephyr started okay, send message of the day as windowgram
	if ($status == 0) /bin/athena/get_message -new -zephyr
	/usr/new/mh/bin/msgchk -nonotify nomail		# Check for mail
	(/usr/athena/olc who &) >& /dev/null		# Ping the OLC server
endif


# Run the window-session customizing commands in your ~/.startup.X file.

if ((! $?NOCALLS) && (-r ~/.startup.X)) then
	if ($?verbose_login) then
	  echo "Running custom startup activities listed in ~/.startup.X..."
	endif
	source ~/.startup.X
endif


# Start the xlogout window.  To skip this, put the command
# "set skip_xlogout" in your .environment file.

if (! $?skip_xlogout) then
	(/usr/athena/xlogout &)
endif


if ($?verbose_login) echo "Session initialization completed."


# Gate the session.

# This command, NOT run in the background, "gates" your session.  When
# this process terminates, the session ends and you are logged out.
# To terminate this process, type the "logout" command in an xterm window
# or invoke the "end_session" program.

/usr/athena/session_gate				# Wait for logout


# Run any user-specified shutdown activities

if ((! $?NOCALLS) && (-r ~/.logout)) source ~/.logout
