diff --git a/callbacks_unix.go b/callbacks_unix.go index 466beed..cb3b2f6 100644 --- a/callbacks_unix.go +++ b/callbacks_unix.go @@ -16,7 +16,7 @@ while we're at it the callback for our idle function will be handled here too fo // #cgo pkg-config: gtk+-3.0 // #include // extern gboolean our_callback(gpointer); -// extern gboolean our_delete_event_callback(GtkWidget *, GdkEvent *, gpointer); +// extern gboolean our_window_callback(GtkWidget *, GdkEvent *, gpointer); // extern void our_clicked_callback(GtkButton *, gpointer); import "C" @@ -26,8 +26,8 @@ func our_callback(what C.gpointer) C.gboolean { return togbool(f()) } -//export our_delete_event_callback -func our_delete_event_callback(widget *C.GtkWidget, event *C.GdkEvent, what C.gpointer) C.gboolean { +//export our_window_callback +func our_window_callback(widget *C.GtkWidget, event *C.GdkEvent, what C.gpointer) C.gboolean { return our_callback(what) } @@ -38,6 +38,7 @@ func our_clicked_callback(button *C.GtkButton, what C.gpointer) { var callbacks = map[string]C.GCallback{ "idle": C.GCallback(C.our_callback), - "delete-event": C.GCallback(C.our_delete_event_callback), + "delete-event": C.GCallback(C.our_window_callback), + "configure-event": C.GCallback(C.our_window_callback), "clicked": C.GCallback(C.our_clicked_callback), } diff --git a/gtkcalls_unix.go b/gtkcalls_unix.go index fa69789..115060c 100644 --- a/gtkcalls_unix.go +++ b/gtkcalls_unix.go @@ -80,6 +80,13 @@ func gtk_window_resize(window *gtkWidget, width int, height int) { C.gtk_window_resize((*C.GtkWindow)(unsafe.Pointer(window)), C.gint(width), C.gint(height)) } +func gtk_window_get_size(window *gtkWidget) (int, int) { + var width, height C.gint + + C.gtk_window_get_size((*C.GtkWindow)(unsafe.Pointer(window)), &width, &height) + return int(width), int(height) +} + func gtk_fixed_new() *gtkWidget { return (*gtkWidget)(unsafe.Pointer(C.gtk_fixed_new())) } diff --git a/sysdata_unix.go b/sysdata_unix.go index dfe3a8c..6f9e001 100644 --- a/sysdata_unix.go +++ b/sysdata_unix.go @@ -35,6 +35,19 @@ var classTypes = [nctypes]*classData{ return true // do not close the window } }, + "configure-event": func(w *sysData) func() bool { + return func() bool { + if w.container != nil && w.resize != nil { // wait for init + width, height := gtk_window_get_size(w.widget) + // run in another goroutine since this will be called in uitask + go func() { + w.resize(0, 0, width, height) + }() + } + // TODO really return true? + return true // do not continue events; we just did so + } + }, }, }, c_button: &classData{ @@ -80,6 +93,7 @@ println(s.widget) uitask <- func() { fixed := gtk_fixed_new() gtk_container_add(s.widget, fixed) + // TODO return the container before assigning the signals? for signal, generator := range ct.signals { g_signal_connect(s.widget, signal, generator(s)) } @@ -139,6 +153,7 @@ if classTypes[s.ctype] == nil || classTypes[s.ctype].setText == nil { return nil } func (s *sysData) setRect(x int, y int, width int, height int) error { +if classTypes[s.ctype] == nil || classTypes[s.ctype].setText == nil { return nil } ret := make(chan struct{}) defer close(ret) uitask <- func() {