gui: Rewrite main core message loop

Signed-off-by: Michael Buesch <m@bues.ch>