Try to fix X threading warning

Replace pthreads with GThread and g_main_context_invoke with
gdk_threads_add_idle as suggested here:
http://stackoverflow.com/a/18651036/472927

Problem still occurs, albeit now more rarely