func (w *Window) Connect(sig string, f interface{}) { csignal := _GString(sig) goclosure := C.gGoclosureNew(unsafe.Pointer(&f), nil) C.g_signal_connect_closure(C.gpointer(unsafe.Pointer(w.c)), csignal, (*C.GClosure)(unsafe.Pointer(goclosure)), 0) _GFree(unsafe.Pointer(csignal)) }
func Connect(obj unsafe.Pointer, signal string, cb interface{}) uint64 { cbp := &cb refHolderLock.Lock() refHolder = append(refHolder, cbp) //FIXME deref refHolderLock.Unlock() closure := C.new_closure(unsafe.Pointer(cbp)) cSignal := (*C.gchar)(unsafe.Pointer(C.CString(signal))) defer C.free(unsafe.Pointer(cSignal)) id := C.g_signal_connect_closure(C.gpointer(obj), cSignal, closure, C.gboolean(0)) return uint64(id) }
func ObjConnect(obj *C.GObject, signal string, cb interface{}) C.gulong { cbp := &cb refHolderLock.Lock() refHolder = append(refHolder, cbp) //TODO deref refHolderLock.Unlock() closure := C.new_closure(unsafe.Pointer(cbp)) cSignal := (*C.gchar)(unsafe.Pointer(C.CString(signal))) defer C.free(unsafe.Pointer(cSignal)) id := C.g_signal_connect_closure(asGPtr(obj), cSignal, closure, False()) return id }
// Connect is a wrapper around g_signal_connect_closure(). f must be // a function with a signaure matching the callback signature for // detailedSignal. userData must either 0 or 1 elements which can // be optionally passed to f. If f takes less arguments than it is // passed from the GLib runtime, the extra arguments are ignored. // // Arguments for f must be a matching Go equivalent type for the // C callback, or an interface type which the value may be packed in. // If the type is not suitable, a runtime panic will occur when the // signal is emitted. func (v *Object) Connect(detailedSignal string, f interface{}, userData ...interface{}) (SignalHandle, error) { if len(userData) > 1 { return 0, errors.New("userData len must be 0 or 1") } cstr := C.CString(detailedSignal) defer C.free(unsafe.Pointer(cstr)) closure, err := ClosureNew(f, userData...) if err != nil { return 0, err } C._g_closure_add_finalize_notifier(closure) c := C.g_signal_connect_closure(C.gpointer(v.native()), (*C.gchar)(cstr), closure, gbool(false)) handle := SignalHandle(c) // Map the signal handle to the closure. signals[handle] = closure return handle, nil }
// Connect is a wrapper around g_signal_connect_closure(). f must be // a function with a signaure matching the callback signature for // detailedSignal. userData must either 0 or 1 elements which can // be optionally passed to f. If f takes less arguments than it is // passed from the GLib runtime, the extra arguments are ignored. // // Currently, the non userdata arguments to f must be a *Object if // the callback calls for any GObject. Trying to use other GObject // types will cause a panic when the callback is run. This is a bug. // The type of the optional user data argument in f may be any type // that Go can type convert userData[0] as. Non-GObject types may // always be used as their Go equivalent types (for example, *C.gchar // as a Go string). func (v *Object) Connect(detailedSignal string, f interface{}, userData ...interface{}) (SignalHandle, error) { if len(userData) > 1 { return 0, errors.New("userData len must be 0 or 1") } cstr := C.CString(detailedSignal) defer C.free(unsafe.Pointer(cstr)) closure, err := ClosureNew(f, userData...) if err != nil { return 0, err } c := C.g_signal_connect_closure(C.gpointer(v.Native()), (*C.gchar)(cstr), closure, gbool(false)) handle := SignalHandle(c) // Add closure to internally-maintained signals map. signals[handle] = closure return handle, nil }