From a7f7ea1b8da51a19aaca7d5d989a28f0c9ecbf94 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Fri, 14 Mar 2014 20:03:02 -0400 Subject: Major overhaul of the way GTK+ events are handled. Closures that perform events are no longer generated; instead all events are given to fixed, compile-time, cgo-exported callback functions that take the sysData as user data. This saves memory (we no longer need to generate closures and we no longer have to save them elsewhere to keep them from being garbage collected) and makes the top of sysdata_unix.go slightly cleaner, but it moves the code for handling UI events into callbacks_unix.go. This is needed for Area, in which we need to feed the sysData to an event connected to a subwidget instead of the main widget returned. --- gtkcalls_unix.go | 23 ----------------------- 1 file changed, 23 deletions(-) (limited to 'gtkcalls_unix.go') diff --git a/gtkcalls_unix.go b/gtkcalls_unix.go index 5d3702d..f2bce9e 100644 --- a/gtkcalls_unix.go +++ b/gtkcalls_unix.go @@ -12,8 +12,6 @@ import ( // #cgo pkg-config: gtk+-3.0 // #include // #include -// /* because cgo is flaky with macros */ -// void gSignalConnect(GtkWidget *widget, char *signal, GCallback callback, void *data) { g_signal_connect(widget, signal, callback, data); } import "C" type ( @@ -25,16 +23,6 @@ func gtk_init() bool { return fromgbool(C.gtk_init_check((*C.int)(nil), (***C.char)(nil))) } -// see our_idle_callback in callbacks_unix.go for details -type gtkIdleOp struct { - what func() - done chan struct{} -} - -func gdk_threads_add_idle(idleop *gtkIdleOp) { - C.gdk_threads_add_idle(callbacks["idle"], C.gpointer(unsafe.Pointer(idleop))) -} - func gtk_main() { C.gtk_main() } @@ -48,17 +36,6 @@ func gtk_window_new() *gtkWidget { return fromgtkwidget(C.gtk_window_new(0)) } -// the garbage collector has been found to eat my callback functions; this will stop it -var callbackstore = make([]*func() bool, 0, 50) - -func g_signal_connect(obj *gtkWidget, sig string, callback func() bool) { - callbackstore = append(callbackstore, &callback) - ccallback := callbacks[sig] - csig := C.CString(sig) - defer C.free(unsafe.Pointer(csig)) - C.gSignalConnect(togtkwidget(obj), csig, ccallback, unsafe.Pointer(&callback)) -} - // TODO ensure this works if called on an individual control func gtk_widget_show(widget *gtkWidget) { C.gtk_widget_show_all(togtkwidget(widget)) -- cgit v1.2.3