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"
|
|
|
|
)
|
|
|
|
|
2014-05-19 21:18:53 -05:00
|
|
|
// #cgo pkg-config: gtk+-3.0
|
|
|
|
// #include "gtk_unix.h"
|
|
|
|
import "C"
|
|
|
|
|
2014-02-16 14:55:51 -06:00
|
|
|
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{
|
2014-06-10 08:55:14 -05:00
|
|
|
what: f,
|
|
|
|
done: done,
|
2014-03-12 19:00:29 -05:00
|
|
|
})
|
|
|
|
<-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-05-19 21:18:53 -05:00
|
|
|
C.gtk_main()
|
2014-03-01 14:18:29 -06:00
|
|
|
return nil
|
2014-02-16 14:55:51 -06:00
|
|
|
}
|