From 7a99d42d656b74e523fb89ef38b1402615c67570 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 16 Feb 2014 16:43:48 -0500 Subject: Added cgo-safe callback code for GTK+ signals. GTK+ signals work! --- callbacks_unix.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 callbacks_unix.go (limited to 'callbacks_unix.go') diff --git a/callbacks_unix.go b/callbacks_unix.go new file mode 100644 index 0000000..d47d67d --- /dev/null +++ b/callbacks_unix.go @@ -0,0 +1,27 @@ +// +build !windows,!darwin,!plan9 + +// 16 february 2014 +package main + +import ( + "unsafe" +) + +/* +cgo doesn't support calling Go functions by default; we have to mark them for export. Not a problem, except arguments to GTK+ callbacks depend on the callback itself. Since we're generating callback functions as simple closures of one type, this file will wrap the generated callbacks in the appropriate callback type. We pass the actual generated pointer to the extra data parameter of the callback. +*/ + +// #cgo pkg-config: gtk+-3.0 +// #include +// extern gboolean our_delete_event_callback(GtkWidget *, GdkEvent *, gpointer); +import "C" + +//export our_delete_event_callback +func our_delete_event_callback(widget *C.GtkWidget, event *C.GdkEvent, what C.gpointer) C.gboolean { + f := *(*func() bool)(unsafe.Pointer(what)) + return togbool(f()) +} + +var callbacks = map[string]C.GCallback{ + "delete-event": C.GCallback(C.our_delete_event_callback), +} -- cgit v1.2.3