summaryrefslogtreecommitdiffstats
path: root/config/chroot_local-includes/usr/local/lib/tails-configure-keyboard
blob: 4ae9639494a66fcdbc4aa985b82d2dd7568c6609 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/sh

set -e
set -u

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

if [ -z "${XKBVARIANT:-}" ] ; then
	XKBCONF="$XKBLAYOUT"
else
	XKBCONF="$XKBLAYOUT+$XKBVARIANT"
fi

# 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

# Choose preferred IBus input methods
LANGPREFIX=`echo "$LANG" | sed 's/_.*//'`
case "$LANGPREFIX" in
   ja)
      PRELOAD="['anthy', 'pinyin', 'hangul', 'Unikey', 'bopomofo']"
      SOURCES="[$SOURCES, ('ibus', 'anthy'), ('ibus', 'pinyin'), ('ibus', 'hangul'), ('ibus', 'Unikey'), ('ibus', 'bopomofo')]"
      NEEDIBUS='y'
      ;;
   ko)
      PRELOAD="['hangul', 'pinyin', 'anthy', 'Unikey', 'bopomofo']"
      SOURCES="[$SOURCES, ('ibus', 'hangul'), ('ibus', 'pinyin'), ('ibus', 'anthy'), ('ibus', 'Unikey'), ('ibus', 'bopomofo')]"
      NEEDIBUS='y'
      ;;
   vi)
      PRELOAD="['Unikey', 'hangul', 'pinyin', 'anthy', 'bopomofo']"
      SOURCES="[$SOURCES, ('ibus', 'Unikey'), ('ibus', 'hangul'), ('ibus', 'pinyin'), ('ibus', 'anthy'), ('ibus', 'bopomofo')]"
      NEEDIBUS='y'
      ;;
   zh)
      PRELOAD="['pinyin', 'bopomofo', 'anthy', 'hangul', 'Unikey']"
      SOURCES="[$SOURCES, ('ibus', 'pinyin'), ('ibus', 'bopomofo'), ('ibus', 'anthy'), ('ibus', 'hangul'), ('ibus', 'Unikey')]"
      NEEDIBUS='y'
      ;;
   *)
      PRELOAD="['pinyin', 'anthy', 'hangul', 'Unikey', 'bopomofo']"
      SOURCES="[$SOURCES, ('ibus', 'pinyin'), ('ibus', 'anthy'), ('ibus', 'hangul'), ('ibus', 'Unikey'), ('ibus', 'bopomofo')]"
      NEEDIBUS='n'
      ;;
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"
if [ -n "${XKBOPTIONS:-}" ] ; then
    dconf write /org/gnome/desktop/input-sources/xkb-options "$XKBOPTIONS"
fi

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