Removed the gtk_main_quit() kludge from uitask_unix.go; this also removes our_idle_callback() and its associated stuff.
This commit is contained in:
parent
37051f5c15
commit
1f0299bd51
|
@ -18,7 +18,6 @@ while we're at it the callback for our idle function will be handled here too
|
|||
// extern gboolean our_window_delete_event_callback(GtkWidget *, GdkEvent *, gpointer);
|
||||
// extern gboolean our_window_configure_event_callback(GtkWidget *, GdkEvent *, gpointer);
|
||||
// extern void our_button_clicked_callback(GtkButton *, gpointer);
|
||||
// extern gboolean our_idle_callback(gpointer);
|
||||
// /* because cgo is flaky with macros; static inline because we have //exports */
|
||||
// static inline void gSignalConnect(GtkWidget *widget, char *signal, GCallback callback, void *data) { g_signal_connect(widget, signal, callback, data); }
|
||||
import "C"
|
||||
|
@ -71,25 +70,3 @@ func g_signal_connect_pointer(obj *C.GtkWidget, sig string, callback C.GCallback
|
|||
defer C.free(unsafe.Pointer(csig))
|
||||
C.gSignalConnect(obj, csig, callback, p)
|
||||
}
|
||||
|
||||
// there are two issues we solve here:
|
||||
// 1) we need to make sure the uitask request gets garbage collected when we're done so as to not waste memory, but only when we're done so as to not have craziness happen
|
||||
// 2) we need to make sure one idle function runs and finishes running before we start the next; otherwise we could wind up with weird things like the ret channel being closed early
|
||||
// so our_idle_callback() calls the uitask function in what and sends a message back to the dispatcher over done that it finished running; the dispatcher is still holding onto the uitask function so it won't be collected
|
||||
type gtkIdleOp struct {
|
||||
what func()
|
||||
done chan struct{}
|
||||
}
|
||||
|
||||
//export our_idle_callback
|
||||
func our_idle_callback(what C.gpointer) C.gboolean {
|
||||
idleop := (*gtkIdleOp)(unsafe.Pointer(what))
|
||||
idleop.what()
|
||||
idleop.done <- struct{}{}
|
||||
return C.FALSE // remove this idle function; we're finished
|
||||
}
|
||||
|
||||
func gdk_threads_add_idle_op(idleop *gtkIdleOp) {
|
||||
C.gdk_threads_add_idle(C.GCallback(C.our_idle_callback),
|
||||
C.gpointer(unsafe.Pointer(idleop)))
|
||||
}
|
||||
|
|
|
@ -28,6 +28,17 @@ import (
|
|||
// g_free(p);
|
||||
// }
|
||||
// extern gboolean our_createWindow_callback(gpointer);
|
||||
// /* this is called when we're done */
|
||||
// static inline gboolean our_quit_callback(gpointer data)
|
||||
// {
|
||||
// gtk_main_quit();
|
||||
// return FALSE; /* remove from idle handler (not like it matters) */
|
||||
// }
|
||||
// /* I would call gdk_threads_add_idle() directly from ui() but cgo whines, so; trying to access our_quit_callback() in any way other than a call would cause _cgo_main.c to complain too */
|
||||
// static inline void signalQuit(void)
|
||||
// {
|
||||
// gdk_threads_add_idle(our_quit_callback, NULL);
|
||||
// }
|
||||
import "C"
|
||||
|
||||
//export our_createWindow_callback
|
||||
|
@ -63,22 +74,10 @@ func uiinit() error {
|
|||
}
|
||||
|
||||
func ui() {
|
||||
// thanks to tristan and Daniel_S in irc.gimp.net/#gtk
|
||||
// see our_idle_callback in callbacks_unix.go for details
|
||||
go func() {
|
||||
// TODO do differently
|
||||
<-Stop
|
||||
// using gdk_threads_add_idle() will make sure it gets run when any events currently being handled finish running
|
||||
f := func() {
|
||||
C.gtk_main_quit()
|
||||
}
|
||||
done := make(chan struct{})
|
||||
gdk_threads_add_idle_op(>kIdleOp{
|
||||
what: f,
|
||||
done: done,
|
||||
})
|
||||
<-done
|
||||
close(done)
|
||||
C.signalQuit()
|
||||
// TODO wait for it to return?
|
||||
}()
|
||||
|
||||
C.gtk_main()
|
||||
|
|
Loading…
Reference in New Issue