(scripts/i3) keyboard layout layout switcher for i3 mostly working
This commit is contained in:
@@ -106,7 +106,6 @@ source_list+=("${personal_scripts}/navigate_bash_setup.sh")
|
||||
source_list+=("${personal_scripts}/fzf-bash-history.sh")
|
||||
source_list+=("${personal_scripts}/colors.sh")
|
||||
source_list+=("${personal_scripts}/dunst.sh")
|
||||
source_list+=("${personal_scripts}/i3-kb-layout-switcher.sh")
|
||||
source_list+=("$HOME/.cargo/env")
|
||||
|
||||
for script in ${source_list[@]}; do
|
||||
|
||||
@@ -77,6 +77,9 @@ bindsym $mod+Shift+v exec pkill picom
|
||||
bindsym $mod+d exec --no-startup-id rofi -show combi
|
||||
bindsym $mod+Shift+d exec --no-startup-id rofi -show run
|
||||
|
||||
# start keyboard layout selector
|
||||
bindsym $mod+m exec --no-startup-id i3-kb-layout-switcher.sh
|
||||
|
||||
# start a terminal
|
||||
bindsym $mod+Return exec ghostty
|
||||
bindsym $mod+t exec ghostty -e tmux attach
|
||||
|
||||
68
scripts/i3-kb-layout-switcher.sh
Normal file → Executable file
68
scripts/i3-kb-layout-switcher.sh
Normal file → Executable file
@@ -1,49 +1,55 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
function switch_kb_layout {
|
||||
layouts=("us", "us")
|
||||
variants=("default, intl")
|
||||
languages="$(echo "${devices}" | grep -ioP '(?<="layout": ").*(?=")' -m 1)"
|
||||
variants="$(echo "${devices}" | grep -ioP '(?<="variant": ").*(?=")' -m 1)"
|
||||
layouts=("us" "us" "ch")
|
||||
variants=("" "intl" "")
|
||||
lines=${#layouts[@]}
|
||||
number=0
|
||||
selection=-1
|
||||
|
||||
## TODO: use `setxkbmap -print` to get status
|
||||
current="$(echo "${devices}" | grep -ioP '(?<="active_layout_index": ).*(?=,)' -m 1)"
|
||||
if [[ ${#layouts[@]} -ne ${#variants[@]} ]]; then
|
||||
notify-send "layout-switcher" "#layouts != #variants"
|
||||
return 1
|
||||
fi
|
||||
|
||||
languages=(${languages})
|
||||
variants=(${variants})
|
||||
|
||||
number=$((${#languages[@]} - 1))
|
||||
for n in $(seq 0 $number); do
|
||||
layouts+=("${languages[$n]//,/} - ${variants[$n]//,/}")
|
||||
unset names
|
||||
for n in ${!layouts[@]}; do
|
||||
if [[ -n "${variants[$n]}" ]]; then
|
||||
names+=("${layouts[$n]}:${variants[$n]}")
|
||||
else
|
||||
names+=("${layouts[$n]}")
|
||||
fi
|
||||
done
|
||||
|
||||
# ## TODO: use `setxkbmap -print` to get status
|
||||
# current="$(echo "${devices}" | grep -ioP '(?<="active_layout_index": ).*(?=,)' -m 1)"
|
||||
|
||||
if $(which rofi &>/dev/null); then
|
||||
# selection="$(printf "%s\n" "${layouts[@]}" | fuzzel --lines ${#layouts[@]} --dmenu --select-index ${current})"
|
||||
return 1
|
||||
selection="$(printf "%s\n" "${names[@]}" | rofi -dmenu -format 'i' -fixed-num-lines ${lines} -selected-row ${number} -case-smart)"
|
||||
else
|
||||
notify-send "layout-switcher" "requires [rofi]"
|
||||
return 1
|
||||
fi
|
||||
|
||||
for n in $(seq 0 $number); do
|
||||
if [[ "${layouts[$n]}" == "${selection}" ]]; then
|
||||
index=$n
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [[ -z "${index}" ]]; then
|
||||
if [[ -z "$selection" ]]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [[ $selection -lt 0 || $selection -ge $lines ]]; then
|
||||
notify-send "layout-switcher" "invalid selection"
|
||||
return 1
|
||||
fi
|
||||
|
||||
hyprctl switchxkblayout all "${index}" >/dev/null
|
||||
# if [[ $selection -ge $lines ]]; then
|
||||
# notify-send "layout-switcher" "invalid selection"
|
||||
# return 1
|
||||
# fi
|
||||
#
|
||||
if [[ -n "${variants[$selection]}" ]]; then
|
||||
setxkbmap -layout "${layouts[$selection]}" -variant "${variants[$selection]}"
|
||||
else
|
||||
setxkbmap -layout "${layouts[$selection]}"
|
||||
fi
|
||||
}
|
||||
|
||||
# switch_kb_layout
|
||||
|
||||
function choose_layout_us {
|
||||
setxkbmap -layout us
|
||||
}
|
||||
|
||||
function choose_layout_int {
|
||||
setxkbmap -layout us -variant intl
|
||||
}
|
||||
switch_kb_layout
|
||||
|
||||
Reference in New Issue
Block a user