use double buffering

render to cairo_image_surface and drop that onto the xlib_surface
to get rid of flickering on redraws.
refactor calculation of dimentions
move renderling of layouts into extra function