diff options
| author | Pietro Gagliardi <[email protected]> | 2014-08-30 23:02:02 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-08-30 23:02:02 -0400 |
| commit | 77bf566ebbcb62acd4d08d905d9542d6ff9b6b80 (patch) | |
| tree | eeb8e72bc3bf57f5be7f0c0af4319189ac6de838 /common_unix.go | |
| parent | 155899c65ed32245e2ccad4197a10c77017d835b (diff) | |
...in with the new.
Diffstat (limited to 'common_unix.go')
| -rw-r--r-- | common_unix.go | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/common_unix.go b/common_unix.go new file mode 100644 index 0000000..d88afbb --- /dev/null +++ b/common_unix.go @@ -0,0 +1,56 @@ +// +build !windows,!darwin + +// 7 july 2014 + +package ui + +import ( + "unsafe" +) + +// #include "gtk_unix.h" +// /* because cgo doesn't like g_signal_connect() */ +// void gSignalConnect(gpointer obj, gchar *sig, GCallback callback, gpointer data) +// { +// g_signal_connect(obj, sig, callback, data); +// } +// void gSignalConnectAfter(gpointer obj, gchar *sig, GCallback callback, gpointer data) +// { +// g_signal_connect_after(obj, sig, callback, data); +// } +import "C" + +func fromgstr(s *C.gchar) string { + return C.GoString((*C.char)(unsafe.Pointer(s))) +} + +func togstr(s string) *C.gchar { + return (*C.gchar)(unsafe.Pointer(C.CString(s))) +} + +func freegstr(s *C.gchar) { + C.free(unsafe.Pointer(s)) +} + +func fromgbool(b C.gboolean) bool { + return b != C.FALSE +} + +func togbool(b bool) C.gboolean { + if b == true { + return C.TRUE + } + return C.FALSE +} + +func g_signal_connect(object C.gpointer, name string, to C.GCallback, data C.gpointer) { + cname := togstr(name) + defer freegstr(cname) + C.gSignalConnect(object, cname, to, data) +} + +func g_signal_connect_after(object C.gpointer, name string, to C.GCallback, data C.gpointer) { + cname := togstr(name) + defer freegstr(cname) + C.gSignalConnectAfter(object, cname, to, data) +} |
