(scripts) fixed initial selection of i3 layout switcher
This commit is contained in:
@@ -4,7 +4,7 @@ function switch_kb_layout {
|
|||||||
layouts=("us" "us" "ch")
|
layouts=("us" "us" "ch")
|
||||||
variants=("" "intl" "")
|
variants=("" "intl" "")
|
||||||
lines=${#layouts[@]}
|
lines=${#layouts[@]}
|
||||||
number=0
|
index=0
|
||||||
selection=-1
|
selection=-1
|
||||||
|
|
||||||
if [[ ${#layouts[@]} -ne ${#variants[@]} ]]; then
|
if [[ ${#layouts[@]} -ne ${#variants[@]} ]]; then
|
||||||
@@ -15,17 +15,22 @@ function switch_kb_layout {
|
|||||||
unset names
|
unset names
|
||||||
for n in ${!layouts[@]}; do
|
for n in ${!layouts[@]}; do
|
||||||
if [[ -n "${variants[$n]}" ]]; then
|
if [[ -n "${variants[$n]}" ]]; then
|
||||||
names+=("${layouts[$n]}:${variants[$n]}")
|
names+=("${layouts[$n]}(${variants[$n]})")
|
||||||
else
|
else
|
||||||
names+=("${layouts[$n]}")
|
names+=("${layouts[$n]}")
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# ## TODO: use `setxkbmap -print` to get status
|
current="$(setxkbmap -print | sed -n '/xkb_symbols/p' | sed -E 's/.*pc\+([^+]+)\+.*/\1/')"
|
||||||
# current="$(echo "${devices}" | grep -ioP '(?<="active_layout_index": ).*(?=,)' -m 1)"
|
for n in ${!layouts[@]}; do
|
||||||
|
if [[ "${current}" == "${layouts[$n]}(${variants[$n]})" ]]; then
|
||||||
|
index=${n}
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
if $(which rofi &>/dev/null); then
|
if $(which rofi &>/dev/null); then
|
||||||
selection="$(printf "%s\n" "${names[@]}" | rofi -dmenu -format 'i' -fixed-num-lines ${lines} -selected-row ${number} -case-smart)"
|
selection="$(printf "%s\n" "${names[@]}" | rofi -dmenu -format 'i' -fixed-num-lines ${lines} -selected-row ${index} -case-smart)"
|
||||||
else
|
else
|
||||||
notify-send "layout-switcher" "requires [rofi]"
|
notify-send "layout-switcher" "requires [rofi]"
|
||||||
return 1
|
return 1
|
||||||
@@ -45,10 +50,9 @@ function switch_kb_layout {
|
|||||||
# return 1
|
# return 1
|
||||||
# fi
|
# fi
|
||||||
#
|
#
|
||||||
if [[ -n "${variants[$selection]}" ]]; then
|
setxkbmap "${layouts[$selection]}" "${variants[$selection]}"
|
||||||
setxkbmap -layout "${layouts[$selection]}" -variant "${variants[$selection]}"
|
if [[ $? -ne 0 ]]; then
|
||||||
else
|
notify-send "layout-switcher" "failed to set layout\n[${layouts[$selection]}:${variants[$selection]}]"
|
||||||
setxkbmap -layout "${layouts[$selection]}"
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user