#!/bin/sh
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License, Version 1.0 only
# (the "License").  You may not use this file except in compliance
# with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#


HAS_XSCRNSVR=0
X11_BIN=/usr/X11/bin
DESKTOP_SESSION=${DESKTOP_SESSION:-"xdm"}
MAIL=${MAIL-"/var/mail/$USER"}
SHELL=${SHELL-"/bin/sh"}
DISPLAY=${DISPLAY-":0"}
TERM=${TERM-"xterm"}

case $DESKTOP_SESSION in
gnome|GNOME|JDS|tgnome|TGNOME|tjds|TJDS|TrustedJDS)
    EDITOR=${EDITOR:-"gedit"}
    ;;
kde|KDE)
    EDITOR=${EDITOR:-"kedit"}
    ;;
mate|MATE)
    EDITOR=${EDITOR:-"pluma"}
    ;;
*)
    EDITOR=${EDITOR:-"vi"}
    ;;
esac

for XPATH in `/bin/echo $PATH | /bin/tr ":" " "`
do
  if [ -x $XPATH/xscreensaver-demo ] ; then
    HAS_XSCRNSVR=1
  fi
done

if [ $HAS_XSCRNSVR -eq 0 -a -x $X11_BIN/xscreensaver-demo ] ; then
  PATH=${PATH}:$X11_BIN
fi

export PATH EDITOR MAIL TERM SHELL DISPLAY

if xmodmap | /usr/bin/grep mod4 | /usr/bin/grep Alt > /dev/null 2>/dev/null
then
    xmodmap -e "clear Mod1" \
            -e "clear Mod4" \
            -e "add Mod1 = Alt_L" \
            -e "add Mod1 = Alt_R" \
            -e "add Mod4 = Meta_L" \
            -e "add Mod4 = Meta_R"
fi