Skip to content

How to setup kanata for Latin & Cyrillic layouts

Ivan Greqov edited this page Dec 23, 2024 · 1 revision

This is how I setup kanata to work with 2 languages: English and Russian. Let's assume we have a system with 2 standard layouts: qwerty for English, йцукен for Russian. Switching between languages controlled by Shift+Alt shortcut.

I use alt layout for English, so let's create a layer (called sowa) for that layout. I will show only home row for the sake of simplicity:

(deflayer sowa
	...
	x n r t c ` / h a e i ;
	...
)

If we switch (Shift+Alt) to Russian language right now we'll see wrong order for Cyrillic letters:

;; actual characters:
	ч т к е с ё

;; expected characters for йцукен:
	ф ы в а п р

I also use alt layout for Russian so I expect to see the following letters on the home row: з и о а к ё. To make this happen I created a Cyrillic layer (called sowaru):

(deflayer sowaru
	...
	p b j f r ` a g y c d ;
	...
)

The next step is to add a macro that switches both OS language and kanata layer:

(defalias
	EN (multi lsft lalt (layer-switch sowa))
	RU (multi lsft lalt (layer-switch sowaru))
)

After adding those @EN, @RU macros to layers everything works like expected. Everything except shortcuts.

For shortcuts on Cyrillic layer I want to press the same key as on Latin layer. For example, for ctrl+x shortcut I expect to press the first key on home (middle) row. But on our Cyrillic layer we have p letter on that spot. To fix this issue let's temporarily switch to Latin layer on Ctrl/Alt/Shift presses. I use home row mods here but the logic will be the same for regular Ctrl/Alt/Shift keys:

;; on hold switch to sowa layer for English letters for shortcuts
	r1 (tap-hold 200 200 r (multi lctl (layer-while-held sowa)))
	g1 (tap-hold 200 200 g (multi rctl (layer-while-held sowa)))
	j1 (tap-hold 200 200 j (multi lalt (layer-while-held sowa)))
	c1 (tap-hold 200 200 c (multi ralt (layer-while-held sowa)))

;; stay on sowaru layer for capital Cyrillic letters
	fo (tap-hold 200 200 f lsft)
	y1 (tap-hold 200 200 y rsft)

(deflayer sowaru
	...
	p b @j1 @fo @r1 ` a @g1 @y1 @c1 d ;
	...
)

It works for single modifier key shortcuts. To make it work for multiple modifiers (like ctrl+shift+t) we have to add home row mods to Latin layer too:

;; home row mods
	c0 (tap-hold 200 200 c lctl)
	h0 (tap-hold 200 200 h rctl)
	t0 (tap-hold 200 200 t lsft)
	a0 (tap-hold 200 200 a rsft)
	r0 (tap-hold 200 200 r lalt)
	e0 (tap-hold 200 200 e ralt)

(deflayer sowa
	...
	x n @r0 @t0 @c0 ` / @h0 @a0 @e0 i ;
	...
)

That's all.

Conclusion We'd successfully setup kanata to work with EN/RU languages. Setup uses standard OS layouts qwerty/йцукен, no need to create custom ones.

Люди не должны страдать, машины должны страдать.

Clone this wiki locally