RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process
Keep a replaced config alive until Settings has rebuilt its page
oxydizer4276a869fa1c
diff --git a/src/config_runtime/watcher.zig b/src/config_runtime/watcher.zigindex 5d6fe0b..3451230 100644--- a/src/config_runtime/watcher.zig+++ b/src/config_runtime/watcher.zig@@ -98,7 +98,9 @@ pub fn applyLoadedConfig(server: *Server, new_cfg: loader.Config) void {var old = server.config;server.config = new_cfg;@import("apply.zig").applyDiff(server, old, new_cfg);- old.deinit();+ // The open Settings page was built from `old` and is rebuilt on its next+ // frame (or after a drag): it keeps `old` until then.+ if (server.input.open_control_center) |cc| cc.retireConfig(&old) else old.deinit();server.config_generation += 1;server.config_reload_error = null;@import("../ipc/events.zig").onConfigLoaded(server);diff --git a/src/control_center/ControlCenter.zig b/src/control_center/ControlCenter.zigindex 608c06c..2035863 100644--- a/src/control_center/ControlCenter.zig+++ b/src/control_center/ControlCenter.zig@@ -96,6 +96,10 @@ page: Page = .general,built_page: ?Page = null,pending_page: ?Page = null,refresh_pending: bool = false,+/// Configs replaced since the page was last built. The tree's strings (the+/// start logo's file name, a font family) point into their arenas, so each+/// is freed only once a rebuild has dropped those pointers (`retireConfig`).+retired_configs: std.ArrayList(@import("config").loader.Config) = .empty,pointer_down: bool = false,/// The window is activated; keys arrive only with `hasKeyboardFocus`.focused: bool = false,@@ -257,6 +261,8 @@ pub fn destroy(cc: *ControlCenter) void {appearance_section.deinit(&cc.appearance);cc.appearance.arena.deinit();cc.appearance.font_arena.deinit();+ @import("tree.zig").releaseRetired(cc);+ cc.retired_configs.deinit(gpa);cc.background.deinit(gpa);// The buffer node belongs to the window's tree and may outlive this// in the close animation's snapshot pass: unhook it from us first.@@ -353,6 +359,7 @@ pub fn resize(cc: *ControlCenter, width: i32, height: i32) void {const cc_tree = @import("tree.zig");pub const buildTree = cc_tree.buildTree;pub const append = cc_tree.append;+pub const retireConfig = cc_tree.retireConfig;pub const buildGeneral = cc_tree.buildGeneral;pub const buildDevices = cc_tree.buildDevices;diff --git a/src/control_center/tree.zig b/src/control_center/tree.zigindex 6c7a9ad..9bfcc77 100644--- a/src/control_center/tree.zig+++ b/src/control_center/tree.zig@@ -2,6 +2,7 @@const i18n = @import("i18n");const std = @import("std");+const gpa = @import("../main.zig").gpa;const ui = @import("ui");const layout = ui.layout;const Widget = layout.Widget;@@ -55,6 +56,7 @@ pub fn buildTree(cc: *ControlCenter) void {cc.root.linkParents();cc.built_page = cc.page;cc.refresh_pending = false;+ releaseRetired(cc);return;}cc.search.capture();@@ -280,6 +282,23 @@ pub fn buildTree(cc: *ControlCenter) void {cc.search.built_empty = cc.search.empty();cc.built_page = cc.page;cc.refresh_pending = false;+ releaseRetired(cc);+}++/// Takes over a replaced config that the open page may still point into, and+/// asks for the rebuild that drops those pointers. Rebuilding here would run+/// inside whatever widget callback reloaded the config.+pub fn retireConfig(cc: *ControlCenter, old: *@import("config").loader.Config) void {+ cc.retired_configs.append(gpa, old.*) catch {+ old.deinit();+ return;+ };+ cc.refresh();+}++pub fn releaseRetired(cc: *ControlCenter) void {+ for (cc.retired_configs.items) |*old| old.deinit();+ cc.retired_configs.clearRetainingCapacity();}pub fn append(cc: *ControlCenter, widget: Widget) void {