Ensure we have a client window before using it
The XIM input method can some times go into weird states, especially when extended devices or in mixed environments with multiple input methods installed.
Ideally, people should simply stop using XIM, which is utterly broken, and use IBus instead; nevertheless, crashing is not nice.
Fixes: #61 (closed) Fixes: #518 (closed)