Skip to content

Commit 0f2f0ab

Browse files
authored
Update Adwaita version check for Box unref (#6796)
As of Adwaita 1.5.0, the GTK Box is not being properly unref'd when the parent window is closed. Update the conditional to account for this. Also add a couple of missing unref()s in errdefers. This fixes an issue where Ghostty would not properly quit after closing the last surface. #3807 is related (though I'm not sure it's the exact same problem).
2 parents ee78a3d + 946c0c3 commit 0f2f0ab

File tree

3 files changed

+4
-5
lines changed

3 files changed

+4
-5
lines changed

src/apprt/gtk/Surface.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ pub fn init(self: *Surface, app: *App, opts: Options) !void {
370370

371371
// Create an overlay so we can layer the GL area with other widgets.
372372
const overlay = gtk.Overlay.new();
373+
errdefer overlay.unref();
373374
const overlay_widget = overlay.as(gtk.Widget);
374375
overlay.setChild(gl_area_widget);
375376

src/apprt/gtk/Tab.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ pub fn init(self: *Tab, window: *Window, parent_: ?*CoreSurface) !void {
6464
// box makes it easier to maintain the tab contents because we never need to
6565
// change the root widget of the notebook page (tab).
6666
const box = gtk.Box.new(.vertical, 0);
67+
errdefer box.unref();
6768
const box_widget = box.as(gtk.Widget);
6869
box_widget.setHexpand(1);
6970
box_widget.setVexpand(1);

src/apprt/gtk/TabView.zig

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,14 +209,11 @@ pub fn closeTab(self: *TabView, tab: *Tab) void {
209209

210210
// If we have no more tabs we close the window
211211
if (self.nPages() == 0) {
212-
// libadw versions <= 1.3.x leak the final page view
212+
// libadw versions < 1.5.1 leak the final page view
213213
// which causes our surface to not properly cleanup. We
214214
// unref to force the cleanup. This will trigger a critical
215215
// warning from GTK, but I don't know any other workaround.
216-
// Note: I'm not actually sure if 1.4.0 contains the fix,
217-
// I just know that 1.3.x is broken and 1.5.1 is fixed.
218-
// If we know that 1.4.0 is fixed, we can change this.
219-
if (!adwaita.versionAtLeast(1, 4, 0)) {
216+
if (!adwaita.versionAtLeast(1, 5, 1)) {
220217
const box: *gtk.Box = @ptrCast(@alignCast(tab.box));
221218
box.as(gobject.Object).unref();
222219
}

0 commit comments

Comments
 (0)