Attempt to optimize the event look on XWindow

The changes are not tested.
Fix problem with xwindow event loop optimisation