diff --git a/install/config/detect-keyboard-layout.sh b/install/config/detect-keyboard-layout.sh index aaaee4f875..204042334d 100644 --- a/install/config/detect-keyboard-layout.sh +++ b/install/config/detect-keyboard-layout.sh @@ -2,12 +2,29 @@ conf="/etc/vconsole.conf" hyprconf="$HOME/.config/hypr/input.conf" -if grep -q '^XKBLAYOUT=' "$conf"; then - layout=$(grep '^XKBLAYOUT=' "$conf" | cut -d= -f2 | tr -d '"') - sed -i "/^[[:space:]]*kb_options *=/i\ kb_layout = $layout" "$hyprconf" -fi +default="us" +# Extract the primary keyboard layout (XKBLAYOUT) from vconsole.conf. +# We use grep to find the line, cut to get the value after '=', and tr to remove quotes. +layout=$(grep '^XKBLAYOUT=' "$conf" | cut -d= -f2 | tr -d '"') + +# Extract the keyboard variant (XKBVARIANT) from vconsole.conf. +# This might be empty if no specific variant is used for the chosen layout. +variant=$(grep '^XKBVARIANT=' "$conf" | cut -d= -f2 | tr -d '"') -if grep -q '^XKBVARIANT=' "$conf"; then - variant=$(grep '^XKBVARIANT=' "$conf" | cut -d= -f2 | tr -d '"') - sed -i "/^[[:space:]]*kb_options *=/i\ kb_variant = $variant" "$hyprconf" +if [ "$layout" != "$default" ]; then + kb_layout="$default,$layout" + kb_variant=",$variant" + kb_options="grp:alt_shift_toggle" +else + kb_layout="$layout" + kb_variant="$variant" + kb_options="" fi +sed -i "/^[[:space:]]*kb_layout *=/d" "$hyprconf" +sed -i "/^[[:space:]]*kb_variant *=/d" "$hyprconf" +sed -i "/^[[:space:]]*kb_options *=/d" "$hyprconf" + +echo "kb_layout = $kb_layout" >> "$hyprconf" + +[ -n "$kb_variant" ] && echo "kb_variant = $kb_variant" >> "$hyprconf" +[ -n "$kb_options" ] && echo "kb_options = $kb_options" >> "$hyprconf" \ No newline at end of file