Change keyboard layout in i3

I installed an i3 for myself. I encountered a problem that switching the keyboard layout does not work.

Problem

The XKLAVIER_ALLOW_SECONDARY event is not triggered because it is raised from libxklavier, which is a dependency of xfce4-xkb-plugin. xfce4-xkb-plugin is a plugin that renders the current layout in the top panel. If we moved from xfce to i3, then it is not started, and the event does not occur, that is, the layout changes only in dom0, and in VMs it is no longer propagated.

Solution

The simplest solution is to run xfce4-panel. To do this, you need to add the following line to .config/i3/config in dom0:

exec --no-startup-id xfce4-panel

The line runs xfce4-xkb-plugin. After that, the layout begins to be propagated into the virtual machines.

Next, you need to set up your keyboard layouts:

localectl set-x11-keymap us,sr pc105 , grp:alt_shift_toggle

The command persistently adjusts the necessary layouts.
The first argument LAYOUT set the keyboard layouts. You can see the list of all available layouts through localectl list-keymaps
The second argument is MODEL. I just put the value from output of setxkbmap -query.
The third argument VARIANT that equals a comma , must consist of keyboard variants (e.g. qwerty) separated by commas: one variant for each layout. The blank variant means “use default”. So the comma means “default variant for us, default variant for sr”.

You can see your previous layout settings from xfce in .config/xfce4/xfconf/xfce-perchannel-xml/keyboard-layout.xml.

Also, consider adding

exec --no-startup-id /usr/lib64/xfce4/notifyd/xfce4-notifyd

to receive dom0 notifications such as starting/stopping qubes and global clipboard actions.

1 Like