#!/bin/bash

if [ -f "$GDM_XIM" ]; then
	source "$GDM_XIM"
	if [ -f "/etc/X11/xinit/xinitrc.d/xinput" ]; then
		export XIM_PROGRAM="none"
		export XIM="none"
	fi

	$IM_EXEC &

	# wait until IM is ready
	unset IM_PROC
	if echo "$IM_EXEC" | grep -q "httx" ; then
		# ATOKX
		IM_PROC="LookupAux"
		# SKK
		if echo "$IM_EXEC" | grep -q "skk" ; then
			IM_PROC="PaletteAux"
		fi
		if echo "$IM_EXEC" | grep -q "canna" ; then
			IM_PROC="PaletteAux"
		fi
	fi
	if [ "$IM_PROC" != "" ]; then
		times=0
		until ps xc | grep -q "$IM_PROC" ; do
			# timeout in 30sec
			if [ $times -ge 30 ]; then break ; fi
			times=$[$times+1]
			sleep 1
		done
		sleep 1
		unset times
	fi
fi
