diff options
| author | srdusr <[email protected]> | 2024-07-29 14:01:00 +0200 |
|---|---|---|
| committer | srdusr <[email protected]> | 2024-07-29 14:01:00 +0200 |
| commit | 5fe599437ab9d1d9cfa749e861ce2f3acc02aa3c (patch) | |
| tree | 2956b9b18af7b6c0741da8b68da18de66ed393e5 /crates/config/src/engine/layout.rs | |
| parent | 6fad44b3ecffb22f77a78661ce179b304e9a6ccc (diff) | |
| download | srdwm-5fe599437ab9d1d9cfa749e861ce2f3acc02aa3c.tar.gz srdwm-5fe599437ab9d1d9cfa749e861ce2f3acc02aa3c.zip | |
Split crates/config/src/lib.rs (1441 lines) into engine/
Pure reorganization, no behavior change - verified by diffing the
function-name and struct/enum-name sets before/after (both identical)
plus a full cargo test pass. lib.rs is now a thin shim (mod
declarations + pub use) since a crate root can't itself become a
directory; all the actual content moved into engine/, split along the
Lua API's own srd.*/srd.window.*/srd.layout.*/srd.workspace.*/
srd.theme.* namespace groupings the file's own section comments
already used:
- mod.rs: SharedState, Engine, ConfigError, and Engine's core methods
(new/get/set/dispatch/reload/...).
- register.rs: register_srd_module, which wires every fn_* builder
from every other file into the srd Lua table - the one place that
genuinely needs to see all of them.
- general.rs/window.rs/layout.rs/workspace.rs/theme.rs: the fn_*
builder methods themselves, one file per srd.* sub-namespace.
- support.rs: free functions shared across those (do_reload,
parse_direction, flatten_table_into, validate, default_config) and
the WindowAction enum.
- tests.rs: the ~300-line test module, left unsplit for the same
shared-helper reason manager/tests.rs and udev's tests were.
~40 fn_* methods and the support.rs free functions/enum went from
private to pub(super): called across what are now sibling submodules,
which Rust's privacy model doesn't let see each other's private items.
Diffstat (limited to 'crates/config/src/engine/layout.rs')
| -rw-r--r-- | crates/config/src/engine/layout.rs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/crates/config/src/engine/layout.rs b/crates/config/src/engine/layout.rs new file mode 100644 index 0000000..ebdb317 --- /dev/null +++ b/crates/config/src/engine/layout.rs @@ -0,0 +1,32 @@ +use super::*; +use super::support::flatten_table_into; + +impl Engine { + // ---- srd.layout.* ------------------------------------------------------ + + pub(super) fn fn_layout_set(&self) -> Result<mlua::Function<'_>> { + let state = self.state.clone(); + Ok(self.lua.create_function(move |_, name: String| { + let wm = state.borrow().wm.clone(); + let mut wm = wm.borrow_mut(); + let ws = wm.current_workspace(); + wm.set_layout(ws, name); + wm.arrange_workspace(ws); + Ok(()) + })?) + } + + pub(super) fn fn_layout_configure(&self) -> Result<mlua::Function<'_>> { + let state = self.state.clone(); + Ok(self.lua.create_function(move |_, (name, table): (String, Table)| { + let mut s = state.borrow_mut(); + flatten_table_into(&format!("layout.{name}"), &table, &mut s.values)?; + let master_ratio = s.values.get(&format!("layout.{name}.master_ratio")).and_then(|v| v.as_f64()); + drop(s); + if let Some(ratio) = master_ratio { + state.borrow().wm.borrow_mut().tiling.master_ratio = ratio as f32; + } + Ok(()) + })?) + } +} |