Experimental multiple keyboard support added.

This commit is contained in:
Storm Dragon 2023-08-31 01:31:51 -04:00
parent cb7bfb36e8
commit 19d201ecf4
3 changed files with 161 additions and 1 deletions

View File

@ -32,6 +32,7 @@ An uppercase I looks like a 1, 3 from i3, and 8 because the song [We Are 138](ht
- udiskie: [optional] for automatically mounting removable storage
- xclip: Clipboard support
- xbacklight: [optional] for screen brightness adjustment
- xorg-setxkbmap: [optional] for multiple keyboard layouts
- yad: For screen reader accessible dialogs
I38 will try to detect your browser, file manager, and web browser and present you with a list of options to bind to their launch keys. It will also create bindings for pidgin and mumble if they are installed. To use the bindings, press your ratpoison mode key which is set when you run the i38.sh script. next, press the binding for the application you want, w for web browser, e for text editor, f for file manager, m for mumble, etc. To learn all the bindings, find and read the mode ratpoison section of ~/.config/i3/config.

113
i38.sh
View File

@ -25,6 +25,105 @@ if [[ -n "${missing}" ]]; then
exit 1
fi
keyboard_menu() {
keyboardMenu=("us" "USA"
"ad" "Andorra"
"af" "Afghanistan"
"ara" "Arabic"
"al" "Albania"
"am" "Armenia"
"az" "Azerbaijan"
"by" "Belarus"
"be" "Belgium"
"bd" "Bangladesh"
"in" "India"
"ba" "Bosnia and Herzegovina"
"br" "Brazil"
"bg" "Bulgaria"
"ma" "Morocco"
"mm" "Myanmar"
"ca" "Canada"
"cd" "Congo, Democratic Republic of the"
"cn" "China"
"hr" "Croatia"
"cz" "Czechia"
"dk" "Denmark"
"nl" "Netherlands"
"bt" "Bhutan"
"ee" "Estonia"
"ir" "Iran"
"iq" "Iraq"
"fo" "Faroe Islands"
"fi" "Finland"
"fr" "France"
"gh" "Ghana"
"gn" "Guinea"
"ge" "Georgia"
"de" "Germany"
"gr" "Greece"
"hu" "Hungary"
"is" "Iceland"
"il" "Israel"
"it" "Italy"
"jp" "Japan"
"kg" "Kyrgyzstan"
"kh" "Cambodia"
"kz" "Kazakhstan"
"la" "Laos"
"latam" "Latin American"
"lt" "Lithuania"
"lv" "Latvia"
"mao" "Maori"
"me" "Montenegro"
"mk" "Macedonia"
"mt" "Malta"
"mn" "Mongolia"
"no" "Norway"
"pl" "Poland"
"pt" "Portugal"
"ro" "Romania"
"ru" "Russia"
"rs" "Serbia"
"si" "Slovenia"
"sk" "Slovakia"
"es" "Spain"
"se" "Sweden"
"ch" "Switzerland"
"sy" "Syria"
"tj" "Tajikistan"
"lk" "Sri Lanka"
"th" "Thailand"
"tr" "Turkey"
"tw" "Taiwan"
"ua" "Ukraine"
"gb" "United Kingdom"
"uz" "Uzbekistan"
"vn" "Vietnam"
"kr" "Korea, Republic of"
"nec_vndr/jp" "Japan (PC-98xx Series)"
"ie" "Ireland"
"pk" "Pakistan"
"mv" "Maldives"
"za" "South Africa"
"epo" "Esperanto"
"np" "Nepal"
"ng" "Nigeria"
"et" "Ethiopia"
"sn" "Senegal"
"brai" "Braille"
"tm" "Turkmenistan"
"ml" "Mali"
"tz" "Tanzania"
)
dialog --title "I38" \
--backtitle "Use the arrow keys to find the option you want, and enter to select it. When you are finished selecting layouts, use right arrow to find \"Done\" and press enter." \
--clear \
--cancel-label "Done" \
--no-tags \
--menu "Select Keyboard Layout" 0 0 0 "${keyboardMenu[@]}" --stdout
return $?
}
menulist() {
# Args: List of items for menu.
# returns: selected tag
@ -38,7 +137,7 @@ menulist() {
--backtitle "Use the arrow keys to find the option you want, and enter to select it." \
--clear \
--no-tags \
--menu "$menuText" 0 0 0 ${menuList[@]} --stdout
--menu "$menuText" 0 0 0 "${menuList[@]}" --stdout
return $?
}
@ -172,6 +271,13 @@ while [[ "$escapeKey" == "$mod" ]]; do
dialog --title "I38" --msgbox "Ratpoison and mod key cannot be the same key." -1 -1
fi
done
# Multiple keyboard layouts
if [[ $(yesno "Do you want to use multiple keyboard layouts?") -eq 0 ]]; then
unset kbd
while : ; do
kbd+=("$(keyboard_menu)") || break
done
fi
# Volume jump
volumeJump=$(rangebox "How much should pressing the volume keys change the volume?" 1 15 5)
# Email client
@ -402,6 +508,11 @@ bindsym $mod+Shift+BackSpace mode "default"
EOF
# Multiple keyboard layouts if requested.
if [[ ${#kbd[@]} -gt 1 ]]; then
echo "bindsym Mod4+space exec ${i3Path}/scripts/keyboard.sh cycle ${kbd[@]}" >> ${i3Path}/config
fi
# Create ratpoison mode if requested.
if [[ -n "${escapeKey}" ]]; then
cat << EOF >> ${i3Path}/config

48
scripts/keyboard.sh Executable file
View File

@ -0,0 +1,48 @@
#!/usr/bin/env bash
# This script is a modified version of i3-keyboard-layout.
# Originally Copyright (c) 2018 Sergio Gil.
# https://github.com/porras/i3-keyboard-layout
# This modified script, like the rest of I38, is released under the WTFPL license.
# The original work was released under the MIT license.
set -e
get_kbdlayout() {
layout=$(setxkbmap -query | grep -oP 'layout:\s*\K([\w,]+)')
variant=$(setxkbmap -query | grep -oP 'variant:\s*\K(\w+)')
echo "$layout" "$variant"
}
set_kbdlayout() {
eval "array=($1)"
setxkbmap "${array[@]}" &&
spd-say -P important -Cw "${array[@]}"
}
cycle() {
current_layout=$(get_kbdlayout | xargs)
layouts=("$@" "$1") # add the first one at the end so that it cycles
index=0
while [ "${layouts[$index]}" != "$current_layout" ] && [ $index -lt "${#layouts[@]}" ]; do index=$[index +1]; done
next_index=$[index +1]
next_layout=${layouts[$next_index]}
set_kbdlayout "$next_layout"
}
subcommand="$1"
shift || exit 1
case $subcommand in
"get")
echo -n $(get_kbdlayout)
;;
"cycle")
cycle "$@"
;;
esac
exit 0