From 8110bb2773b6c841029a51eca7971f42a36f480c Mon Sep 17 00:00:00 2001 From: srdusr <99972264+srdusr@users.noreply.github.com> Date: Tue, 2 Apr 2024 00:58:00 +0200 Subject: 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. --- legacy-cpp/src/config/lua_manager.h | 166 ++++++++++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) create mode 100644 legacy-cpp/src/config/lua_manager.h (limited to 'legacy-cpp/src/config/lua_manager.h') 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 +#include +#include +#include +#include +#include + +// 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; + +// 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 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 get_bound_keys() const; + + // Layout system + bool configure_layout(const std::string& layout_name, const std::map& config); + bool configure_layout(const std::string& layout_name, const std::map& config); + bool register_custom_layout(const std::string& name, const std::string& lua_function); + std::vector 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& colors); + bool set_theme_decorations(const std::map& 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 get_theme_colors() const; + + // SRDWindow rules + bool add_window_rule(const std::map& rule); + bool remove_window_rule(const std::string& rule_name); + std::vector> get_window_rules() const; + + // Utility functions + bool execute_lua_code(const std::string& code); + bool validate_lua_syntax(const std::string& code); + std::vector get_lua_errors() const; + + // Configuration validation + bool validate_config() const; + std::vector 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 config_values_; + std::map key_bindings_; + std::vector lua_errors_; + std::vector 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 g_lua_manager; + +#endif // SRDWM_LUA_MANAGER_H + + -- cgit v1.2.3