forked from andlabs/ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon_unix.go
56 lines (45 loc) · 1.18 KB
/
common_unix.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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)
}