More than two keyboard layouts switching problem

Hello community.

I’ve encountered an issue with switching keyboard layouts.

After initial installation I’ve enabled “Keyboard layouts” applet at dom0 panel and added several additional languages. When I tried to switch languages I got wrong language in Qube/Template on each second switch, which defaults to en.

E.g. in dom0 I have en, lang1, lang2, lang3 and I’m trying to switching those via Alt + Shift.
On first Alt + Shift I have lang1 in Qube/Template. Good.
On next Alt + Shift I have en in Qube/Template. Not so good.
On next Alt + Shift I have lang3 in Qube/Template. Good.
I can get lang2 in Qube/Template if I manually click via mouse on that lang in “Keyboard layouts” indicator.

I’ve done some digging and found that after each Alt + Shift switch I get correct layouts in Qube/Template reported via setxkbmap -query.
Especially on second switch I have correct entry which looks like:

rules:      evdev
model:      pc105
layout:     lang2, us
options:    grp:alt_shift_toggle

Which got me thinking that Qube/Template switches to us layout inside on second Alt+Shift keypress. So I’ve looked where logic for layout is handled and found /usr/lib/qubes/qubes-keymap.sh file. In which this block is responsible to “generate” layout options for setxkbmap:

if [ "$KEYMAP_LAYOUT" != "us" ]; then
    KEYMAP_LAYOUT="$KEYMAP_LAYOUT,en"
    KEYMAP_VARIANT="$KEYMAP_VARIANT,"
fi

after changing it to

if [ "$KEYMAP_LAYOUT" != "us" ]; then
    KEYMAP_LAYOUT="$KEYMAP_LAYOUT"
    KEYMAP_VARIANT="$KEYMAP_VARIANT,"
fi

and reboot all is working as expected.

So I wanted to ask if there is something I am missing with my keyboard layouts setup. Because I believe that there should be people who use more than two layouts and as such encounter this situation.
I’ve found several related topics: Cannot Change VM Keyboard Layout in 4.1, Keyboard layout switching shortcut not working. But as I understand those more related to discussing issues when layouts do not change in Qube/Template vs. correct change of some layouts in my case.

Also I wanted to ask why initially in KEYMAP_LAYOUT="$KEYMAP_LAYOUT,en" ,en is needed for layout options for setxkbmap. After my removal of ,en it all seems working normally. According to my understanding layout switching is handled (I might be very wrong) via dom0 sending line like us++grp:alt_shift_toggle which is then parsed by Qube/Template to decide which layout should be used. So there is no need to have lang1,us or lang2,us in options, as on switch in dom0 current layout would be communicated to Qube/Template.

Thank you for feedback.

2 Likes

ok, so I guess without ,us in that line hotkeys (like Ctrl + C/Ctrl +V) are broken on non-latin keyboard layouts…
So had to revert that, but got again issue with non-correct layout.
For now amended qubes-keymap.sh not to pass options line (which includes toggle). Layouts are switching correctly now and hotkeys on non-latin layouts are working.

2 Likes