srdusr
aboutsummaryrefslogtreecommitdiffstats
path: root/legacy-cpp/src/config/lua_manager.h
diff options
context:
space:
mode:
authorsrdusr <[email protected]>2024-04-02 00:58:00 +0200
committersrdusr <[email protected]>2024-04-02 00:58:00 +0200
commit8110bb2773b6c841029a51eca7971f42a36f480c (patch)
treeb3b364a6c0231fe408229e94dc9e25ce4562ad02 /legacy-cpp/src/config/lua_manager.h
parentd1f856edc516047575cf46f12fad2b59006363c8 (diff)
downloadsrdwm-8110bb2773b6c841029a51eca7971f42a36f480c.tar.gz
srdwm-8110bb2773b6c841029a51eca7971f42a36f480c.zip
Rewrite srdwm in Rust: working X11 and Wayland backends, Lua config
The C++ prototype (moved to legacy-cpp/) was mostly a design skeleton: X11 and Windows backends were partially real, Wayland created the wlroots object graph but never wired a single event listener, macOS was stub except monitor enumeration, and the Lua engine's srd.bind() stored a key-combo string but never the actual closure. See docs/PRIOR_ART.md for the full audit. This replaces it with a Cargo workspace: - srdwm-core: platform-independent window/workspace/monitor state, a real master-stack tiling layout, and SmartPlacement grid/cascade/ snap-to-edge placement - fixing several bugs in the C++ version (hardcoded 2-column grid, cascade that never cascaded, snap-to-edge that always returned a fixed rect). 35 unit tests. - srdwm-config: the srd Lua API via mlua, implementing the surface docs/DEFAULTS.md always documented but the C++ engine never actually built (srd.window.close()/focus(direction), srd.workspace.next(), real keybinding closures, require("srd") support). 10 unit tests. - srdwm-x11: a real reparenting WM with a drawn title bar (buttons, drag, resize), verified live under Xephyr - frame placement and client offset match srdwm-core's computed geometry exactly, and the decoration renders correctly on screen. - srdwm-wayland: a from-scratch smithay compositor (the C++ version had nothing working to port from) - runs via the winit backend, tracks xdg-shell toplevels through the same WindowManager and hit-testing code X11 uses, verified to start/render/run without crashing. Decorations are solid-color (no text yet); see docs/IMPLEMENTATION_STATUS.md for exact scope. - srdwm-windows / srdwm-macos: structured, cfg-gated designs informed by komorebi/glazewm and yabai/AeroSpace respectively (see docs/PRIOR_ART.md), honestly marked as unbuilt/unverified since this sandbox has no Windows or macOS target.
Diffstat (limited to 'legacy-cpp/src/config/lua_manager.h')
-rw-r--r--legacy-cpp/src/config/lua_manager.h166
1 files changed, 166 insertions, 0 deletions
diff --git a/legacy-cpp/src/config/lua_manager.h b/legacy-cpp/src/config/lua_manager.h
new file mode 100644
index 0000000..c1c22c5
--- /dev/null
+++ b/legacy-cpp/src/config/lua_manager.h
@@ -0,0 +1,166 @@
+#ifndef SRDWM_LUA_MANAGER_H
+#define SRDWM_LUA_MANAGER_H
+
+#include <memory>
+#include <string>
+#include <vector>
+#include <map>
+#include <functional>
+#include <lua.hpp>
+
+// Forward declarations
+class SRDWindow;
+class SRDWindowManager;
+class LayoutEngine;
+
+// Include platform header for full definition
+#include "../platform/platform.h"
+
+// Include layout engine header
+#include "../layouts/layout_engine.h"
+
+// Lua callback function type
+using LuaCallback = std::function<void()>;
+
+// Lua configuration value
+struct LuaConfigValue {
+ enum class Type {
+ String,
+ Number,
+ Boolean,
+ Table,
+ Function
+ };
+
+ Type type;
+ std::string string_value;
+ double number_value;
+ bool bool_value;
+ std::map<std::string, LuaConfigValue> table_value;
+ std::string function_name;
+};
+
+// Lua manager for SRDWM
+class LuaManager {
+public:
+ LuaManager();
+ ~LuaManager();
+
+ // Initialization and cleanup
+ bool initialize();
+ void shutdown();
+
+ // Configuration loading
+ bool load_config_file(const std::string& path);
+ bool load_config_directory(const std::string& dir_path);
+ bool reload_config();
+
+ // Configuration access
+ LuaConfigValue get_config(const std::string& key) const;
+ std::string get_string(const std::string& key, const std::string& default_value = "") const;
+ int get_int(const std::string& key, int default_value = 0) const;
+ bool get_bool(const std::string& key, bool default_value = false) const;
+ double get_float(const std::string& key, double default_value = 0.0) const;
+
+ // Configuration modification
+ void set_config(const std::string& key, const LuaConfigValue& value);
+ void set_string(const std::string& key, const std::string& value);
+ void set_int(const std::string& key, int value);
+ void set_bool(const std::string& key, bool value);
+ void set_float(const std::string& key, double value);
+
+ // Key binding system
+ bool bind_key(const std::string& key_combination, const std::string& lua_function);
+ bool unbind_key(const std::string& key_combination);
+ std::vector<std::string> get_bound_keys() const;
+
+ // Layout system
+ bool configure_layout(const std::string& layout_name, const std::map<std::string, LuaConfigValue>& config);
+ bool configure_layout(const std::string& layout_name, const std::map<std::string, std::string>& config);
+ bool register_custom_layout(const std::string& name, const std::string& lua_function);
+ std::vector<std::string> get_available_layouts() const;
+ bool set_layout(int monitor_id, const std::string& layout_name);
+ std::string get_layout_name(int monitor_id) const;
+ void set_layout_engine(LayoutEngine* engine);
+
+ // Theme system
+ bool set_theme_colors(const std::map<std::string, std::string>& colors);
+ bool set_theme_decorations(const std::map<std::string, LuaConfigValue>& decorations);
+
+ // SRDWindow decoration controls
+ bool set_window_decorations(const std::string& window_id, bool enabled);
+ bool set_window_border_color(const std::string& window_id, int r, int g, int b);
+ bool set_window_border_width(const std::string& window_id, int width);
+ bool get_window_decorations(const std::string& window_id) const;
+
+ // SRDWindow state controls
+ bool set_window_floating(const std::string& window_id, bool floating);
+ bool toggle_window_floating(const std::string& window_id);
+ bool is_window_floating(const std::string& window_id) const;
+ std::map<std::string, std::string> get_theme_colors() const;
+
+ // SRDWindow rules
+ bool add_window_rule(const std::map<std::string, LuaConfigValue>& rule);
+ bool remove_window_rule(const std::string& rule_name);
+ std::vector<std::map<std::string, LuaConfigValue>> get_window_rules() const;
+
+ // Utility functions
+ bool execute_lua_code(const std::string& code);
+ bool validate_lua_syntax(const std::string& code);
+ std::vector<std::string> get_lua_errors() const;
+
+ // Configuration validation
+ bool validate_config() const;
+ std::vector<std::string> get_validation_errors() const;
+
+ // Reset functionality
+ void reset_config(const std::string& key);
+ void reset_all_configs();
+ void reset_category(const std::string& category);
+
+private:
+ lua_State* L_;
+ std::map<std::string, LuaConfigValue> config_values_;
+ std::map<std::string, std::string> key_bindings_;
+ std::vector<std::string> lua_errors_;
+ std::vector<std::string> validation_errors_;
+
+ // SRDWindow manager reference
+ SRDWindowManager* window_manager_;
+ LayoutEngine* layout_engine_;
+ Platform* platform_;
+
+ // Private methods
+ void setup_lua_environment();
+ void register_srd_module();
+ void register_window_functions();
+ void register_layout_functions();
+ void register_theme_functions();
+ void register_utility_functions();
+
+ // Configuration helpers
+ void parse_config_value(lua_State* L, int index, const std::string& key);
+ void save_config_to_lua();
+ void load_default_config();
+
+ // Error handling
+ void add_lua_error(const std::string& error);
+ void add_validation_error(const std::string& error) const;
+ void clear_errors();
+
+ // File watching
+ void setup_file_watcher();
+ void on_config_file_changed(const std::string& path);
+
+ // Helper functions
+ std::string get_config_file_path() const;
+ std::string get_default_config_path() const;
+ bool create_default_config() const;
+};
+
+// Global Lua manager instance
+extern std::unique_ptr<LuaManager> g_lua_manager;
+
+#endif // SRDWM_LUA_MANAGER_H
+
+