diff options
| author | srdusr <[email protected]> | 2026-04-28 16:22:00 +0200 |
|---|---|---|
| committer | srdusr <[email protected]> | 2026-04-28 16:22:00 +0200 |
| commit | 3ea84a31ee671b88d8c343b3007de0e975eff31c (patch) | |
| tree | 6fd62a55370069dfb3e798bf816bc0da9c1fbf27 /crates/core/src/manager/lock.rs | |
| parent | c4dc99cc3211c4dc1a461f228402be1593b883c9 (diff) | |
| download | srdwm-3ea84a31ee671b88d8c343b3007de0e975eff31c.tar.gz srdwm-3ea84a31ee671b88d8c343b3007de0e975eff31c.zip | |
Stop a config reload from undoing a change the user just made by hand
Reloading rebuilds the theme and general settings from the config file.
That is right for a file edit, but it also wiped every live `srd set` - and
the titlebar right-click menu's "Customize" rows are built entirely out of
live `srd set`s. Changing a button style from that menu and then saving
init.lua for any unrelated reason silently reverted it.
Survivable while reloads only happened on Mod4+Ctrl+r. The reload-on-write
support added in the previous commit 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, so this is a defect rather than a
documented quirk. The AGS peer session reached the same conclusion from the
other side while deciding whether to build Settings controls against these
values, and would have had to label them session-only.
Every setting changed live is recorded on the WindowManager as key -> raw
JSON text, and replayed after each reload through the very same handle_set
that applied it, so a replayed setting cannot behave differently from a real
one. Recorded only on success, so a rejected value is never replayed, and
only for real client calls, so the replay cannot rewrite what it is reading.
Last write wins per key. Raw JSON text because core has no serde dependency
and no reason to gain one for this; the platform crate parses it back.
Verified live in a nested compositor: set button_side left and button_mode
fixed, saved an unrelated config edit, both survived, and the log reported
re-applying two live settings. Three tests cover the round trip, the
rejected-value case and the one-entry-per-key case.
A live value is still a session override rather than a persisted setting.
That distinction is now written down in DEFAULTS.md instead of being a trap.
515 tests pass, clippy clean.
Diffstat (limited to 'crates/core/src/manager/lock.rs')
| -rw-r--r-- | crates/core/src/manager/lock.rs | 16 |
1 files changed, 16 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)] |