srdusr
aboutsummaryrefslogtreecommitdiffstats
path: root/crates/config/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/config/src')
-rw-r--r--crates/config/src/engine/general.rs7
-rw-r--r--crates/config/src/engine/mod.rs17
-rw-r--r--crates/config/src/engine/support.rs4
3 files changed, 26 insertions, 2 deletions
diff --git a/crates/config/src/engine/general.rs b/crates/config/src/engine/general.rs
index 68b441e..7c22747 100644
--- a/crates/config/src/engine/general.rs
+++ b/crates/config/src/engine/general.rs
@@ -8,7 +8,12 @@ impl Engine {
let state = self.state.clone();
Ok(self.lua.create_function(move |_, (key, value): (String, Value)| {
if let Some(v) = ConfigValue::from_lua(&value) {
- state.borrow_mut().values.insert(key, v);
+ let mut s = state.borrow_mut();
+ // Recorded so a reload can tell "the config states this"
+ // from "this is just the seeded default" - see
+ // `SharedState::config_set_keys`.
+ s.config_set_keys.insert(key.clone());
+ s.values.insert(key, v);
}
Ok(())
})?)
diff --git a/crates/config/src/engine/mod.rs b/crates/config/src/engine/mod.rs
index 8facd56..1dd3c35 100644
--- a/crates/config/src/engine/mod.rs
+++ b/crates/config/src/engine/mod.rs
@@ -35,6 +35,17 @@ struct SharedState {
/// `WindowManager` by `main.rs` and served over IPC as
/// `srd keybindings`.
key_descriptions: HashMap<String, String>,
+ /// Every key the *config* set via `srd.set`, as opposed to a seeded
+ /// default. Cleared and rebuilt on each load, so it always describes
+ /// the config currently in force.
+ ///
+ /// `values` alone cannot answer this: defaults are seeded into it
+ /// before any script runs, so every key looks set. The distinction
+ /// matters because a config file stating a value must be able to
+ /// override a live `srd set` when it is reloaded - otherwise a
+ /// setting changed at runtime can never be corrected from the config
+ /// again.
+ config_set_keys: std::collections::HashSet<String>,
/// Combos registered with `srd.bind_repeat`, which fire repeatedly while
/// held (Hyprland's `binde`). A subset of `key_bindings`.
repeat_keys: std::collections::HashSet<String>,
@@ -77,6 +88,7 @@ impl Engine {
values: default_config(),
key_bindings: HashMap::new(),
key_descriptions: HashMap::new(),
+ config_set_keys: std::collections::HashSet::new(),
repeat_keys: std::collections::HashSet::new(),
event_handlers: HashMap::new(),
config_dir: config_dir.into(),
@@ -195,6 +207,11 @@ impl Engine {
}
}
+ /// Keys the loaded config explicitly set - see `config_set_keys`.
+ pub fn config_set_keys(&self) -> Vec<String> {
+ self.state.borrow().config_set_keys.iter().cloned().collect()
+ }
+
pub fn bound_keys(&self) -> Vec<String> {
self.state.borrow().key_bindings.keys().cloned().collect()
}
diff --git a/crates/config/src/engine/support.rs b/crates/config/src/engine/support.rs
index 9d81035..b0c8caf 100644
--- a/crates/config/src/engine/support.rs
+++ b/crates/config/src/engine/support.rs
@@ -34,10 +34,11 @@ pub(super) fn do_reload(lua: &Lua, state: &Rc<RefCell<SharedState>>) -> Result<(
std::mem::take(&mut s.event_handlers),
std::mem::take(&mut s.repeat_keys),
std::mem::take(&mut s.key_descriptions),
+ std::mem::take(&mut s.config_set_keys),
);
(s.config_dir.clone(), previous)
};
- let restore = |state: &Rc<RefCell<SharedState>>, previous: (_, _, _, _)| {
+ let restore = |state: &Rc<RefCell<SharedState>>, previous: (_, _, _, _, _)| {
let mut s = state.borrow_mut();
// Whatever the failed run managed to register before erroring is
// discarded, not merged: half of a broken config is not a config.
@@ -45,6 +46,7 @@ pub(super) fn do_reload(lua: &Lua, state: &Rc<RefCell<SharedState>>) -> Result<(
s.event_handlers = previous.1;
s.repeat_keys = previous.2;
s.key_descriptions = previous.3;
+ s.config_set_keys = previous.4;
};
let path = config_dir.join("init.lua");
let src = match std::fs::read_to_string(&path) {