Fixed window resizing in GTK+ acting wonky AND several related TODOs to boot!
This commit is contained in:
parent
58673a614c
commit
847690bb10
|
@ -14,6 +14,10 @@ import (
|
||||||
// {
|
// {
|
||||||
// g_signal_connect(obj, sig, callback, 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"
|
import "C"
|
||||||
|
|
||||||
func fromgstr(s *C.gchar) string {
|
func fromgstr(s *C.gchar) string {
|
||||||
|
@ -33,3 +37,9 @@ func g_signal_connect(object C.gpointer, name string, to C.GCallback, data C.gpo
|
||||||
defer freegstr(cname)
|
defer freegstr(cname)
|
||||||
C.gSignalConnect(object, cname, to, data)
|
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)
|
||||||
|
}
|
||||||
|
|
|
@ -66,9 +66,19 @@ func (w *widgetbase) commitResize(c *allocation, d *sizing) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
// TODO this uses w.parentw directly; change?
|
|
||||||
C.gtk_layout_move(w.parentw.layout, w.widget, C.gint(c.x), C.gint(c.y))
|
// as we resize on size-allocate, we have to also use size-allocate on our children
|
||||||
C.gtk_widget_set_size_request(w.widget, C.gint(c.width), C.gint(c.height))
|
// this is fine anyway; in fact, this allows us to move without knowing what the container is!
|
||||||
|
// this is what GtkBox does anyway
|
||||||
|
// thanks to tristan in irc.gimp.net/#gtk+
|
||||||
|
|
||||||
|
var r C.GtkAllocation
|
||||||
|
|
||||||
|
r.x = C.int(c.x)
|
||||||
|
r.y = C.int(c.y)
|
||||||
|
r.width = C.int(c.width)
|
||||||
|
r.height = C.int(c.height)
|
||||||
|
C.gtk_widget_size_allocate(w.widget, &r)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *widgetbase) getAuxResizeInfo(d *sizing) {
|
func (w *widgetbase) getAuxResizeInfo(d *sizing) {
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
|
|
||||||
// #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);
|
// extern void windowResizing(GtkWidget *, GdkRectangle *, gpointer);
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
type window struct {
|
type window struct {
|
||||||
|
@ -53,9 +53,13 @@ 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(
|
// we connect to the layout's size-allocate, not to the window's configure-event
|
||||||
C.gpointer(unsafe.Pointer(w.window)),
|
// this allows us to handle client-side decoration-based configurations (such as GTK+ on Wayland) properly
|
||||||
"configure-event",
|
// also see commitResize() in sizing_unix.go for additional notes
|
||||||
|
// thanks to many people in irc.gimp.net/#gtk+ for help (including tristan for suggesting g_signal_connect_after())
|
||||||
|
g_signal_connect_after(
|
||||||
|
C.gpointer(unsafe.Pointer(layoutw)),
|
||||||
|
"size-allocate",
|
||||||
C.GCallback(C.windowResizing),
|
C.GCallback(C.windowResizing),
|
||||||
C.gpointer(unsafe.Pointer(w)))
|
C.gpointer(unsafe.Pointer(w)))
|
||||||
// TODO size
|
// TODO size
|
||||||
|
@ -161,12 +165,8 @@ func windowClosing(wid *C.GtkWidget, e *C.GdkEvent, data C.gpointer) C.gboolean
|
||||||
}
|
}
|
||||||
|
|
||||||
//export windowResizing
|
//export windowResizing
|
||||||
func windowResizing(wid *C.GtkWidget, event *C.GdkEvent, data C.gpointer) C.gboolean {
|
func windowResizing(wid *C.GtkWidget, r *C.GdkRectangle, data C.gpointer) {
|
||||||
w := (*window)(unsafe.Pointer(data))
|
w := (*window)(unsafe.Pointer(data))
|
||||||
e := (*C.GdkEventConfigure)(unsafe.Pointer(event))
|
w.doresize(int(r.width), int(r.height))
|
||||||
w.doresize(int(e.width), int(e.height))
|
fmt.Printf("new size %d x %d\n", r.width, r.height)
|
||||||
// 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
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue