2015-08-10 16:30:25 +02:00
|
|
|
#!/bin/bash
|
2007-01-10 23:48:32 +01:00
|
|
|
#
|
|
|
|
# $Id: xim,v 1.28 2004/12/07 11:04:59 mfabian Exp $
|
|
|
|
#
|
|
|
|
# Copyright © 2001 SUSE LINUX GmbH Nuernberg, Germany
|
|
|
|
#
|
2007-03-01 20:58:07 +01:00
|
|
|
# Mike Fabian <mfabian@suse.de>, 2000, 2001, 2002, 2004, 2005, 2006, 2007
|
|
|
|
# Werner Fink <werner@suse.de>, 2007
|
2007-01-10 23:48:32 +01:00
|
|
|
#
|
|
|
|
# This program comes with ABSOLUTELY NO WARRANTY; it may be copied or modified
|
|
|
|
# under the terms of the GNU General Public License version 2 as published by
|
|
|
|
# the Free Software Foundation.
|
|
|
|
|
|
|
|
|
2020-09-29 07:58:41 +02:00
|
|
|
# usually, {/usr,}/etc/X11/xim is used to start a default input method.
|
2007-01-10 23:48:32 +01:00
|
|
|
|
|
|
|
# If want to change the default, you have the following options:
|
|
|
|
#
|
|
|
|
# 1) Set the variable INPUT_METHOD in /etc/sysconfig/language.
|
|
|
|
# For example:
|
|
|
|
# INPUT_METHOD="scim"
|
|
|
|
# This changes the default for all users
|
2015-06-23 15:28:13 +02:00
|
|
|
# 2) set and export the variable "INPUT_METHOD" in ~/.i18n in the
|
|
|
|
# home directory of a user.
|
|
|
|
# For example:
|
2007-01-10 23:48:32 +01:00
|
|
|
# export INPUT_METHOD="scim"
|
|
|
|
# This changes the default only for one user.
|
|
|
|
#
|
|
|
|
# The possible values for the variable INPUT_METHOD are the names
|
2020-09-29 07:58:41 +02:00
|
|
|
# of the scripts which exist in the directory {/usr,}/etc/X11/xim.d/
|
|
|
|
# for example if a script {/usr,}/etc/X11/xim.d/scim exists,
|
2007-01-10 23:48:32 +01:00
|
|
|
# and INPUT_METHOD is set to "scim", this script will be tried first
|
|
|
|
# to start an input method and only if this fails other input methods
|
|
|
|
# will be tried.
|
|
|
|
#
|
|
|
|
# 3) If you don't like the behaviour of any of the available
|
2020-09-29 07:58:41 +02:00
|
|
|
# scripts in {/usr,}/etc/X11/xim.d, you can write your own script
|
2007-01-10 23:48:32 +01:00
|
|
|
# containing the necessary lines to start your preferred input
|
|
|
|
# method and save it as ~/.xim. If a file ~/.xim exists, only
|
|
|
|
# this file is sourced to start an input method and nothing
|
|
|
|
# else.
|
|
|
|
# Usually you need only a few lines, the systemwide
|
2020-09-29 07:58:41 +02:00
|
|
|
# file to start an input method, {/usr,}/etc/X11/xim, is only so
|
2007-01-10 23:48:32 +01:00
|
|
|
# complicated because it tries to find a nice default depending
|
|
|
|
# on the language and the installed input methods.
|
|
|
|
#
|
|
|
|
# For example, if you want to use "scim" as your input method,
|
|
|
|
# it is enough to have the following 5 lines (and nothing else)
|
|
|
|
# in your ~/.xim file:
|
|
|
|
|
|
|
|
# export XMODIFIERS="@im=SCIM"
|
|
|
|
# export GTK_IM_MODULE=scim
|
|
|
|
# export QT_IM_SWITCHER=imsw-multi
|
|
|
|
# export QT_IM_MODULE=scim
|
|
|
|
# scim -d
|
|
|
|
|
2020-09-29 07:58:41 +02:00
|
|
|
echo "$0: Checking whether an input method should be started."
|
2007-01-10 23:48:32 +01:00
|
|
|
|
2007-03-01 20:58:07 +01:00
|
|
|
#
|
|
|
|
# Get variables from the user environment which might influence the start
|
|
|
|
# of an input method (see bug #235044, written by Werner Fink <werner@suse.de>):
|
|
|
|
#
|
|
|
|
|
|
|
|
adduserenv () {
|
|
|
|
local cur var=${1+"$@"}
|
2018-11-06 12:49:16 +01:00
|
|
|
: ${HOSTNAME:=$(hostname)}
|
2015-06-23 15:28:13 +02:00
|
|
|
# Use ~/.i18n
|
2015-06-24 09:30:30 +02:00
|
|
|
if test -e "$HOME/.i18n"; then
|
2020-09-29 07:58:41 +02:00
|
|
|
echo "$0: Checking whether an input method is specified in $HOME/.i18n."
|
2015-06-23 15:28:13 +02:00
|
|
|
eval $(set +u +e
|
2020-09-29 07:58:41 +02:00
|
|
|
if [ -r /etc/profile.d/lang.sh ]; then
|
|
|
|
. /etc/profile.d/lang.sh < /dev/null > /dev/null 2>&1
|
|
|
|
elif [ -r /usr/etc/profile.d/lang.sh ]; then
|
|
|
|
. /usr/etc/profile.d/lang.sh < /dev/null > /dev/null 2>&1
|
|
|
|
fi
|
2015-06-23 15:28:13 +02:00
|
|
|
for cur in $var; do
|
2015-08-20 07:27:11 +02:00
|
|
|
test -n "${!cur}" && echo export $cur=${!cur}
|
2015-06-23 15:28:13 +02:00
|
|
|
done)
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
# Fall back to ~/.profile or ~/.login
|
2009-04-02 18:55:24 +02:00
|
|
|
case "$SHELL" in
|
2015-06-23 15:28:13 +02:00
|
|
|
*/sh|*/ash|*/bash|*/ksh|*/mksh|*/pdksh|*/zsh)
|
2009-04-02 18:55:24 +02:00
|
|
|
if test -s "$HOME/.profile" ; then
|
2020-09-29 07:58:41 +02:00
|
|
|
echo "$0: Checking whether an input method is specified in $HOME/.profile."
|
2013-05-24 14:57:26 +02:00
|
|
|
eval $(export HOSTNAME
|
2015-06-23 15:28:13 +02:00
|
|
|
(echo . "'$HOME/.profile' < /dev/null > /dev/null 2>&1"
|
2009-04-02 18:55:24 +02:00
|
|
|
echo "set +u +e"
|
|
|
|
for cur in $var; do
|
2015-06-24 09:30:30 +02:00
|
|
|
echo echo \${$cur+"$cur=\$$cur;"}
|
|
|
|
done
|
|
|
|
echo echo export $var) | $SHELL)
|
2009-04-02 18:55:24 +02:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
*/csh|*/tcsh)
|
|
|
|
if test -s "$HOME/.login" ; then
|
2020-09-29 07:58:41 +02:00
|
|
|
echo "$0: Checking whether an input method is specified in $HOME/.login."
|
2013-05-24 14:57:26 +02:00
|
|
|
eval $(export HOSTNAME
|
|
|
|
(echo onintr -
|
2015-06-23 15:28:13 +02:00
|
|
|
echo source "'$HOME/.login' < /dev/null >& /dev/null"
|
2009-04-02 18:55:24 +02:00
|
|
|
echo unset verbose
|
|
|
|
for cur in $var; do
|
2015-06-24 09:30:30 +02:00
|
|
|
echo if \( \${?$cur} \) echo $cur=\`printenv $cur\`
|
|
|
|
done
|
|
|
|
echo echo export $var) | $SHELL)
|
2009-04-02 18:55:24 +02:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
2007-03-01 20:58:07 +01:00
|
|
|
}
|
|
|
|
|
2013-12-10 18:09:54 +01:00
|
|
|
# workaround for bnc#853063
|
|
|
|
# activate/deactivate g-s-d keyboard plugin depending on IM
|
|
|
|
gnome_ibus_workaround () {
|
|
|
|
local im=$1
|
|
|
|
im=${im##*/}
|
|
|
|
im=${im#[0-9][0-9]-}
|
|
|
|
test "$im" = "none" && return
|
2014-08-23 10:33:00 +02:00
|
|
|
windowmanager=${WINDOWMANAGER##*/}
|
|
|
|
windowmanager=${windowmanager%-*}
|
|
|
|
if [ "$windowmanager" = "gnome" ]; then
|
2013-12-10 18:09:54 +01:00
|
|
|
local active
|
|
|
|
if [ "$im" = "ibus" ]; then
|
|
|
|
active=true
|
|
|
|
else
|
|
|
|
active=false
|
|
|
|
fi
|
|
|
|
gsettings set org.gnome.settings-daemon.plugins.keyboard active $active
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2008-11-04 17:58:59 +01:00
|
|
|
# if gdm passes the language to Xsession, we should not override this
|
|
|
|
# see http://bugzilla.novell.com/show_bug.cgi?id=440371
|
|
|
|
# The test for $GDM_LANG needs to be changed slightly as soon as other
|
|
|
|
# displaymanager also pass a second argument to Xsession.
|
|
|
|
if test -n "$GDM_LANG" ; then
|
2020-09-29 07:58:41 +02:00
|
|
|
echo "$0: use GDM_LANG=$GDM_LANG"
|
2008-11-04 17:58:59 +01:00
|
|
|
adduserenv INPUT_METHOD
|
|
|
|
else
|
|
|
|
adduserenv LANG LC_CTYPE LC_ALL INPUT_METHOD
|
|
|
|
fi
|
2007-03-01 20:58:07 +01:00
|
|
|
|
2015-06-23 15:28:13 +02:00
|
|
|
# if INPUT_METHOD is already set to something non-empty here, the user should
|
|
|
|
# set it in ~/.i18n or in ~/.profile or ~/.login or on the command line before
|
|
|
|
# using startx. In that case, don't read the system wide default from
|
|
|
|
# /etc/sysconfig/language, use the user supplied value instead:
|
2014-11-05 18:14:06 +01:00
|
|
|
if [ -z "$INPUT_METHOD" ] ; then
|
2007-03-01 20:58:07 +01:00
|
|
|
echo "sourcing /etc/sysconfig/language to get the value of INPUT_METHOD"
|
2014-11-05 18:14:06 +01:00
|
|
|
. /etc/sysconfig/language
|
2007-01-10 23:48:32 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$INPUT_METHOD" != "" ]; then
|
|
|
|
echo "INPUT_METHOD is set to $INPUT_METHOD."
|
|
|
|
echo "Trying to start this user selected input method first ..."
|
|
|
|
if [ -r "/etc/X11/xim.d/$INPUT_METHOD" ] ; then
|
|
|
|
echo "sourcing /etc/X11/xim.d/$INPUT_METHOD"
|
2014-11-05 18:14:06 +01:00
|
|
|
. /etc/X11/xim.d/$INPUT_METHOD
|
|
|
|
if [ "$?" = "0" ]; then
|
2007-01-10 23:48:32 +01:00
|
|
|
echo "Start of $INPUT_METHOD succeeded."
|
2013-12-10 18:09:54 +01:00
|
|
|
gnome_ibus_workaround $INPUT_METHOD
|
2007-01-10 23:48:32 +01:00
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
echo "Start of $INPUT_METHOD failed."
|
|
|
|
fi
|
2020-09-29 07:58:41 +02:00
|
|
|
elif [ -r "/usr/etc/X11/xim.d/$INPUT_METHOD" ] ; then
|
|
|
|
echo "sourcing /usr/etc/X11/xim.d/$INPUT_METHOD"
|
|
|
|
. /usr/etc/X11/xim.d/$INPUT_METHOD
|
|
|
|
if [ "$?" = "0" ]; then
|
|
|
|
echo "Start of $INPUT_METHOD succeeded."
|
|
|
|
gnome_ibus_workaround $INPUT_METHOD
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
echo "Start of $INPUT_METHOD failed."
|
|
|
|
fi
|
2007-01-10 23:48:32 +01:00
|
|
|
else
|
2020-09-29 07:58:41 +02:00
|
|
|
echo "{/usr,}/etc/X11/xim.d/$INPUT_METHOD does not exist."
|
2007-01-10 23:48:32 +01:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "INPUT_METHOD is not set or empty (no user selected input method)."
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Determine the LC_CTYPE locale category setting
|
|
|
|
tmplang=${LC_ALL-${LC_CTYPE-${LANG-en_US}}}
|
|
|
|
|
|
|
|
echo "Trying to start a default input method for the locale $tmplang ..."
|
|
|
|
|
|
|
|
subdirlist=$tmplang
|
2015-08-10 10:08:44 +02:00
|
|
|
while [ "$tmplang" != "${tmplang%[_.@]*}" ]
|
2007-01-10 23:48:32 +01:00
|
|
|
do
|
|
|
|
tmplang=${tmplang%[_.@]*}
|
|
|
|
subdirlist="$subdirlist $tmplang"
|
|
|
|
done
|
|
|
|
|
|
|
|
im_failed=0
|
|
|
|
|
|
|
|
for subdir in $subdirlist ; do
|
|
|
|
if [ -d /etc/X11/xim.d/$subdir ] ; then
|
|
|
|
echo "Checking for a default input method in /etc/X11/xim.d/$subdir/"
|
|
|
|
for im in /etc/X11/xim.d/$subdir/* ; do
|
|
|
|
if [ -r $im ] ; then
|
|
|
|
echo "sourcing $im ..."
|
2014-11-05 18:14:06 +01:00
|
|
|
. $im
|
|
|
|
if [ "$?" = "0" ]; then
|
2007-01-10 23:48:32 +01:00
|
|
|
echo "$im started sucessfully"
|
2013-12-10 18:09:54 +01:00
|
|
|
gnome_ibus_workaround $im
|
2007-01-10 23:48:32 +01:00
|
|
|
return 0
|
|
|
|
else
|
|
|
|
echo "$im failed"
|
|
|
|
im_failed=1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2020-09-29 07:58:41 +02:00
|
|
|
for subdir in $subdirlist ; do
|
|
|
|
if [ -d /usr/etc/X11/xim.d/$subdir ] ; then
|
|
|
|
echo "Checking for a default input method in /usr/etc/X11/xim.d/$subdir/"
|
|
|
|
for im in /usr/etc/X11/xim.d/$subdir/* ; do
|
|
|
|
if [ -r $im ] ; then
|
|
|
|
echo "sourcing $im ..."
|
|
|
|
. $im
|
|
|
|
if [ "$?" = "0" ]; then
|
|
|
|
echo "$im started sucessfully"
|
|
|
|
gnome_ibus_workaround $im
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
echo "$im failed"
|
|
|
|
im_failed=1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
|
2014-11-05 18:14:06 +01:00
|
|
|
if [ "$im_failed" = 0 ] ; then
|
2007-01-10 23:48:32 +01:00
|
|
|
echo "There is no default input method for the current locale."
|
|
|
|
else
|
|
|
|
echo "All default input methods tried for the current locale failed."
|
|
|
|
fi
|
|
|
|
|
2008-11-18 14:29:43 +01:00
|
|
|
# If there is no default input method for the current locale, source
|
|
|
|
# the dummy input method "none" to get reasonable default settings
|
|
|
|
# of the relevant environment variables:
|
|
|
|
|
2020-09-29 07:58:41 +02:00
|
|
|
if [ -r /etc/X11/xim.d/none ]; then
|
|
|
|
. /etc/X11/xim.d/none
|
|
|
|
elif [ -r /usr/etc/X11/xim.d/none ]; then
|
|
|
|
. /usr/etc/X11/xim.d/none
|
|
|
|
fi
|
|
|
|
|