2014-02-16 14:55:51 -06:00
|
|
|
// +build !windows,!darwin,!plan9
|
|
|
|
|
|
|
|
// 16 february 2014
|
2014-03-12 20:55:45 -05:00
|
|
|
|
2014-02-19 10:41:10 -06:00
|
|
|
package ui
|
2014-02-16 14:55:51 -06:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"runtime"
|
|
|
|
)
|
|
|
|
|
|
|
|
var uitask chan func()
|
|
|
|
|
2014-03-01 14:18:29 -06:00
|
|
|
func ui(main func()) error {
|
2014-02-16 14:55:51 -06:00
|
|
|
runtime.LockOSThread()
|
|
|
|
|
|
|
|
uitask = make(chan func())
|
2014-04-27 11:43:15 -05:00
|
|
|
err := gtk_init()
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("gtk_init() failed: %v", err)
|
2014-02-16 14:55:51 -06:00
|
|
|
}
|
|
|
|
|
2014-03-12 19:00:29 -05:00
|
|
|
// 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)
|
2014-02-16 16:09:58 -06:00
|
|
|
}
|
2014-03-12 19:00:29 -05:00
|
|
|
}()
|
2014-03-01 14:18:29 -06:00
|
|
|
|
2014-03-05 12:25:19 -06:00
|
|
|
go func() {
|
|
|
|
main()
|
|
|
|
uitask <- gtk_main_quit
|
|
|
|
}()
|
2014-03-01 14:18:29 -06:00
|
|
|
|
2014-02-16 14:55:51 -06:00
|
|
|
gtk_main()
|
2014-03-01 14:18:29 -06:00
|
|
|
return nil
|
2014-02-16 14:55:51 -06:00
|
|
|
}
|