From 37ba0529135e4def7d749c534893b777711b5845 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 11 Sep 2024 10:42:36 -0700 Subject: [PATCH] apprt/gtk: cleaup final notebook page on libadw 1.3.x --- src/apprt/gtk/adwaita.zig | 12 +++++++++--- src/apprt/gtk/notebook.zig | 14 +++++++++++++- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/apprt/gtk/adwaita.zig b/src/apprt/gtk/adwaita.zig index 0543bdfa7..f2d6bcfdd 100644 --- a/src/apprt/gtk/adwaita.zig +++ b/src/apprt/gtk/adwaita.zig @@ -43,7 +43,13 @@ pub fn versionAtLeast( // We use the functions instead of the constants such as // c.ADW_MINOR_VERSION because the function gets the actual // runtime version. - return c.adw_get_major_version() >= major and - c.adw_get_minor_version() >= minor and - c.adw_get_micro_version() >= micro; + if (c.adw_get_major_version() >= major) { + if (c.adw_get_major_version() > major) return true; + if (c.adw_get_minor_version() >= minor) { + if (c.adw_get_minor_version() > minor) return true; + return c.adw_get_micro_version() >= micro; + } + } + + return false; } diff --git a/src/apprt/gtk/notebook.zig b/src/apprt/gtk/notebook.zig index a2c25c2ce..8dd3a8690 100644 --- a/src/apprt/gtk/notebook.zig +++ b/src/apprt/gtk/notebook.zig @@ -275,8 +275,20 @@ pub const Notebook = union(enum) { c.adw_tab_view_close_page(tab_view, page); // If we have no more tabs we close the window - if (self.nPages() == 0) + if (self.nPages() == 0) { + // libadw versions <= 1.3.x leak the final page view + // which causes our surface to not properly cleanup. We + // unref to force the cleanup. This will trigger a critical + // warning from GTK, but I don't know any other workaround. + // Note: I'm not actually sure if 1.4.0 contains the fix, + // I just know that 1.3.x is broken and 1.5.1 is fixed. + // If we know that 1.4.0 is fixed, we can change this. + if (!adwaita.versionAtLeast(1, 4, 0)) { + c.g_object_unref(tab.box); + } + c.gtk_window_destroy(tab.window.window); + } }, .gtk_notebook => |notebook| { const page = c.gtk_notebook_get_page(notebook, @ptrCast(tab.box)) orelse return;