srdusr
aboutsummaryrefslogtreecommitdiffstats
path: root/crates/config/src/engine/register.rs
diff options
context:
space:
mode:
authorsrdusr <[email protected]>2024-07-29 14:01:00 +0200
committersrdusr <[email protected]>2024-07-29 14:01:00 +0200
commit5fe599437ab9d1d9cfa749e861ce2f3acc02aa3c (patch)
tree2956b9b18af7b6c0741da8b68da18de66ed393e5 /crates/config/src/engine/register.rs
parent6fad44b3ecffb22f77a78661ce179b304e9a6ccc (diff)
downloadsrdwm-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/register.rs')
-rw-r--r--crates/config/src/engine/register.rs97
1 files changed, 97 insertions, 0 deletions
diff --git a/crates/config/src/engine/register.rs b/crates/config/src/engine/register.rs
new file mode 100644
index 0000000..d68d253
--- /dev/null
+++ b/crates/config/src/engine/register.rs
@@ -0,0 +1,97 @@
+use super::*;
+use super::support::WindowAction;
+
+impl Engine {
+ pub(super) fn register_srd_module(&self) -> Result<()> {
+ let lua = &self.lua;
+ let srd = lua.create_table()?;
+
+ srd.set("set", self.fn_set()?)?;
+ srd.set("get", self.fn_get()?)?;
+ srd.set("reset", self.fn_reset()?)?;
+ srd.set("reset_all", self.fn_reset_all()?)?;
+ srd.set("reset_category", self.fn_reset_category()?)?;
+ srd.set("bind", self.fn_bind()?)?;
+ srd.set("bind_repeat", self.fn_bind_repeat()?)?;
+ srd.set("on", self.fn_on()?)?;
+ srd.set("rule", self.fn_rule()?)?;
+ srd.set("load", self.fn_load()?)?;
+ srd.set("spawn", self.fn_spawn()?)?;
+ srd.set("notify", self.fn_notify()?)?;
+ srd.set("quit", self.fn_quit()?)?;
+ srd.set("reload", self.fn_reload()?)?;
+ srd.set("validate_config", self.fn_validate_config()?)?;
+
+ let debug = lua.create_table()?;
+ debug.set("config_status", self.fn_debug_config_status()?)?;
+ debug.set("validate_config", self.fn_validate_config()?)?;
+ debug.set("show_settings", self.fn_debug_show_settings()?)?;
+ debug.set("profile_start", self.fn_debug_profile_start()?)?;
+ debug.set("profile_stop", self.fn_debug_profile_stop()?)?;
+ srd.set("debug", debug)?;
+
+ let window = lua.create_table()?;
+ window.set("focused", self.fn_window_focused()?)?;
+ window.set("close", self.fn_window_action(WindowAction::Close)?)?;
+ window.set("minimize", self.fn_window_action(WindowAction::Minimize)?)?;
+ window.set("maximize", self.fn_window_action(WindowAction::Maximize)?)?;
+ window.set("fullscreen", self.fn_window_action(WindowAction::Fullscreen)?)?;
+ window.set("toggle_pin", self.fn_window_action(WindowAction::TogglePin)?)?;
+ window.set("focus", self.fn_window_focus_direction()?)?;
+ window.set("move", self.fn_window_move_direction()?)?;
+ window.set("next", self.fn_window_cycle(true)?)?;
+ window.set("prev", self.fn_window_cycle(false)?)?;
+ window.set("set_decorations", self.fn_window_set_decorations()?)?;
+ window.set("set_border_color", self.fn_window_set_border_color()?)?;
+ window.set("set_border_width", self.fn_window_set_border_width()?)?;
+ window.set("set_opacity", self.fn_window_set_opacity()?)?;
+ window.set("set_floating", self.fn_window_set_floating()?)?;
+ window.set("toggle_floating", self.fn_window_action(WindowAction::ToggleFloating)?)?;
+ window.set("is_floating", self.fn_window_is_floating()?)?;
+ // `srd.window.scratchpad()` moves the *focused* window into the
+ // scratchpad pool, hiding it (sway's `move scratchpad`).
+ // `srd.window.scratchpad_show()` toggles pool visibility and takes
+ // no target of its own - deliberately not routed through
+ // `fn_window_action`'s focused-window gate, since showing a hidden
+ // scratchpad window has to work even when nothing is currently
+ // focused (an empty workspace, or focus on a different monitor).
+ // See `WindowManager::scratchpad_show`'s doc comment.
+ window.set("scratchpad", self.fn_window_action(WindowAction::ScratchpadAdd)?)?;
+ window.set("scratchpad_show", self.fn_scratchpad_show()?)?;
+ srd.set("window", window)?;
+
+ let layout = lua.create_table()?;
+ layout.set("set", self.fn_layout_set()?)?;
+ layout.set("configure", self.fn_layout_configure()?)?;
+ srd.set("layout", layout)?;
+
+ let workspace = lua.create_table()?;
+ workspace.set("next", self.fn_workspace_cycle(true)?)?;
+ workspace.set("prev", self.fn_workspace_cycle(false)?)?;
+ workspace.set("switch", self.fn_workspace_switch()?)?;
+ workspace.set("move_window", self.fn_workspace_move_window()?)?;
+ srd.set("workspace", workspace)?;
+
+ let theme = lua.create_table()?;
+ theme.set("set_colors", self.fn_theme_set("theme.colors")?)?;
+ theme.set("set_decorations", self.fn_theme_set("theme.decorations")?)?;
+ srd.set("theme", theme)?;
+
+ // Expose `srd` both as a global and as a `require("srd")`-able
+ // module: `require` resolves through `package.preload`/`package.path`,
+ // never through globals, so config files that (reasonably) write
+ // `local srd = require("srd")` would otherwise get a "module not
+ // found" error despite `srd` existing as a global.
+ let package: Table = lua.globals().get("package")?;
+ let preload: Table = package.get("preload")?;
+ preload.set(
+ "srd",
+ lua.create_function(|lua, ()| {
+ let srd: Table = lua.globals().get("srd")?;
+ Ok(srd)
+ })?,
+ )?;
+ lua.globals().set("srd", srd)?;
+ Ok(())
+ }
+}