gtk-ng: attach surface size callbacks AFTER realize

The `gdk.Surface` is only ever available *after* the window had been
first presented and mapped. Trying to get the surface during `init`
like what we had previously done will **always** return null.
This commit is contained in:
Leah Amelia Chen
2025-08-20 03:23:35 +08:00
parent 0930b2daff
commit 7977b3695a

View File

@@ -301,24 +301,6 @@ pub const Window = extern struct {
// Initialize our actions
self.initActionMap();
// We need to setup resize notifications on our surface
if (self.as(gtk.Native).getSurface()) |gdk_surface| {
_ = gobject.Object.signals.notify.connect(
gdk_surface,
*Self,
propGdkSurfaceWidth,
self,
.{ .detail = "width" },
);
_ = gobject.Object.signals.notify.connect(
gdk_surface,
*Self,
propGdkSurfaceHeight,
self,
.{ .detail = "height" },
);
}
// Start states based on config.
if (priv.config) |config_obj| {
const config = config_obj.get();
@@ -1124,6 +1106,25 @@ pub const Window = extern struct {
return;
}
// We need to setup resize notifications on our surface,
// which is only available after the window had been realized.
if (self.as(gtk.Native).getSurface()) |gdk_surface| {
_ = gobject.Object.signals.notify.connect(
gdk_surface,
*Self,
propGdkSurfaceWidth,
self,
.{ .detail = "width" },
);
_ = gobject.Object.signals.notify.connect(
gdk_surface,
*Self,
propGdkSurfaceHeight,
self,
.{ .detail = "height" },
);
}
// When we are realized we always setup our appearance since this
// calls some winproto functions.
self.syncAppearance();