#!/bin/ksh

# ###########################################################################
#
#  Common Desktop Environment
#
#  (c) Copyright 1993, 1994 Hewlett-Packard Company
#  (c) Copyright 1993, 1994 International Business Machines Corp.
#  (c) Copyright 1993, 1994 Sun Microsystems, Inc.
#  (c) Copyright 1993, 1994 Novell, Inc.
#
#      ************** DO NOT EDIT THIS FILE **************
#
#  /usr/dt/config/Xsetup is a factory-default file and will
#  be unconditionally overwritten upon subsequent installation.
#  Before making changes to the file, copy it to the configuration 
#  directory, /etc/dt/config. You must also update the setup
#  resource in /etc/dt/config/Xconfig.
#
# ###########################################################################

# ###########################################################################
# 
# Directory specifications
# 
# ###########################################################################


  XDIR=/usr/openwin/bin









# ###########################################################################
#  
# Append desktop font aliases to font path
#
# ###########################################################################


ADDFONTPATH_LOCAL() {
        # Combine lines together to make arguments for the xset command
        FP=`awk '
        BEGIN { fp="fp+ " }
        /^[     ]*$/ { fp=" +fp " ; continue }
        { printf("%s%s", fp, $0) ; fp="," } ' $1`
        if [ -n "$FP" ]; then

                eval "xset $FP"
        fi
}

ADDFONTPATH_REMOTE() {
        nawk '  BEGIN {
                fp=" fp+ "
               XDIR=0
                }
                /^[     ]*$/ {
                fp=" +fp " ; continue }
                {cmd = sprintf("%s%s%s%s%s",XDIR,"/xset",fp, $0," 1>/dev/null");
                system(cmd); } ' XDIR=$OPENWINHOME/bin  $1
}







    #
    # Switch Sun's Alt and Meta mod mappings to work with Motif
    #
    if xmodmap | /bin/grep mod4 | /bin/grep Alt > /dev/null 2>/dev/null
    then
	$XDIR/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


    #
    # Append desktop font paths. Note: these directories should be
    # accessable by the X server. The file precedence is:
    #
    #   /etc/dt/config/xfonts/C
    #   /usr/dt/config/xfonts/C
    #   /etc/dt/config/xfonts/$LANG
    #   /usr/dt/config/xfonts/$LANG
    #


    if [ "$DTXSERVERLOCATION" != "remote" ]; then

      #
      # Since X server is local, optimize by checking local desktop
      # font directories and making one call to xset.
      #

      if [ -r $OPENWINHOME/lib/locale/$LANG/OWfontpath ]; then
          ADDFONTPATH_LOCAL $OPENWINHOME/lib/locale/$LANG/OWfontpath
      fi

      if [ -f /etc/dt/config/xfonts/C/fonts.dir ]; then
          fontpath=/etc/dt/config/xfonts/C
      fi

      if [ -f /usr/dt/config/xfonts/C/fonts.dir ]; then
        if [ -z "$fontpath" ]; then
          fontpath=/usr/dt/config/xfonts/C
        else
          fontpath=$fontpath,/usr/dt/config/xfonts/C
        fi
      fi

      if [ "$LANG" != "C" ]; then
        if [ -z "$fontpath" ]; then
          if [ -f /etc/dt/config/xfonts/$LANG/fonts.dir ]; then
            fontpath=/etc/dt/config/xfonts/$LANG
          else
            fontpath=$fontpath,/etc/dt/config/xfonts/$LANG
          fi
        fi
      fi

      if [ "$LANG" != "C" ]; then
        if [ -f /usr/dt/config/xfonts/$LANG/fonts.dir ]; then
          if [ -z "$fontpath" ]; then
            fontpath=/usr/dt/config/xfonts/$LANG
          else
            fontpath=$fontpath,/usr/dt/config/xfonts/$LANG
          fi
        fi
      fi


      if [ ! -z "$fontpath" ]; then
        $XDIR/xset fp+ $fontpath
      fi

    else
      #
      # Since X server not local, we don't know if the desktop font
      # directories exist on the X server machine, so we have to
      # set them one at a time.
      #

      if [ -r $OPENWINHOME/lib/locale/$LANG/OWfontpath ]; then
          ADDFONTPATH_REMOTE $OPENWINHOME/lib/locale/$LANG/OWfontpath
      fi

      $XDIR/xset fp+ /etc/dt/config/xfonts/C 1>/dev/null

      $XDIR/xset fp+ /usr/dt/config/xfonts/C 1>/dev/null

      if [ "$LANG" != "C" ]; then 
        $XDIR/xset fp+ /etc/dt/config/xfonts/$LANG 1>/dev/null
      fi

      if [ "$LANG" != "C" ]; then
        $XDIR/xset fp+ /usr/dt/config/xfonts/$LANG 1>/dev/null
      fi
    fi




