Fix multithreading issues.

We should not update the UI from another thread than the main one,
so we defer the rendering to the main thread using g_idle_add().