Switching keyboard input language with usability in mind

Introduction

This article is somehow i3wm specific but with a little effort can be reused with other window managers, as its mostly about solving usability, and then about i3wm absense of keyboard switcher itself.

The problem

  • i3wm tends to be minimalistic and so it does not provide any specific way how to implement it. You can use other WM language switcher (as did I and used nm-applet from Gnome/Unity for some time).
  • Usability (and thats the main one): most keyboard switchers tend to switch languages in circle, e.g.:

    lang_cicle.png

Problems:

  • You always have to look which language you are in or count to next previous; Keypresses, ru<->en:
    • ru -1-> ua -2-> de -3-> en (3)
    • en -> ru (1)

    This is very uncomfortable to cound that you should press some key combination thrice to switch forth and once to switch back. I see many people suffer from this, making mistakes, and trying to be more careful when doing this, actually simple action.

  • In real life almost always you would switch between the single pair of languages, e.g.:
    • ru <-> en;
    • ua <-> en;
    • de <-> ru;

… during a single file editing session.

Solution

Refused

Decided: Quick & simple solution (use i3 key bindings and xkb!)

OK, so after some googling and attempts to fix buggy (in connection with i3wm and dbus) nm-applet I’ve made this quick and dirty solution in my i3 config:

mode "kbdchg" {
        bindsym 1           exec "echo 'us,ru' > ~/.config/keyboard/layout;set-x-keyboard"
        bindsym 2           exec "echo 'us,ua' > ~/.config/keyboard/layout;set-x-keyboard"
        bindsym 3           exec "echo 'us,de' > ~/.config/keyboard/layout;set-x-keyboard"
        bindsym a           exec "setxkbmap -option apple:badmap;set-x-keyboard"
        bindsym c           exec "setxkbmap -option;set-x-keyboard"
        bindsym Return mode "default"
        bindsym Escape mode "default"
}

bindsym Mod4+n mode "kbdchg"
bindsym Mod4+Cyrillic_te mode "kbdchg"

… and so, now to switch between languages I need to specify default pair and do it ONCE, and then I can switch back and forth using my preferred combination (both Shift keys in my case).

once.png

Suprisingly, this quick and dirty solution proven to be stable and easy

  • 2 years pass after I did this change. I am more then happy with this, specifically when I see how others around me suffer from usabilty issues of swiching between several languages in this circle pattern.
  • Usability matters, even such a small change gives tremendious outcome.

Comments

Comments powered by Disqus