Backport commit 86cd5c04 from master, and anyway make the IM fully resilient against lack of text-input interface.