apprt/gtk: cleaup final notebook page on libadw 1.3.x

This commit is contained in:
Mitchell Hashimoto
2024-09-11 10:42:36 -07:00
parent 2b5d436792
commit 37ba052913
2 changed files with 22 additions and 4 deletions

View File

@ -43,7 +43,13 @@ pub fn versionAtLeast(
// We use the functions instead of the constants such as // We use the functions instead of the constants such as
// c.ADW_MINOR_VERSION because the function gets the actual // c.ADW_MINOR_VERSION because the function gets the actual
// runtime version. // runtime version.
return c.adw_get_major_version() >= major and if (c.adw_get_major_version() >= major) {
c.adw_get_minor_version() >= minor and if (c.adw_get_major_version() > major) return true;
c.adw_get_micro_version() >= micro; 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;
} }

View File

@ -275,8 +275,20 @@ pub const Notebook = union(enum) {
c.adw_tab_view_close_page(tab_view, page); c.adw_tab_view_close_page(tab_view, page);
// If we have no more tabs we close the window // 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); c.gtk_window_destroy(tab.window.window);
}
}, },
.gtk_notebook => |notebook| { .gtk_notebook => |notebook| {
const page = c.gtk_notebook_get_page(notebook, @ptrCast(tab.box)) orelse return; const page = c.gtk_notebook_get_page(notebook, @ptrCast(tab.box)) orelse return;