Automatic keyboard detection

[endlessm/eos-shell#3425]
optional: no need for `g_clear_pointer` because `g_free` works fine on `NULL`