Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions install/provisioning/kmscon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
# beside OMARCHY_KMSCON=1.
#
# omarchy_keymap_xkb <keymap> XKB "layout model variant options" for a
# console keymap, us for one nobody knows
# console keymap, us for one nobody knows,
# and US first for one in the US-prompt list
# omarchy_kmscon_face <lang> the font family Han characters are drawn in
# omarchy_kmscon <log> <keymap> <lang> <#rrggbb or ""> <command...>
# run command in kmscon on this VT; returns when kmscon ends
Expand All @@ -28,12 +29,45 @@ fi
# typed in it is typed again at boot under that keymap: the layouts must place
# keys alike. From systemd's table, the one localectl and the installed system
# use.
#
# Layouts in omarchy_hooks.conf's US-prompt list (non-Latin layouts and all rs
# variants) go after US, a Shift+Shift away. omarchy_hooks.conf keeps
# vconsole.conf out of the initramfs for them, so the LUKS prompt types US,
# and the login screen and desktop start in US too. Starting kmscon in US
# keeps the passphrase typeable at every prompt.
omarchy_keymap_xkb() {
local keymap=${1:-us} layout="" model=- variant=- options=-
local i moved=0 us_variant="" others="" other_variants=""
local -a layouts variants

if ! read -r layout variant options < <(omarchy_keymap_xkb_extra "$keymap"); then
read -r layout model variant options < <(awk -v k="$keymap" '$1 == k { print $2, $3, $4, $5; exit }' /usr/share/systemd/kbd-model-map 2>/dev/null) || true
fi
printf '%s %s %s %s\n' "${layout:-us}" "${model:--}" "${variant:--}" "${options:--}"
layout=${layout:-us}

# omarchy_hooks.conf's list, Serbian's Latin variants included, as at every
# prompt after kmscon.
case ${layout%%,*} in
af | am | ara | bd | bg | by | et | ge | gr | il | in | iq | ir | kg | kh | kz | la | lk | mk | mm | mn | mv | np | rs | ru | sy | th | tj | ua)
IFS=, read -ra layouts <<<"$layout"
IFS=, read -ra variants <<<"${variant#-}"
for i in "${!layouts[@]}"; do
if ((!moved)) && [[ ${layouts[i]} == us ]]; then
us_variant=${variants[i]:-} moved=1
else
others+=,${layouts[i]} other_variants+=,${variants[i]:-}
fi
done
layout=us$others variant=$us_variant$other_variants
[[ $variant == *[!,]* ]] || variant=-
if [[ $options != *grp:* ]]; then
[[ $options != "-" ]] || options=""
options=${options:+$options,}grp:shifts_toggle
fi
;;
esac

printf '%s %s %s %s\n' "$layout" "${model:--}" "${variant:--}" "${options:--}"
}

# Han characters take a different form in each CJK language, and Noto's
Expand Down
16 changes: 14 additions & 2 deletions test/shell.d/provision-owner-keyboard-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,8 @@ pass "console font rejects non-VT paths"
# takes its keyboard layout and font once, at its start. The password is typed
# at boot in the layout of the console keymap, so kmscon must type that layout,
# and setup must have kmscon started again when the keyboard step changes it.
# A layout in omarchy_hooks.conf's US-prompt list, Serbian Latin included, is
# typed at boot in US, so kmscon starts there too.

kms=$tmp/kmscon
mkdir -p "$kms/bin"
Expand All @@ -948,8 +950,18 @@ source "$ROOT/install/provisioning/kmscon.sh"
[[ $(omarchy_keymap_xkb us) == "us pc105+inet - terminate:ctrl_alt_bksp" ]] || fail "a US keymap types US in kmscon" "$(omarchy_keymap_xkb us)"
[[ $(omarchy_keymap_xkb de-latin1-nodeadkeys) == "de pc105 nodeadkeys terminate:ctrl_alt_bksp" ]] ||
fail "kmscon types the layout systemd pairs with a keymap" "$(omarchy_keymap_xkb de-latin1-nodeadkeys)"
[[ $(omarchy_keymap_xkb ua) == "ua,us - - grp:shifts_toggle,grp_led:scroll" && $(omarchy_keymap_xkb cz) == "cz,us - qwerty, grp:shifts_toggle,grp_led:scroll" ]] ||
fail "kmscon types the form's own layout for a keymap systemd lacks" "$(omarchy_keymap_xkb ua) / $(omarchy_keymap_xkb cz)"
[[ $(omarchy_keymap_xkb cz) == "cz,us - qwerty, grp:shifts_toggle,grp_led:scroll" ]] ||
fail "kmscon types the form's own layout for a keymap systemd lacks" "$(omarchy_keymap_xkb cz)"
[[ $(omarchy_keymap_xkb ua) == "us,ua - - grp:shifts_toggle,grp_led:scroll" &&
$(omarchy_keymap_xkb bg-cp1251) == "us,bg - ,phonetic grp:shifts_toggle,grp_led:scroll" ]] ||
fail "kmscon starts a non-Latin layout of the form's in US, its variant kept" "$(omarchy_keymap_xkb ua) / $(omarchy_keymap_xkb bg-cp1251)"
[[ $(omarchy_keymap_xkb ru) == "us,ru pc105 - terminate:ctrl_alt_bksp,grp:shifts_toggle,grp_led:scroll" ]] ||
fail "kmscon starts systemd's non-Latin layout in US" "$(omarchy_keymap_xkb ru)"
[[ $(omarchy_keymap_xkb ge) == "us,ge pc105 - terminate:ctrl_alt_bksp,grp:shifts_toggle" &&
$(omarchy_keymap_xkb il) == "us,il pc105 - terminate:ctrl_alt_bksp,grp:shifts_toggle" ]] ||
fail "a non-Latin layout without US or a toggle gains both" "$(omarchy_keymap_xkb ge) / $(omarchy_keymap_xkb il)"
[[ $(omarchy_keymap_xkb sr-latin) == "us,rs pc105 ,latin terminate:ctrl_alt_bksp,grp:shifts_toggle" ]] ||
fail "Serbian Latin starts in US, matching omarchy_hooks.conf" "$(omarchy_keymap_xkb sr-latin)"
[[ $(bash -c 'source "$1" && omarchy_keymap_xkb de_CH-latin1' bash "$ROOT/install/provisioning/kmscon.sh") == "ch - - -" ]] ||
fail "kmscon.sh resolves extra keymaps when sourced on its own"
[[ $(omarchy_keymap_xkb no-such-keymap) == "us - - -" ]] || fail "an unknown keymap types US" "$(omarchy_keymap_xkb no-such-keymap)"
Expand Down