#!/bin/ksh
###  Product:           @(#)Common Desktop Environment 1.0          
#####################################################################
###  File:              0050.dtxmodmap
###
###  Default Location:  /usr/dt/config/Xsession.d/
###
###  Purpose:           Perform keyboard mapping
###                     
###  Description:
###                     This script is invoked by means of the Xsession file
###                     at user login. It invokes xmodmap to setup the
###                     keyboard mapping required for selected locales.
###                     If XKB is in use, then the Xserver has already
###                     mapped the keyboard, so skip this.
###
###  Invoked by:        /usr/dt/bin/Xsession
###
###  Product:           @(#)Common Desktop Environment 1.0          
###
###  Note:              
###
###    The /usr/dt/config/Xsession.d/0050.dtxmodmap file is a
###    factory-default file and will be unconditionally overwritten upon
###    subsequent installation. To customize keyboard mapping
###    behavior, copy this file to the configuration directory,
###    /etc/dt/config/Xsession.d and customize that version
###    of the file.
###    
###  Revision:          $Revision: 1.1 $
###
###  (c) Copyright 1993, 1994 Hewlett-Packard Company
###  (c) Copyright 1993, 2010 International Business Machines Corp.
###  (c) Copyright 1993, 1994 Sun Microsystems, Inc.
###  (c) Copyright 1993, 1994 Unix System Labs, Inc., a subsidiary of
###      Novell, Inc.
###
#####################################################################

################################################################
# Look to see if the X property _XKB_RULES_NAMES exists.
# If it does, the X server has already set the keyboard mapping.
################################################################
/usr/bin/X11/xprop -root | /usr/bin/grep -q "_XKB_RULES_NAMES"
if [ "$?" = "0" ]
then
    return
fi

#
#  Determine the xmodmap keyboard to be used.
#

Cname=C

if [ ${DISPLAY%.*} = ":0" ]
then

    KBD=""
    XDIR=/usr/lpp/X11/defaults/xmodmap

    LONG_KBD_LANG=`/usr/lpp/X11/bin/querykbd`
    KBD_LANG=`/usr/lpp/X11/bin/querykbd | cut -f1 -d'.'`

    if [ "$KBD_LANG" = "NULL" ]
    then
        dspmsg $XINITRCMSG/xinit.cat 2 'xinit: Odm keyboard id is NULL.\n'
    else
        if [ "$KBD_LANG" != "$Cname" ]
        then
            if [ -r $IMKEYMAPPATH/$KBD_LANG/keyboard ]
            then
                KBD=$IMKEYMAPPATH/$KBD_LANG/keyboard
            else
                if [ "$IMKEYMAPPATH" = "/usr/lib/nls/im.alt" ]
                then
                    if [ "$sys_version" = "3"  /
                             -a -r $XDIR/$KBD_LANG/keyboard.alt ]
                    then
                        KBD=$XDIR/$KBD_LANG/keyboard.alt 
                    else 
                        if [ -r $XDIR/${KBD_LANG}@alt/keyboard ]
                        then
                            KBD=$XDIR/${KBD_LANG}@alt/keyboard
                        fi
                    fi
                fi
                if [ "$KBD" = "" ]
                then
                    if [ -r $XDIR/$LONG_KBD_LANG/keyboard ]
                    then
                        KBD=$XDIR/$LONG_KBD_LANG/keyboard
                    else
                        if [ -r $XDIR/$KBD_LANG/keyboard ]
                        then
                            KBD=$XDIR/$KBD_LANG/keyboard
			fi
                    fi
                fi
            fi
        fi
    fi
    if [ "$KBD" != "" ]
    then
        xmodmap $KBD
    else
	if [ "$IMKEYMAPPATH" = "/usr/lib/nls/im.alt" ]
	then
	    if [ "$sys_version" = "3"  /
		     -a -r $XDIR/$KBD_LANG/keyboard.alt ]
	    then
		xmodmap $XDIR/$KBD_LANG/keyboard.alt 
		exit
	    fi
  	    if [ -r $XDIR/${KBD_LANG}@alt/keyboard ]
	    then
	        xmodmap $XDIR/${KBD_LANG}@alt/keyboard
		exit
	    fi
        fi
        if [ -r $XDIR/$LANG/keyboard ]
        then
            xmodmap $XDIR/$LANG/keyboard
        fi
    fi
fi

##########################         eof       #####################
