summaryrefslogtreecommitdiffstats
path: root/local/bin/input_control.sh
blob: 05bc1cb7175a9d60172aad68aabbdd8868e386c9 (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/bash

# Use either X keyboard extension layouts (setxkbmap), or fcitx (or both).
#
# At first I configured this to use setxkbmap, it works fine.
# 
# fcitx already provides keybindings, but I wanted to display 
# the current input method in dwmblocks immediatly.  So I'm
# adding such support through fcitx5-remote.

signal=20

# signal dwmblocks to update block
send_signal() {
    pkill -RTMIN+$signal dwmblocks
}

# Cycle X keyboard extension layouts
cycle_layouts() {
    layouts=(us latam)              # X keyboard extension
    STATE_FILE="$XDG_STATE_HOME/keyboard_layout_state"

    if [ -f "$STATE_FILE" ]; then
        index=$(cat "$STATE_FILE")
    else
        index=0
    fi
    next_index=$(( (index + 1) % ${#layouts[@]} ))
    echo $next_index > "$STATE_FILE"

    setxkbmap ${layouts[$index]}
}

fcitx_control() {
    # For this to correctly reflect the state of the system "Share Input State"
    # should be set to "All" in fcitx5-configtool.

    case $1 in
        en)
            fcitx5-remote -g Default
            fcitx5-remote -c    # Closed
            ;;
        es)
            fcitx5-remote -g Spanish
            fcitx5-remote -c    # Closed
            ;;
        ja) 
            fcitx5-remote -g Default
            fcitx5-remote -o    # Open
            ;;
        *)
            fcitx5-remote -q    # 
            fcitx5-remote -n
            fcitx5-remote
            ;;
    esac
}

#cycle_layouts
fcitx_control $1

send_signal