summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-07-07 21:04:44 -0400
committerPietro Gagliardi <[email protected]>2014-07-07 21:04:44 -0400
commitcddf0417dc10fe2e094eba5e614ad7302fc4c207 (patch)
tree4f0e8b9d36f6555ae968ab0628805a0d201b7715
parent0c57837676eba65696a1e8175ff0b59ad1e00c37 (diff)
Added Go() and the GTK+ uitask functions.
-rw-r--r--redo/uitask.go18
-rw-r--r--redo/uitask_unix.go34
2 files changed, 51 insertions, 1 deletions
diff --git a/redo/uitask.go b/redo/uitask.go
index c29470a..32f8faf 100644
--- a/redo/uitask.go
+++ b/redo/uitask.go
@@ -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.
diff --git a/redo/uitask_unix.go b/redo/uitask_unix.go
new file mode 100644
index 0000000..211349b
--- /dev/null
+++ b/redo/uitask_unix.go
@@ -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
+}