Improve keyboard handling

When using other applications (e.g. gedit) with ibus keyboards one
can notice that with some keyboards the pre-edit text doesn't get
deleted when the application/field loses focus. This is necessary
for keyboards that don't show a pop-up window, e.g.
Danish-post(m17n). Otherwise it is impossible to type any
character that ends up as pre-edit text without typing another
character that commits the pre-edit. For other keyboards like
Chinese(Pinyin) it is acceptable and expected that the pre-edit
text gets removed when the application/field loses focus.

Unfortunately there's no way to ask IBus if a keyboard shows a
pre-edit window. However, it seems that (almost?) all keyboards that
don't show a pre-edit window set the underline attribute to the
value 'None', so we use that to distinguish between the two kinds
of keyboards.

Change-Id: I96ffcf0e7b075e49f2b94038222bbd3fa2b58c5b