From 5fe599437ab9d1d9cfa749e861ce2f3acc02aa3c Mon Sep 17 00:00:00 2001 From: srdusr <99972264+srdusr@users.noreply.github.com> Date: Mon, 29 Jul 2024 14:01:00 +0200 Subject: 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. --- crates/config/src/engine/workspace.rs | 42 +++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 crates/config/src/engine/workspace.rs (limited to 'crates/config/src/engine/workspace.rs') diff --git a/crates/config/src/engine/workspace.rs b/crates/config/src/engine/workspace.rs new file mode 100644 index 0000000..a51e108 --- /dev/null +++ b/crates/config/src/engine/workspace.rs @@ -0,0 +1,42 @@ +use super::*; + +impl Engine { + // ---- srd.workspace.* --------------------------------------------------- + + pub(super) fn fn_workspace_cycle(&self, forward: bool) -> Result> { + let state = self.state.clone(); + Ok(self.lua.create_function(move |_, ()| { + let wm = state.borrow().wm.clone(); + let mut wm = wm.borrow_mut(); + let ids: Vec<_> = wm.workspaces().iter().map(|w| w.id).collect(); + if ids.is_empty() { + return Ok(()); + } + let cur = wm.current_workspace(); + let pos = ids.iter().position(|&id| id == cur).unwrap_or(0); + let next = if forward { (pos + 1) % ids.len() } else { (pos + ids.len() - 1) % ids.len() }; + wm.switch_workspace(ids[next]); + Ok(()) + })?) + } + + pub(super) fn fn_workspace_switch(&self) -> Result> { + let state = self.state.clone(); + Ok(self.lua.create_function(move |_, id: usize| { + state.borrow().wm.borrow_mut().switch_workspace(id); + Ok(()) + })?) + } + + pub(super) fn fn_workspace_move_window(&self) -> Result> { + let state = self.state.clone(); + Ok(self.lua.create_function(move |_, id: usize| { + let wm = state.borrow().wm.clone(); + let mut wm = wm.borrow_mut(); + if let Some(focused) = wm.focused_id() { + wm.move_window_to_workspace(focused, id); + } + Ok(()) + })?) + } +} -- cgit v1.2.3