Saturday, October 30, 2010

Kxkb: spare layouts (poor man's sticky switching)

I am almost done with alternative implementation of much missed sticky switching. There were two reasons on why new implementation (and thus naming) differs:
  1. The shortcuts - having base (1st) layout constant is critical for keyboard shortcuts to work in KDE, especially for non-latin layout users
  2. It's simpler - this allows most of the switching still to be performed by xkb leaving only occasional map switches for KDE keyboard module
The idea of spare layouts is that only last layout of the base pack can be switched out for "spare" layout from the context menu. And the hope is that
a) most of the users will lock 2 layouts
b) users will switch more (e.g. in case of en-ru-uk set) between en-ru and en-uk than between ru-uk.

Under the hood only the base layouts are configured for xkb backend so pretty much any switching method uses standard xkb group switching (as in KDE 4.x) though when "spare" layout is chosen in context menu, the last of the base layouts is swapped out with the chosen one and xkb map is reconfigured.

One drawback is that switching to spare layout is slower (as the map is reconfigured - not just a group switch). This has also another slowdown for window switching if by-window/by-app mode is used - when active window changed and the map of the active window is different from the previous one reconfiguration has to be done. It's not extremely slow (~10-200ms in my tests) but definitely much slower than just a group switch.

I guess users who crave for sticky switching lived with slow switching so hopefully it'll be ok as it's much easier to let x.org do the group switching and just change the map occasionally rather than take over all the switching work in the keyboard module.

This approach also allows to have more than 4 layouts (xkb protocol limitaton) - if more than 4 layouts configured they will automatically become spare layouts.

Couple of snapshots: the configuration of spare layouts (gray background is the spare layouts) and the context menu look (first part of the menu is base layouts).


5 comments:

  1. Nice to hear 'sticky switching' is comming back.

    Thank you for your work!

    ReplyDelete
  2. This is very useful. Thank you for your efforts. :)

    ReplyDelete
  3. Thanks Andriy.
    If i have some try, i'll try to test this feature.

    ReplyDelete
  4. Is it possible to toggle a spare layout via dbus? (It seems there is no key binding for that.)

    ReplyDelete
  5. I would like to have a key to reach spare layouts not only mouse. Is it possible?

    ReplyDelete