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