Add X event handling

The cause for flickering is yet unknown, but I may investigate a little
on that in the future.