Added window resize handling to the GTK+ backend.

This commit is contained in:
Pietro Gagliardi 2014-07-14 22:54:57 -04:00
parent daafb7aef8
commit b3cba4bfb1
1 changed files with 18 additions and 0 deletions

View File

@ -6,10 +6,12 @@ package ui
import ( import (
"unsafe" "unsafe"
"fmt"
) )
// #include "gtk_unix.h" // #include "gtk_unix.h"
// extern gboolean windowClosing(GtkWidget *, GdkEvent *, gpointer); // extern gboolean windowClosing(GtkWidget *, GdkEvent *, gpointer);
// extern gboolean windowResizing(GtkWidget *, GdkEvent *, gpointer);
import "C" import "C"
type window struct { type window struct {
@ -47,6 +49,11 @@ func newWindow(title string, width int, height int) *Request {
"delete-event", "delete-event",
C.GCallback(C.windowClosing), C.GCallback(C.windowClosing),
C.gpointer(unsafe.Pointer(w))) C.gpointer(unsafe.Pointer(w)))
g_signal_connect(
C.gpointer(unsafe.Pointer(w.window)),
"configure-event",
C.GCallback(C.windowResizing),
C.gpointer(unsafe.Pointer(w)))
// TODO size // TODO size
C.gtk_container_add(w.container, layoutw) C.gtk_container_add(w.container, layoutw)
c <- w c <- w
@ -144,3 +151,14 @@ func windowClosing(wid *C.GtkWidget, e *C.GdkEvent, data C.gpointer) C.gboolean
} }
return C.GDK_EVENT_STOP // keeps window alive return C.GDK_EVENT_STOP // keeps window alive
} }
//export windowResizing
func windowResizing(wid *C.GtkWidget, event *C.GdkEvent, data C.gpointer) C.gboolean {
w := (*window)(unsafe.Pointer(data))
e := (*C.GdkEventConfigure)(unsafe.Pointer(event))
_ = w // TODO
// TODO this does not take CSD into account; my attempts at doing so so far have failed to work correctly in the face of rapid live resizing
// TODO triggered twice on each resize or maximize for some reason???
fmt.Printf("new size %d x %d\n", e.width, e.height)
return C.GDK_EVENT_PROPAGATE // let's be safe
}