-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfcitx5.tmux.in
119 lines (110 loc) · 4.04 KB
/
fcitx5.tmux.in
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/env bash
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
fcitx5_interpolation="\#{fcitx5}"
set_tmux_option() {
local option=$1
local value=$2
tmux set-option -gq "$option" "$value"
}
get_tmux_option() {
local option
local default_value
local option_value
option="$1"
default_value="$2"
option_value="$(tmux show-option -qv "$option")"
if [ -z "$option_value" ]; then
option_value="$(tmux show-option -gqv "$option")"
fi
if [ -z "$option_value" ]; then
echo "$default_value"
else
echo "$option_value"
fi
}
do_interpolation() {
local all_interpolated="$1"
value=$(get_tmux_option "@fcitx5")
all_interpolated=${all_interpolated//${fcitx5_interpolation}/${value}}
echo "$all_interpolated"
}
update_tmux_option() {
local option
local option_value
local new_option_value
option=$1
option_value=$(get_tmux_option "$option")
new_option_value=$(do_interpolation "$option_value")
set_tmux_option "$option" "$new_option_value"
}
to_ascii() {
LC_CTYPE=C printf "%d" "'$1'"
}
main() {
pid=$(tmux display-message -pF '#{pid}')
tmux run -b "@CMAKE_INSTALL_FULL_LIBEXECDIR@/fcitx5-tmux $pid"
declare -A KEYS=(
[F1]=0xffbe
[F2]=0xffbf
[F3]=0xffc0
[F4]=0xffc1
[F5]=0xffc2
[F6]=0xffc3
[F7]=0xffc4
[F8]=0xffc5
[F9]=0xffc6
[F10]=0xffc7
[F11]=0xffc8
[F12]=0xffc9
[Insert]=0xff63
[Delete]=0xffff
[Home]=0xff50
[End]=0xff57
[PageDown]=0xff56
[PageUp]=0xff55
[Tab]=0xff09
[Space]=0x0020
[BSpace]=0xff08
[Enter]=0xff0d
[Escape]=0xff1b
[Up]=0xff52
[Down]=0xff54
[Left]=0xff51
[Right]=0xff53
[KP/]=0xffaf
[KP*]=0xffaa
[KP-]=0xffad
[KP7]=0xffb7
[KP8]=0xffb8
[KP9]=0xffb9
[KP+]=0xffab
[KP4]=0xffb4
[KP5]=0xffb5
[KP6]=0xffb6
[KP1]=0xffb1
[KP2]=0xffb2
[KP3]=0xffb3
[KPEnter]=0xff8d
[KP0]=0xffb0
[KP.]=0xffae
)
for KEY in a b c d e f g h i j k l m n o p q r s t u v w x y z 1 2 3 4 5 6 7 8 9 0 , . / "\\;" "'" "[" "]" "-" "=" "!" "@" "#" "^" "(" ")" "_" "+"; do
VALUE=$(to_ascii "$KEY")
tmux bind-key -n "$KEY" run "dbus-send --print-reply=literal --dest=org.fcitx.Fcitx5.Tmux-$pid /tmux org.fcitx.Fcitx.TmuxProxy.ProcessKeyEvent uint32:$VALUE uint32:0"
tmux bind-key -n "C-$KEY" run "dbus-send --print-reply=literal --dest=org.fcitx.Fcitx5.Tmux-$pid /tmux org.fcitx.Fcitx.TmuxProxy.ProcessKeyEvent uint32:$VALUE uint32:4"
tmux bind-key -n "M-$KEY" run "dbus-send --print-reply=literal --dest=org.fcitx.Fcitx5.Tmux-$pid /tmux org.fcitx.Fcitx.TmuxProxy.ProcessKeyEvent uint32:$VALUE uint32:8"
tmux bind-key -n "M-C-$KEY" run "dbus-send --print-reply=literal --dest=org.fcitx.Fcitx5.Tmux-$pid /tmux org.fcitx.Fcitx.TmuxProxy.ProcessKeyEvent uint32:$VALUE uint32:12"
done
for KEY in A B C D E F G H I J K L M N O P Q R S T U V W X Y Z "\"" "$" "%" "*" "&"; do
VALUE=$(to_ascii "$KEY")
tmux bind-key -n "$KEY" run "dbus-send --print-reply=literal --dest=org.fcitx.Fcitx5.Tmux-$pid /tmux org.fcitx.Fcitx.TmuxProxy.ProcessKeyEvent uint32:$VALUE uint32:0"
done
for KEY in "${!KEYS[@]}"; do
VALUE=${KEYS[$KEY]}
tmux bind-key -n ${KEY} run "dbus-send --print-reply=literal --dest=org.fcitx.Fcitx5.Tmux-$pid /tmux org.fcitx.Fcitx.TmuxProxy.ProcessKeyEvent uint32:$VALUE uint32:0"
tmux bind-key -n C-${KEY} run "dbus-send --print-reply=literal --dest=org.fcitx.Fcitx5.Tmux-$pid /tmux org.fcitx.Fcitx.TmuxProxy.ProcessKeyEvent uint32:$VALUE uint32:4"
tmux bind-key -n M-${KEY} run "dbus-send --print-reply=literal --dest=org.fcitx.Fcitx5.Tmux-$pid /tmux org.fcitx.Fcitx.TmuxProxy.ProcessKeyEvent uint32:$VALUE uint32:8"
tmux bind-key -n M-C-${KEY} run "dbus-send --print-reply=literal --dest=org.fcitx.Fcitx5.Tmux-$pid /tmux org.fcitx.Fcitx.TmuxProxy.ProcessKeyEvent uint32:$VALUE uint32:12"
done
}
main