diff options
Diffstat (limited to 'crates/core/src')
| -rw-r--r-- | crates/core/src/manager/lock.rs | 16 | ||||
| -rw-r--r-- | crates/core/src/manager/mod.rs | 24 |
2 files changed, 40 insertions, 0 deletions
diff --git a/crates/core/src/manager/lock.rs b/crates/core/src/manager/lock.rs index 0ffe0ca..15c0a9f 100644 --- a/crates/core/src/manager/lock.rs +++ b/crates/core/src/manager/lock.rs @@ -51,6 +51,22 @@ impl WindowManager { pub fn drain_refresh_request(&mut self) -> bool { std::mem::take(&mut self.refresh_requested) } + + /// Records that `key` was set live to `value_json`. See + /// `live_settings`' own doc comment. + /// + /// Last write wins, so setting the same key twice leaves one entry and + /// the replay applies each key exactly once. + pub fn record_live_setting(&mut self, key: &str, value_json: String) { + self.live_settings.insert(key.to_string(), value_json); + } + + /// Every live setting recorded so far, for replay after a config + /// reload. Cloned rather than borrowed: the replay mutates the same + /// `WindowManager` this came from. + pub fn live_settings(&self) -> Vec<(String, String)> { + self.live_settings.iter().map(|(k, v)| (k.clone(), v.clone())).collect() + } } #[cfg(test)] diff --git a/crates/core/src/manager/mod.rs b/crates/core/src/manager/mod.rs index 7454ce2..e778a32 100644 --- a/crates/core/src/manager/mod.rs +++ b/crates/core/src/manager/mod.rs @@ -437,6 +437,29 @@ pub struct WindowManager { /// Set by `request_refresh`, drained by the main loop. Same /// cross-boundary queued-request shape as `lock_requested`. refresh_requested: bool, + /// Every setting changed live since startup, as `srd set` key -> the + /// raw JSON text of its value, in insertion-independent key order. + /// + /// Exists so a config reload does not silently undo a change the user + /// just made by hand. `apply_general_settings` rebuilds the whole + /// `ThemeConfig` and general-settings block from the config file, which + /// is the correct precedence for a *file* edit - but it also wiped + /// every live `srd set`, and the titlebar right-click menu's own + /// "Customize" section is built entirely out of live `srd set`s. So + /// changing a button style from that menu and then saving `init.lua` + /// for any unrelated reason silently reverted it. + /// + /// That was survivable while reloads only happened on an explicit + /// `Mod4+Ctrl+r`. `general.config_reload_on_write` makes a reload + /// happen on every save, which turns a rare surprise into a reliable + /// one - a control that silently reverts is worse than no control. + /// + /// Raw JSON text rather than a typed value because this crate has no + /// serde dependency and no business gaining one for this; the platform + /// crate parses it back and replays it through the same `handle_set` + /// that recorded it, so a replayed setting cannot diverge from a real + /// one. `BTreeMap` for a deterministic replay order. + live_settings: std::collections::BTreeMap<String, String>, drag: Option<DragState>, resize: Option<ResizeState>, rules: Vec<WindowRule>, @@ -601,6 +624,7 @@ impl WindowManager { theme: ThemeConfig::default(), lock: LockConfig::default(), refresh_requested: false, + live_settings: std::collections::BTreeMap::new(), drag: None, resize: None, rules: Vec::new(), |