From 55f7a9638ebcd2dfb78394cf396f2edac926baaf Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Wed, 12 Mar 2014 20:00:29 -0400 Subject: Changed the way uitask is dispatched on GTK+ to make event handling not a CPU hog. --- uitask_unix.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'uitask_unix.go') diff --git a/uitask_unix.go b/uitask_unix.go index 9b22635..1ccc621 100644 --- a/uitask_unix.go +++ b/uitask_unix.go @@ -18,15 +18,19 @@ func ui(main func()) error { return fmt.Errorf("gtk_init failed (reason unknown; TODO)") } - // thanks to tristan in irc.gimp.net/#gtk - gdk_threads_add_idle(func() bool { - select { - case f := <-uitask: - f() - default: // do not block + // thanks to tristan and Daniel_S in irc.gimp.net/#gtk + // see our_idle_callback in callbacks_unix.go for details + go func() { + for f := range uitask { + done := make(chan struct{}) + gdk_threads_add_idle(>kIdleOp{ + what: f, + done: done, + }) + <-done + close(done) } - return true // don't destroy the callback - }) + }() go func() { main() -- cgit v1.2.3