#!/bin/sh
#
# Copyright (C) 2007  OLPC
# Author: Bernardo Innocenti <bernie@codewiz.org>
# Author: John (J5) Palmieri <johnp@redhat.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

# provide some defaults
LANG="en_US.UTF-8"
XKB_LAYOUT="us"

# enable internationalization
[ -f "$HOME/.i18n" ] && . "$HOME/.i18n"
export LANG

# We need to stop loading of certain GTK Input Modules (d.l.o #6945)
# Normally we would load the "gtk-im-context-simple" module, but 
# some keyboards require to use Compose tables, in which case we need 
# to use the "xim" module
# In reality, the Compose tables get loaded if the locale is set 
# appropriately, so we use the LANG variable below
#if [ "$LANG" = "am_ET.UTF-8" ]; then
#  GTK_IM_MODULE="xim"
#else
#  GTK_IM_MODULE="gtk-im-context-simple"
#fi

# load keyboard settings
[ -f "/etc/sysconfig/keyboard" ] && . "/etc/sysconfig/keyboard"
[ -f "$HOME/.kbd" ] && . "$HOME/.kbd"
#export GTK_IM_MODULE

# set mouse & keyboard speed
xset m 7/4 0
xset r rate 500 30

[ -n "$XKB_OPTION" ] && XKB_OPTION=`echo "$XKB_OPTION" | sed -e 's/\b/-option /g'`

# set keyboard layout
setxkbmap \
	${XKB_MODEL:+ -model $XKB_MODEL} \
	${XKB_LAYOUT:+ -layout $XKB_LAYOUT} \
	${XKB_VARIANT:+ -variant $XKB_VARIANT} \
	$XKB_OPTION

# disable repeat on several keys
xset -r 9 -r 220  -r 67 -r 68 -r 69 -r 70 -r 71 -r 72 -r 73 -r 74 -r 79 -r \
	81 -r 87 -r 89 -r 95 -r 96 -r 224 -r 147 -r 49 -r 10 -r 11 -r 12 -r 13 -r 14 -r \
	15 -r 16 -r 17 -r 18 -r 19 -r 20 -r 21 -r 23 -r 24 -r 25 -r 26 -r 27 -r 28 -r \
	29 -r 30 -r 31 -r 32 -r 33 -r 34 -r 35 -r 36 -r 37 -r 38 -r 39 -r 40 -r 41 -r 42 -r \
	43 -r 44 -r 45 -r 46 -r 47 -r 48 -r 51 -r 52 -r 53 -r 54 -r 55 -r 56 -r 57 -r \
	58 -r 59 -r 60 -r 61 -r 62 -r 219 -r 112 -r 110 -r 117 -r 115 -r 96  -r 221 -r \
	225 -r 236 -r 217 -r 218 -r 219 -r 220 -r 221 -r 191 -r 192 -r 193 -r 222 -r \
	223 -r 224 -r 225 -r 194 -r 195 -r 196 -r 226 -r 227 -r 228 -r 229 -r 197 -r \
	198 -r 199 -r 156 -r 235

# source custom user session, if present
[ -f "$HOME/.xsession" ] && . "$HOME/.xsession"

# useful for performance work
mv $HOME/.boot_time $HOME/.boot_time.prev 2>/dev/null
cat /proc/uptime >$HOME/.boot_time

export XMODIFIERS=@im=SCIM
export GTK_IM_MODULE=xim
export USE_XOPENIM=t
scim -d


# finally, run sugar
exec /usr/bin/ck-xinit-session /usr/bin/sugar
