tails-configure-keyboard 2.02 KB
Newer Older
1 2
#!/bin/sh

3 4
set -e
set -u
5

6
# Get $XKBMODEL, $XKBLAYOUT, $XKBVARIANT and $XKBOPTIONS
7 8
. /var/lib/tails-user-session/keyboard

9
if [ -z "${XKBVARIANT:-}" ] ; then
10
	XKBCONF="$XKBLAYOUT"
11
else
12
	XKBCONF="$XKBLAYOUT+$XKBVARIANT"
13
fi
14

15 16 17 18 19 20
# Choose the keyboard layout we'll use regardless of the IBus input methods
if [ "$XKBLAYOUT" = 'us' ] ; then
    SOURCES="('xkb', '$XKBCONF')"
else
    SOURCES="('xkb', '$XKBCONF'), ('xkb', 'us')"
fi
21 22 23 24 25

# Choose preferred IBus input methods
LANGPREFIX=`echo "$LANG" | sed 's/_.*//'`
case "$LANGPREFIX" in
   ja)
26 27
      PRELOAD="['mozc-jp', 'libpinyin', 'hangul', 'Unikey', 'chewing']"
      SOURCES="[$SOURCES, ('ibus', 'mozc-jp'), ('ibus', 'libpinyin'), ('ibus', 'chewing'), ('ibus', 'hangul'), ('ibus', 'Unikey')]"
28 29
      ;;
   ko)
30 31
      PRELOAD="['hangul', 'libpinyin', 'mozc-jp', 'Unikey', 'chewing']"
      SOURCES="[$SOURCES, ('ibus', 'hangul'), ('ibus', 'libpinyin'), ('ibus', 'chewing'), ('ibus', 'mozc-jp'), ('ibus', 'Unikey')]"
32 33
      ;;
   vi)
34 35
      PRELOAD="['Unikey', 'hangul', 'libpinyin', 'mozc-jp', 'chewing']"
      SOURCES="[$SOURCES, ('ibus', 'Unikey'), ('ibus', 'hangul'), ('ibus', 'libpinyin'), ('ibus', 'chewing'), ('ibus', 'mozc-jp')]"
36 37
      ;;
   zh)
38 39
      PRELOAD="['libpinyin', 'chewing', 'mozc-jp', 'hangul', 'Unikey']"
      SOURCES="[$SOURCES, ('ibus', 'libpinyin'), ('ibus', 'chewing'), ('ibus', 'mozc-jp'), ('ibus', 'hangul'), ('ibus', 'Unikey')]"
40 41
      ;;
   *)
42 43
      PRELOAD="['libpinyin', 'mozc-jp', 'hangul', 'Unikey', 'chewing']"
      SOURCES="[$SOURCES, ('ibus', 'libpinyin'), ('ibus', 'mozc-jp'), ('ibus', 'hangul'), ('ibus', 'Unikey'), ('ibus', 'chewing')]"
44 45 46 47 48 49
      ;;
esac

# Configure enabled input methods and their preferred order
dconf write /desktop/ibus/general/preload-engines "$PRELOAD"
dconf write /org/gnome/desktop/input-sources/sources "$SOURCES"
50
if [ -n "${XKBOPTIONS:-}" ] ; then
51 52
    dconf write /org/gnome/desktop/input-sources/xkb-options "$XKBOPTIONS"
fi
53 54 55 56 57

# Export environment variables to enable use of IBus
export GTK_IM_MODULE='ibus'
export QT_IM_MODULE='ibus'
export XMODIFIERS='@im=ibus'