diff options
| author | Mitsuo Tokumori <rtokumori@pucp.edu.pe> | 2023-11-25 15:50:08 -0500 |
|---|---|---|
| committer | Mitsuo Tokumori <rtokumori@pucp.edu.pe> | 2023-11-25 15:50:56 -0500 |
| commit | c285ddd9d16f0038da0c036882eef7be75e2aae0 (patch) | |
| tree | 7c4b75f275c2bf63dea6d5691051ea6e973def4c /local/bin/input_control.sh | |
| parent | 6778640f84cce092f425ad4ab9a1ec310a08f6d2 (diff) | |
Add helper scripts for dwmblocks
Diffstat (limited to 'local/bin/input_control.sh')
| -rwxr-xr-x | local/bin/input_control.sh | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/local/bin/input_control.sh b/local/bin/input_control.sh new file mode 100755 index 0000000..05bc1cb --- /dev/null +++ b/local/bin/input_control.sh @@ -0,0 +1,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 |
