Replace gdk_threads_enter and gdk_threads_leave with local functions