Added Go() and the GTK+ uitask functions.

This commit is contained in:
Pietro Gagliardi 2014-07-07 21:04:44 -04:00
parent 0c57837676
commit cddf0417dc
2 changed files with 51 additions and 1 deletions

View File

@ -2,7 +2,23 @@
package ui
// TODO Go, Start, Stop
import (
"runtime"
)
// Go initializes package ui.
// TODO write this bit
func Go() error {
runtime.LockOSThread()
if err := uiinit(); err != nil {
return err
}
go uitask()
uimsgloop()
return nil
}
// TODO Stop
// This is the ui main loop.
// It is spawned by Go as a goroutine.

34
redo/uitask_unix.go Normal file
View File

@ -0,0 +1,34 @@
// 7 july 2014
package ui
import (
"unsafe"
)
// #cgo pkg-config: gtk+-3.0
// #include "gtk_unix.h"
// extern gboolean doissue(gpointer data);
import "C"
func uiinit() error {
// TODO replace with the eerror-checking version
C.gtk_init()
return nil
}
func uimsgloop() {
C.gtk_main()
}
func issue(req *Request) {
C.gdk_threads_add_idle(C.GSourceFunc(C.doissue), C.gpointer(unsafe.Pointer(req)))
}
//export doissue
func doissue(data C.gpointer) C.gboolean {
req := (*Request)(unsafe.Pointer(data))
req.op()
close(req.done)
return C.FALSE // don't repeat
}