From 0c68eaf99faf5d61bcbdb7781894fd06cd576aa3 Mon Sep 17 00:00:00 2001 From: Jasson Date: Wed, 10 Jul 2024 03:15:43 -0400 Subject: [PATCH] Comments in configs folder and template handler function --- hyprctl/main.cpp | 3 - src/config/ConfigDataValues.hpp | 118 ++++++++-- src/config/ConfigManager.cpp | 342 +++++++++++++++------------- src/config/ConfigManager.hpp | 49 ++-- src/config/ConfigValue.hpp | 58 ++++- src/desktop/LayerSurface.cpp | 13 +- src/layout/DwindleLayout.cpp | 2 +- src/layout/MasterLayout.cpp | 6 +- src/layout/MasterLayout.hpp | 6 +- src/managers/input/InputManager.cpp | 9 +- 10 files changed, 400 insertions(+), 206 deletions(-) diff --git a/hyprctl/main.cpp b/hyprctl/main.cpp index 45fe9142..1e413ba0 100644 --- a/hyprctl/main.cpp +++ b/hyprctl/main.cpp @@ -1,4 +1,3 @@ -#include #include #include #include @@ -10,7 +9,6 @@ #include #include #include -#include #include #include #include @@ -22,7 +20,6 @@ #include #include #include -#include #include #include #include diff --git a/src/config/ConfigDataValues.hpp b/src/config/ConfigDataValues.hpp index 322bd14a..5cf8042e 100644 --- a/src/config/ConfigDataValues.hpp +++ b/src/config/ConfigDataValues.hpp @@ -1,48 +1,89 @@ #pragma once #include "../defines.hpp" -#include "../helpers/varlist/VarList.hpp" #include +#include +/** +* @enum eConfigValueDataTypes +* @brief Enumerates the possible data types for configuration values. +*/ enum eConfigValueDataTypes { CVD_TYPE_INVALID = -1, CVD_TYPE_GRADIENT = 0, CVD_TYPE_CSS_VALUE = 1 }; +/** +* @class ICustomConfigValueData +* @brief Abstract base class for custom configuration value data. +*/ class ICustomConfigValueData { public: + /** @brief Virtual destructor. */ virtual ~ICustomConfigValueData() = 0; + /** + * @brief Get the data type of the custom configuration value. + * @return The data type. + */ virtual eConfigValueDataTypes getDataType() = 0; - virtual std::string toString() = 0; + /** + * @brief Convert the custom configuration value to a string. + * @return The string representation of the value. + */ + virtual std::string toString() = 0; }; +/** + * @class CGradientValueData + * @brief Represents gradient configuration value data. + */ class CGradientValueData : public ICustomConfigValueData { public: - CGradientValueData(){}; + /** @brief Default constructor. */ + CGradientValueData() {}; + + /** + * @brief Constructor with initial color. + * @param col Initial color. + */ CGradientValueData(CColor col) { m_vColors.push_back(col); }; - virtual ~CGradientValueData(){}; + /** @brief Destructor. */ + virtual ~CGradientValueData() {}; + + /** + * @brief Get the data type of the gradient value. + * @return The data type (CVD_TYPE_GRADIENT). + */ virtual eConfigValueDataTypes getDataType() { return CVD_TYPE_GRADIENT; } + /** + * @brief Reset the gradient with a single color. + * @param col The color to reset the gradient to. + */ void reset(CColor col) { m_vColors.clear(); m_vColors.emplace_back(col); m_fAngle = 0; } - /* Vector containing the colors */ + /** @brief Vector containing the colors */ std::vector m_vColors; - /* Float corresponding to the angle (rad) */ + /** @brief Float representing the angle (in radians). */ float m_fAngle = 0; - // + /** + * @brief Equality operator for comparing gradient values. + * @param other The other gradient value to compare with. + * @return True if equal, false otherwise. + */ bool operator==(const CGradientValueData& other) const { if (other.m_vColors.size() != m_vColors.size() || m_fAngle != other.m_fAngle) return false; @@ -54,6 +95,10 @@ class CGradientValueData : public ICustomConfigValueData { return true; } + /** + * @brief Convert the gradient value to a string. + * @return The string representation of the gradient value. + */ virtual std::string toString() { std::string result; for (auto& c : m_vColors) { @@ -65,13 +110,44 @@ class CGradientValueData : public ICustomConfigValueData { } }; +/** + * @class CCssGapData + * @brief Represents CSS gap configuration value data. + */ class CCssGapData : public ICustomConfigValueData { public: - CCssGapData() : top(0), right(0), bottom(0), left(0){}; - CCssGapData(int64_t global) : top(global), right(global), bottom(global), left(global){}; - CCssGapData(int64_t vertical, int64_t horizontal) : top(vertical), right(horizontal), bottom(vertical), left(horizontal){}; - CCssGapData(int64_t top, int64_t horizontal, int64_t bottom) : top(top), right(horizontal), bottom(bottom), left(horizontal){}; - CCssGapData(int64_t top, int64_t right, int64_t bottom, int64_t left) : top(top), right(right), bottom(bottom), left(left){}; + /** @brief Default constructor. */ + CCssGapData() : top(0), right(0), bottom(0), left(0) {}; + + /** + * @brief Constructor with global gap size. + * @param global The global gap size. + */ + CCssGapData(int64_t global) : top(global), right(global), bottom(global), left(global) {}; + + /** + * @brief Constructor with vertical and horizontal gap sizes. + * @param vertical The vertical gap size. + * @param horizontal The horizontal gap size. + */ + CCssGapData(int64_t vertical, int64_t horizontal) : top(vertical), right(horizontal), bottom(vertical), left(horizontal) {}; + + /** + * @brief Constructor with top, horizontal, and bottom gap sizes. + * @param top The top gap size. + * @param horizontal The horizontal gap size. + * @param bottom The bottom gap size. + */ + CCssGapData(int64_t top, int64_t horizontal, int64_t bottom) : top(top), right(horizontal), bottom(bottom), left(horizontal) {}; + + /** + * @brief Constructor with top, right, bottom, and left gap sizes. + * @param top The top gap size. + * @param right The right gap size. + * @param bottom The bottom gap size. + * @param left The left gap size. + */ + CCssGapData(int64_t top, int64_t right, int64_t bottom, int64_t left) : top(top), right(right), bottom(bottom), left(left) {}; /* Css like directions */ int64_t top; @@ -79,7 +155,11 @@ class CCssGapData : public ICustomConfigValueData { int64_t bottom; int64_t left; - void parseGapData(CVarList varlist) { + /** + * @brief Parses gap data from a variable list. + * @param varlist The variable list to parse. + */ + void parseGapData(Hyprutils::String::CVarList varlist) { switch (varlist.size()) { case 1: { *this = CCssGapData(std::stoi(varlist[0])); @@ -105,6 +185,10 @@ class CCssGapData : public ICustomConfigValueData { } } + /** + * @brief Reset the gaps to a global size. + * @param global The global gap size. + */ void reset(int64_t global) { top = global; right = global; @@ -112,10 +196,18 @@ class CCssGapData : public ICustomConfigValueData { left = global; } + /** + * @brief Get the data type of the CSS gap value. + * @return The data type (CVD_TYPE_CSS_VALUE). + */ virtual eConfigValueDataTypes getDataType() { return CVD_TYPE_CSS_VALUE; } + /** + * @brief Convert the CSS gap value to a string. + * @return The string representation of the CSS gap value. + */ virtual std::string toString() { return std::format("{} {} {} {}", top, right, bottom, left); } diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 12f3ac22..e314ab37 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -3,11 +3,13 @@ #include "../render/decorations/CHyprGroupBarDecoration.hpp" #include "config/ConfigDataValues.hpp" -#include "helpers/varlist/VarList.hpp" #include "../protocols/LayerShell.hpp" +#include "config/defaultConfig.hpp" #include #include +#include +#include #include #include #include @@ -25,8 +27,14 @@ #include using namespace Hyprutils::String; -extern "C" char** environ; +extern "C" char** environ; +/** +* @brief Parses a gradient configuration value and sets it to the provided data. +* @param VALUE The string representation of the gradient value. +* @param data Pointer to the gradient data. +* @return CParseResult object indicating the success or failure of the operation. +*/ static Hyprlang::CParseResult configHandleGradientSet(const char* VALUE, void** data) { std::string V = VALUE; @@ -81,11 +89,21 @@ static Hyprlang::CParseResult configHandleGradientSet(const char* VALUE, void** return result; } +/** +* @brief Destroys the gradient configuration data. +* @param data Pointer to the gradient data. +*/ static void configHandleGradientDestroy(void** data) { if (*data) delete reinterpret_cast(*data); } +/** +* @brief Parses a gap configuration value and sets it to the provided data. +* @param VALUE The string representation of the gap value. +* @param data Pointer to the gap data. +* @return CParseResult object indicating the success or failure of the operation. +*/ static Hyprlang::CParseResult configHandleGapSet(const char* VALUE, void** data) { std::string V = VALUE; @@ -106,209 +124,204 @@ static Hyprlang::CParseResult configHandleGapSet(const char* VALUE, void** data) return result; } +/** +* @brief Destroys the gap configuration data. +* @param data Pointer to the gap data. +*/ static void configHandleGapDestroy(void** data) { if (*data) delete reinterpret_cast(*data); } +/** +* @brief Template function to handle command parsing and execution. +* @param c The command. +* @param v The value. +* @param handler Function pointer to the specific handler in the ConfigManager. +* @return CParseResult object indicating the success or failure of the operation. +*/ +template +static Hyprlang::CParseResult handleCommand(const char* c, const char* v, Handler handler) { + const std::string VALUE = v; + const std::string COMMAND = c; + + const auto RESULT = (g_pConfigManager.get()->*handler)(COMMAND, VALUE); + + Hyprlang::CParseResult result; + if (RESULT.has_value()) + result.setError(RESULT.value().c_str()); + return result; +} +/** +* @brief Handles raw execution commands from the configuration. +* @param c The command. +* @param v The value. +* @return CParseResult object indicating the success or failure of the operation. +*/ static Hyprlang::CParseResult handleRawExec(const char* c, const char* v) { - const std::string VALUE = v; - const std::string COMMAND = c; - - const auto RESULT = g_pConfigManager->handleRawExec(COMMAND, VALUE); - - Hyprlang::CParseResult result; - if (RESULT.has_value()) - result.setError(RESULT.value().c_str()); - return result; + return handleCommand(c, v, &CConfigManager::handleRawExec); } +/** +* @brief Handles exec-once commands from the configuration. +* @param c The command. +* @param v The value. +* @return CParseResult object indicating the success or failure of the operation. +*/ static Hyprlang::CParseResult handleExecOnce(const char* c, const char* v) { - const std::string VALUE = v; - const std::string COMMAND = c; - - const auto RESULT = g_pConfigManager->handleExecOnce(COMMAND, VALUE); - - Hyprlang::CParseResult result; - if (RESULT.has_value()) - result.setError(RESULT.value().c_str()); - return result; + return handleCommand(c, v, &CConfigManager::handleExecOnce); } +/** +* @brief Handles monitor commands from the configuration. +* @param c The command. +* @param v The value. +* @return CParseResult object indicating the success or failure of the operation. +*/ static Hyprlang::CParseResult handleMonitor(const char* c, const char* v) { - const std::string VALUE = v; - const std::string COMMAND = c; - - const auto RESULT = g_pConfigManager->handleMonitor(COMMAND, VALUE); - - Hyprlang::CParseResult result; - if (RESULT.has_value()) - result.setError(RESULT.value().c_str()); - return result; + return handleCommand(c, v, &CConfigManager::handleMonitor); } +/** +* @brief Handles Bezier curve commands from the configuration. +* @param c The command. +* @param v The value. +* @return CParseResult object indicating the success or failure of the operation. +*/ static Hyprlang::CParseResult handleBezier(const char* c, const char* v) { - const std::string VALUE = v; - const std::string COMMAND = c; - - const auto RESULT = g_pConfigManager->handleBezier(COMMAND, VALUE); - - Hyprlang::CParseResult result; - if (RESULT.has_value()) - result.setError(RESULT.value().c_str()); - return result; + return handleCommand(c, v, &CConfigManager::handleBezier); } +/** +* @brief Handles animation commands from the configuration. +* @param c The command. +* @param v The value. +* @return CParseResult object indicating the success or failure of the operation. +*/ static Hyprlang::CParseResult handleAnimation(const char* c, const char* v) { - const std::string VALUE = v; - const std::string COMMAND = c; - - const auto RESULT = g_pConfigManager->handleAnimation(COMMAND, VALUE); - - Hyprlang::CParseResult result; - if (RESULT.has_value()) - result.setError(RESULT.value().c_str()); - return result; + return handleCommand(c, v, &CConfigManager::handleAnimation); } +/** +* @brief Handles keybind commands from the configuration. +* @param c The command. +* @param v The value. +* @return CParseResult object indicating the success or failure of the operation. +*/ static Hyprlang::CParseResult handleBind(const char* c, const char* v) { - const std::string VALUE = v; - const std::string COMMAND = c; - - const auto RESULT = g_pConfigManager->handleBind(COMMAND, VALUE); - - Hyprlang::CParseResult result; - if (RESULT.has_value()) - result.setError(RESULT.value().c_str()); - return result; + return handleCommand(c, v, &CConfigManager::handleBind); } +/** +* @brief Handles unbind commands from the configuration. +* @param c The command. +* @param v The value. +* @return CParseResult object indicating the success or failure of the operation. +*/ static Hyprlang::CParseResult handleUnbind(const char* c, const char* v) { - const std::string VALUE = v; - const std::string COMMAND = c; - - const auto RESULT = g_pConfigManager->handleUnbind(COMMAND, VALUE); - - Hyprlang::CParseResult result; - if (RESULT.has_value()) - result.setError(RESULT.value().c_str()); - return result; + return handleCommand(c, v, &CConfigManager::handleUnbind); } +/** +* @brief Handles window rule commands from the configuration. +* @param c The command. +* @param v The value. +* @return CParseResult object indicating the success or failure of the operation. +*/ static Hyprlang::CParseResult handleWindowRule(const char* c, const char* v) { - const std::string VALUE = v; - const std::string COMMAND = c; - - const auto RESULT = g_pConfigManager->handleWindowRule(COMMAND, VALUE); - - Hyprlang::CParseResult result; - if (RESULT.has_value()) - result.setError(RESULT.value().c_str()); - return result; + return handleCommand(c, v, &CConfigManager::handleWindowRule); } +/** +* @brief Handles layer rule commands from the configuration. +* @param c The command. +* @param v The value. +* @return CParseResult object indicating the success or failure of the operation. +*/ static Hyprlang::CParseResult handleLayerRule(const char* c, const char* v) { - const std::string VALUE = v; - const std::string COMMAND = c; - - const auto RESULT = g_pConfigManager->handleLayerRule(COMMAND, VALUE); - - Hyprlang::CParseResult result; - if (RESULT.has_value()) - result.setError(RESULT.value().c_str()); - return result; + return handleCommand(c, v, &CConfigManager::handleLayerRule); } +/** + * @brief Handles window rule version 2 commands from the configuration. + * @param c The command. + * @param v The value. + * @return CParseResult object indicating the success or failure of the operation. + */ static Hyprlang::CParseResult handleWindowRuleV2(const char* c, const char* v) { - const std::string VALUE = v; - const std::string COMMAND = c; - - const auto RESULT = g_pConfigManager->handleWindowRuleV2(COMMAND, VALUE); - - Hyprlang::CParseResult result; - if (RESULT.has_value()) - result.setError(RESULT.value().c_str()); - return result; + return handleCommand(c, v, &CConfigManager::handleWindowRuleV2); } +/** + * @brief Handles blur layer shell commands from the configuration. + * @param c The command. + * @param v The value. + * @return CParseResult object indicating the success or failure of the operation. + */ static Hyprlang::CParseResult handleBlurLS(const char* c, const char* v) { - const std::string VALUE = v; - const std::string COMMAND = c; - - const auto RESULT = g_pConfigManager->handleBlurLS(COMMAND, VALUE); - - Hyprlang::CParseResult result; - if (RESULT.has_value()) - result.setError(RESULT.value().c_str()); - return result; + return handleCommand(c, v, &CConfigManager::handleBlurLS); } +/** + * @brief Handles workspace rule commands from the configuration. + * @param c The command. + * @param v The value. + * @return CParseResult object indicating the success or failure of the operation. + */ static Hyprlang::CParseResult handleWorkspaceRules(const char* c, const char* v) { - const std::string VALUE = v; - const std::string COMMAND = c; - - const auto RESULT = g_pConfigManager->handleWorkspaceRules(COMMAND, VALUE); - - Hyprlang::CParseResult result; - if (RESULT.has_value()) - result.setError(RESULT.value().c_str()); - return result; + return handleCommand(c, v, &CConfigManager::handleWorkspaceRules); } +/** + * @brief Handles submap commands from the configuration. + * @param c The command. + * @param v The value. + * @return CParseResult object indicating the success or failure of the operation. + */ static Hyprlang::CParseResult handleSubmap(const char* c, const char* v) { - const std::string VALUE = v; - const std::string COMMAND = c; - - const auto RESULT = g_pConfigManager->handleSubmap(COMMAND, VALUE); - - Hyprlang::CParseResult result; - if (RESULT.has_value()) - result.setError(RESULT.value().c_str()); - return result; + return handleCommand(c, v, &CConfigManager::handleSubmap); } +/** + * @brief Handles source commands from the configuration. + * @param c The command. + * @param v The value. + * @return CParseResult object indicating the success or failure of the operation. + */ static Hyprlang::CParseResult handleSource(const char* c, const char* v) { - const std::string VALUE = v; - const std::string COMMAND = c; - - const auto RESULT = g_pConfigManager->handleSource(COMMAND, VALUE); - - Hyprlang::CParseResult result; - if (RESULT.has_value()) - result.setError(RESULT.value().c_str()); - return result; + return handleCommand(c, v, &CConfigManager::handleSource); } +/** + * @brief Handles environment variable commands from the configuration. + * @param c The command. + * @param v The value. + * @return CParseResult object indicating the success or failure of the operation. + */ static Hyprlang::CParseResult handleEnv(const char* c, const char* v) { - const std::string VALUE = v; - const std::string COMMAND = c; - - const auto RESULT = g_pConfigManager->handleEnv(COMMAND, VALUE); - - Hyprlang::CParseResult result; - if (RESULT.has_value()) - result.setError(RESULT.value().c_str()); - return result; + return handleCommand(c, v, &CConfigManager::handleEnv); } +/** + * @brief Handles plugin commands from the configuration. + * @param c The command. + * @param v The value. + * @return CParseResult object indicating the success or failure of the operation. + */ static Hyprlang::CParseResult handlePlugin(const char* c, const char* v) { - const std::string VALUE = v; - const std::string COMMAND = c; - - const auto RESULT = g_pConfigManager->handlePlugin(COMMAND, VALUE); - - Hyprlang::CParseResult result; - if (RESULT.has_value()) - result.setError(RESULT.value().c_str()); - return result; + return handleCommand(c, v, &CConfigManager::handlePlugin); } +/** @brief Constructs a CConfigManager object, initializes configuration settings, and sets default values. */ CConfigManager::CConfigManager() { const auto ERR = verifyConfigExists(); - configPaths.emplace_back(getMainConfigPath()); + configPaths.emplace_back(getMainConfigPath()); // Add the main configuration path to configPaths + + // Initialize the m_pConfig object with the main config path and configuration options m_pConfig = std::make_unique(configPaths.begin()->c_str(), Hyprlang::SConfigOptions{.throwAllErrors = true, .allowMissingConfig = true}); + // Add general configuration values m_pConfig->addConfigValue("general:sensitivity", {1.0f}); m_pConfig->addConfigValue("general:apply_sens_to_raw", Hyprlang::INT{0}); m_pConfig->addConfigValue("general:border_size", Hyprlang::INT{1}); @@ -325,6 +338,7 @@ CConfigManager::CConfigManager() { m_pConfig->addConfigValue("general:allow_tearing", Hyprlang::INT{0}); m_pConfig->addConfigValue("general:resize_corner", Hyprlang::INT{0}); + // Add miscellaneous configuration values m_pConfig->addConfigValue("misc:disable_hyprland_logo", Hyprlang::INT{0}); m_pConfig->addConfigValue("misc:disable_splash_rendering", Hyprlang::INT{0}); m_pConfig->addConfigValue("misc:col.splash", Hyprlang::INT{0x55ffffff}); @@ -355,6 +369,7 @@ CConfigManager::CConfigManager() { m_pConfig->addConfigValue("misc:initial_workspace_tracking", Hyprlang::INT{1}); m_pConfig->addConfigValue("misc:middle_click_paste", Hyprlang::INT{1}); + // Add group-related configuration values m_pConfig->addConfigValue("group:insert_after_current", Hyprlang::INT{1}); m_pConfig->addConfigValue("group:focus_removed_window", Hyprlang::INT{1}); m_pConfig->addConfigValue("group:groupbar:enabled", Hyprlang::INT{1}); @@ -368,6 +383,7 @@ CConfigManager::CConfigManager() { m_pConfig->addConfigValue("group:groupbar:text_color", Hyprlang::INT{0xffffffff}); m_pConfig->addConfigValue("group:groupbar:stacked", Hyprlang::INT{0}); + // Add debug configuration values m_pConfig->addConfigValue("debug:int", Hyprlang::INT{0}); m_pConfig->addConfigValue("debug:log_damage", Hyprlang::INT{0}); m_pConfig->addConfigValue("debug:overlay", Hyprlang::INT{0}); @@ -384,6 +400,7 @@ CConfigManager::CConfigManager() { m_pConfig->addConfigValue("debug:disable_scale_checks", Hyprlang::INT{0}); m_pConfig->addConfigValue("debug:colored_stdout_logs", Hyprlang::INT{1}); + // Add decoration-related configuration values m_pConfig->addConfigValue("decoration:rounding", Hyprlang::INT{0}); m_pConfig->addConfigValue("decoration:blur:enabled", Hyprlang::INT{1}); m_pConfig->addConfigValue("decoration:blur:size", Hyprlang::INT{8}); @@ -554,7 +571,7 @@ CConfigManager::CConfigManager() { m_pConfig->addConfigValue("group:groupbar:col.locked_active", Hyprlang::CConfigCustomValueType{&configHandleGradientSet, configHandleGradientDestroy, "0x66ff5500"}); m_pConfig->addConfigValue("group:groupbar:col.locked_inactive", Hyprlang::CConfigCustomValueType{&configHandleGradientSet, configHandleGradientDestroy, "0x66775500"}); - // devices + // Devices m_pConfig->addSpecialCategory("device", {"name"}); m_pConfig->addSpecialConfigValue("device", "sensitivity", {0.F}); m_pConfig->addSpecialConfigValue("device", "accel_profile", {STRVAL_EMPTY}); @@ -590,7 +607,7 @@ CConfigManager::CConfigManager() { m_pConfig->addSpecialConfigValue("device", "active_area_position", Hyprlang::VEC2{0, 0}); // only for tablets m_pConfig->addSpecialConfigValue("device", "active_area_size", Hyprlang::VEC2{0, 0}); // only for tablets - // keywords + // Keywords m_pConfig->registerHandler(&::handleRawExec, "exec", {false}); m_pConfig->registerHandler(&::handleExecOnce, "exec-once", {false}); m_pConfig->registerHandler(&::handleMonitor, "monitor", {false}); @@ -627,6 +644,11 @@ CConfigManager::CConfigManager() { g_pHyprError->queueCreate(ERR.value(), CColor{1.0, 0.1, 0.1, 1.0}); } +/** + * @brief Retrieves the configuration directory path. + * @return The absolute path to the configuration directory. + * @throws std::runtime_error if neither HOME nor XDG_CONFIG_HOME is set. + */ std::string CConfigManager::getConfigDir() { static const char* xdgConfigHome = getenv("XDG_CONFIG_HOME"); @@ -641,6 +663,10 @@ std::string CConfigManager::getConfigDir() { return home + std::string("/.config"); } +/** +* @brief Retrieves the main configuration file path. +* @return The absolute path to the main configuration file. +*/ std::string CConfigManager::getMainConfigPath() { if (!g_pCompositor->explicitConfigPath.empty()) return g_pCompositor->explicitConfigPath; @@ -648,6 +674,10 @@ std::string CConfigManager::getMainConfigPath() { return getConfigDir() + "/hypr/" + (ISDEBUG ? "hyprlandd.conf" : "hyprland.conf"); } +/** + * @brief Retrieves concatenated string contents of all configuration files specified in `configPaths`. + * @return A string containing concatenated contents of all configuration files. + */ const std::string CConfigManager::getConfigString() { std::string configString; std::string currFileContent; @@ -667,10 +697,15 @@ const std::string CConfigManager::getConfigString() { return configString; } +/** + * @brief Retrieves the current configuration errors as a string. + * @return A string containing current configuration errors. + */ std::string CConfigManager::getErrors() { return m_szConfigErrors; } +/** @brief Reloads the configuration. */ void CConfigManager::reload() { EMIT_HOOK_EVENT("preConfigReload", nullptr); setDefaultAnimationVars(); @@ -680,6 +715,7 @@ void CConfigManager::reload() { postConfigReload(ERR); } +/** @brief Initializes default animation variables if it's the first launch. */ void CConfigManager::setDefaultAnimationVars() { if (isFirstLaunch) { INITANIMCFG("global"); @@ -1082,7 +1118,7 @@ std::vector CConfigManager::getMatchingRules(PHLWINDOW pWindow, boo if (!valid(pWindow)) return std::vector(); - // if the window is unmapped, don't process exec rules yet. + // Adjust shadowExec based on window mapping status shadowExec = shadowExec || !pWindow->m_bIsMapped; std::vector returns; @@ -1092,11 +1128,11 @@ std::vector CConfigManager::getMatchingRules(PHLWINDOW pWindow, boo Debug::log(LOG, "Searching for matching rules for {} (title: {})", appidclass, title); - // since some rules will be applied later, we need to store some flags + // Since some rules will be applied later, we need to store some flags bool hasFloating = pWindow->m_bIsFloating; bool hasFullscreen = pWindow->m_bIsFullscreen; - // local tags for dynamic tag rule match + // Local tags for dynamic tag rule match auto tags = pWindow->m_tags; for (auto& rule : m_dWindowRules) { @@ -2571,4 +2607,4 @@ std::optional CConfigManager::handlePlugin(const std::string& comma m_vDeclaredPlugins.push_back(path); return {}; -} +} \ No newline at end of file diff --git a/src/config/ConfigManager.hpp b/src/config/ConfigManager.hpp index c43cb020..e5986b45 100644 --- a/src/config/ConfigManager.hpp +++ b/src/config/ConfigManager.hpp @@ -3,32 +3,31 @@ #define CONFIG_MANAGER_H #include -#include "../debug/Log.hpp" #include #include "../defines.hpp" #include #include -#include -#include #include -#include #include #include "../helpers/WLClasses.hpp" #include "../helpers/Monitor.hpp" -#include "../helpers/varlist/VarList.hpp" #include "../desktop/Window.hpp" #include "../desktop/LayerSurface.hpp" -#include "defaultConfig.hpp" #include "ConfigDataValues.hpp" #include +// Macros for initializing and creating animation configurations #define INITANIMCFG(name) animationConfig[name] = {} #define CREATEANIMCFG(name, parent) animationConfig[name] = {false, "", "", 0.f, -1, &animationConfig["global"], &animationConfig[parent]} #define HANDLE void* +/** + * @struct SWorkspaceRule + * @brief Configuration rules for workspaces. + */ struct SWorkspaceRule { std::string monitor = ""; std::string workspaceString = ""; @@ -48,6 +47,10 @@ struct SWorkspaceRule { std::map layoutopts; }; +/** + * @struct SMonitorAdditionalReservedArea + * @brief Reserved areas for monitors. + */ struct SMonitorAdditionalReservedArea { int top = 0; int bottom = 0; @@ -55,6 +58,10 @@ struct SMonitorAdditionalReservedArea { int right = 0; }; +/** + * @struct SAnimationPropertyConfig + * @brief Configuration for animation properties. + */ struct SAnimationPropertyConfig { bool overridden = true; @@ -67,22 +74,38 @@ struct SAnimationPropertyConfig { SAnimationPropertyConfig* pParentAnimation = nullptr; }; +/** + * @struct SPluginKeyword + * @brief Stores plugin keyword information. + */ struct SPluginKeyword { HANDLE handle = 0; std::string name = ""; Hyprlang::PCONFIGHANDLERFUNC fn = nullptr; }; +/** + * @struct SPluginVariable + * @brief Stores plugin variable information. + */ struct SPluginVariable { HANDLE handle = 0; std::string name = ""; }; +/** + * @struct SExecRequestedRule + * @brief Stores rules requested with exec. + */ struct SExecRequestedRule { std::string szRule = ""; uint64_t iPid = 0; }; +/** + * @class CConfigManager + * @brief Manages configuration settings. + */ class CConfigManager { public: CConfigManager(); @@ -147,7 +170,7 @@ class CConfigManager { void handlePluginLoads(); std::string getErrors(); - // keywords + // Keywords std::optional handleRawExec(const std::string&, const std::string&); std::optional handleExecOnce(const std::string&, const std::string&); std::optional handleMonitor(const std::string&, const std::string&); @@ -171,14 +194,14 @@ class CConfigManager { private: std::unique_ptr m_pConfig; - std::deque configPaths; // stores all the config paths - std::unordered_map configModifyTimes; // stores modify times + std::deque configPaths; // Stores all the config paths + std::unordered_map configModifyTimes; // Stores modify times - std::unordered_map animationConfig; // stores all the animations with their set values + std::unordered_map animationConfig; // Stores all the animations with their set values std::string m_szCurrentSubmap = ""; // For storing the current keybind submap - std::vector execRequestedRules; // rules requested with exec, e.g. [workspace 2] kitty + std::vector execRequestedRules; // Rules requested with exec, e.g. [workspace 2] kitty std::vector m_vDeclaredPlugins; std::vector pluginKeywords; @@ -196,10 +219,10 @@ class CConfigManager { bool m_bManualCrashInitiated = false; std::deque firstExecRequests; - std::vector> m_vFailedPluginConfigValues; // for plugin values of unloaded plugins + std::vector> m_vFailedPluginConfigValues; // For plugin values of unloaded plugins std::string m_szConfigErrors = ""; - // internal methods + // Internal methods void setAnimForChildren(SAnimationPropertyConfig* const); void updateBlurredLS(const std::string&, const bool); void setDefaultAnimationVars(); diff --git a/src/config/ConfigValue.hpp b/src/config/ConfigValue.hpp index fc8abb4b..12c2c009 100644 --- a/src/config/ConfigValue.hpp +++ b/src/config/ConfigValue.hpp @@ -3,24 +3,36 @@ #include #include #include -#include "../debug/Log.hpp" #include "../macros.hpp" #include "ConfigManager.hpp" +/** + * @class CConfigValue + * @brief A template class to handle configuration values. + * + * This class provides a type-safe way to access configuration values. + * It supports custom types defined in Hyprlang. + * + * @tparam T Type of the configuration value. + */ template class CConfigValue { public: + /** + * @brief Constructor that initializes the configuration value. + * @param val The key to look up the configuration value. + */ CConfigValue(const std::string& val) { const auto PVHYPRLANG = g_pConfigManager->getHyprlangConfigValuePtr(val); p_ = PVHYPRLANG->getDataStaticPtr(); #ifdef HYPRLAND_DEBUG - // verify type + // Verify type during debug mode const auto ANY = PVHYPRLANG->getValue(); const auto TYPE = std::type_index(ANY.type()); - // exceptions + // Handle specific type exceptions const bool STRINGEX = (typeid(T) == typeid(std::string) && TYPE == typeid(Hyprlang::STRING)); const bool CUSTOMEX = (typeid(T) == typeid(Hyprlang::CUSTOMTYPE) && (TYPE == typeid(Hyprlang::CUSTOMTYPE*) || TYPE == typeid(void*) /* dunno why it does this? */)); @@ -28,44 +40,82 @@ class CConfigValue { #endif } + /** + * @brief Returns a pointer to the configuration value. + * @return Pointer to the configuration value. + */ T* ptr() const { return *(T* const*)p_; } + /** + * @brief Dereference operator to access the configuration value. + * @return The configuration value. + */ T operator*() const { return *ptr(); } private: - void* const* p_ = nullptr; + void* const* p_ = nullptr; //< Pointer to the configuration value. }; +// Specializations for std::string + +/** + * @brief Specialization of ptr() for std::string. + * @return nullptr since this implementation is not supported. + */ template <> inline std::string* CConfigValue::ptr() const { RASSERT(false, "Impossible to implement ptr() of CConfigValue"); return nullptr; } +/** + * @brief Specialization of operator* for std::string. + * @return The configuration value as std::string. + */ template <> inline std::string CConfigValue::operator*() const { return std::string{*(Hyprlang::STRING*)p_}; } +// Specializations for Hyprlang::STRING + +/** + * @brief Specialization of ptr() for Hyprlang::STRING. + * @return Pointer to the Hyprlang::STRING configuration value. + */ template <> inline Hyprlang::STRING* CConfigValue::ptr() const { return (Hyprlang::STRING*)p_; } +/** + * @brief Specialization of operator* for Hyprlang::STRING. + * @return The Hyprlang::STRING configuration value. + */ template <> inline Hyprlang::STRING CConfigValue::operator*() const { return *(Hyprlang::STRING*)p_; } +// Specializations for Hyprlang::CUSTOMTYPE + +/** + * @brief Specialization of ptr() for Hyprlang::CUSTOMTYPE. + * @return Pointer to the Hyprlang::CUSTOMTYPE configuration value. + */ template <> inline Hyprlang::CUSTOMTYPE* CConfigValue::ptr() const { return *(Hyprlang::CUSTOMTYPE* const*)p_; } +/** + * @brief Specialization of operator* for Hyprlang::CUSTOMTYPE. + * @return The Hyprlang::CUSTOMTYPE configuration value. + */ template <> inline Hyprlang::CUSTOMTYPE CConfigValue::operator*() const { RASSERT(false, "Impossible to implement operator* of CConfigValue, use ptr()"); diff --git a/src/desktop/LayerSurface.cpp b/src/desktop/LayerSurface.cpp index 9a891531..53affb86 100644 --- a/src/desktop/LayerSurface.cpp +++ b/src/desktop/LayerSurface.cpp @@ -1,6 +1,5 @@ #include "LayerSurface.hpp" #include "../Compositor.hpp" -#include "../events/Events.hpp" #include "../protocols/LayerShell.hpp" #include "../protocols/core/Compositor.hpp" #include "../managers/SeatManager.hpp" @@ -367,12 +366,12 @@ void CLayerSurface::applyRules() { } else if (rule.rule == "dimaround") { dimAround = true; } else if (rule.rule.starts_with("xray")) { - CVarList vars{rule.rule, 0, ' '}; + Hyprutils::String::CVarList vars{rule.rule, 0, ' '}; try { xray = configStringToInt(vars[1]); } catch (...) {} } else if (rule.rule.starts_with("animation")) { - CVarList vars{rule.rule, 2, 's'}; + Hyprutils::String::CVarList vars{rule.rule, 2, 's'}; animationStyle = vars[1]; } } @@ -392,13 +391,13 @@ void CLayerSurface::startAnimation(bool in, bool instant) { if (ANIMSTYLE.starts_with("slide")) { // get closest edge - const auto MIDDLE = geometry.middle(); + const auto MIDDLE = geometry.middle(); - const auto PMONITOR = g_pCompositor->getMonitorFromVector(MIDDLE); + const auto PMONITOR = g_pCompositor->getMonitorFromVector(MIDDLE); - int force = -1; + int force = -1; - CVarList args(ANIMSTYLE, 0, 's'); + Hyprutils::String::CVarList args(ANIMSTYLE, 0, 's'); if (args.size() > 1) { const auto ARG2 = args[1]; if (ARG2 == "top") diff --git a/src/layout/DwindleLayout.cpp b/src/layout/DwindleLayout.cpp index cbeaa420..8e8e1d87 100644 --- a/src/layout/DwindleLayout.cpp +++ b/src/layout/DwindleLayout.cpp @@ -1019,7 +1019,7 @@ void CHyprDwindleLayout::alterSplitRatio(PHLWINDOW pWindow, float ratio, bool ex } std::any CHyprDwindleLayout::layoutMessage(SLayoutMessageHeader header, std::string message) { - const auto ARGS = CVarList(message, 0, ' '); + const auto ARGS = Hyprutils::String::CVarList(message, 0, ' '); if (ARGS[0] == "togglesplit") { toggleSplit(header.pWindow); } else if (ARGS[0] == "swapsplit") { diff --git a/src/layout/MasterLayout.cpp b/src/layout/MasterLayout.cpp index 965c0ed7..0fe9a0f2 100644 --- a/src/layout/MasterLayout.cpp +++ b/src/layout/MasterLayout.cpp @@ -1096,7 +1096,7 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri g_pInputManager->m_pForcedFocus.reset(); }; - CVarList vars(message, 0, ' '); + Hyprutils::String::CVarList vars(message, 0, ' '); if (vars.size() < 1 || vars[0].empty()) { Debug::log(ERR, "layoutmsg called without params"); @@ -1376,7 +1376,7 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri } // If vars is null, we use the default list -void CHyprMasterLayout::runOrientationCycle(SLayoutMessageHeader& header, CVarList* vars, int direction) { +void CHyprMasterLayout::runOrientationCycle(SLayoutMessageHeader& header, Hyprutils::String::CVarList* vars, int direction) { std::vector cycle; if (vars != nullptr) buildOrientationCycleVectorFromVars(cycle, *vars); @@ -1416,7 +1416,7 @@ void CHyprMasterLayout::buildOrientationCycleVectorFromEOperation(std::vector& cycle, CVarList& vars) { +void CHyprMasterLayout::buildOrientationCycleVectorFromVars(std::vector& cycle, Hyprutils::String::CVarList& vars) { for (size_t i = 1; i < vars.size(); ++i) { if (vars[i] == "top") { cycle.push_back(ORIENTATION_TOP); diff --git a/src/layout/MasterLayout.hpp b/src/layout/MasterLayout.hpp index 30d5b3cf..0f8fa7be 100644 --- a/src/layout/MasterLayout.hpp +++ b/src/layout/MasterLayout.hpp @@ -2,10 +2,8 @@ #include "IHyprLayout.hpp" #include "../desktop/DesktopTypes.hpp" -#include "../config/ConfigManager.hpp" #include #include -#include #include enum eFullscreenMode : int8_t; @@ -77,9 +75,9 @@ class CHyprMasterLayout : public IHyprLayout { bool m_bForceWarps = false; - void buildOrientationCycleVectorFromVars(std::vector& cycle, CVarList& vars); + void buildOrientationCycleVectorFromVars(std::vector& cycle, Hyprutils::String::CVarList& vars); void buildOrientationCycleVectorFromEOperation(std::vector& cycle); - void runOrientationCycle(SLayoutMessageHeader& header, CVarList* vars, int next); + void runOrientationCycle(SLayoutMessageHeader& header, Hyprutils::String::CVarList* vars, int next); eOrientation getDynamicOrientation(PHLWORKSPACE); int getNodesOnWorkspace(const int&); void applyNodeDataToWindow(SMasterNodeData*); diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index 9180e9cd..00e13717 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -861,7 +861,7 @@ void CInputManager::setupKeyboard(SP keeb) { keeb.get()); keeb->keyboardEvents.keymap.registerStaticListener( - [this](void* owner, std::any data) { + [](void* owner, std::any data) { auto PKEEB = ((IKeyboard*)owner)->self.lock(); const auto LAYOUT = PKEEB->getActiveLayout(); @@ -1173,7 +1173,7 @@ void CInputManager::setPointerConfigs() { } else if (ACCELPROFILE == "flat") { libinput_device_config_accel_set_profile(LIBINPUTDEV, LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT); } else if (ACCELPROFILE.starts_with("custom")) { - CVarList accelValues = {ACCELPROFILE, 0, ' '}; + Hyprutils::String::CVarList accelValues = {ACCELPROFILE, 0, ' '}; try { double accelStep = std::stod(accelValues[1]); @@ -1185,7 +1185,7 @@ void CInputManager::setPointerConfigs() { const auto CONFIG = libinput_config_accel_create(LIBINPUT_CONFIG_ACCEL_PROFILE_CUSTOM); if (!SCROLLPOINTS.empty()) { - CVarList scrollValues = {SCROLLPOINTS, 0, ' '}; + Hyprutils::String::CVarList scrollValues = {SCROLLPOINTS, 0, ' '}; try { double scrollStep = std::stod(scrollValues[0]); std::vector scrollPoints; @@ -1624,8 +1624,7 @@ void CInputManager::newSwitch(wlr_input_device* pDevice) { Debug::log(LOG, "New switch with name \"{}\" added", pDevice->name); - PNEWDEV->hyprListener_destroy.initCallback( - &pDevice->events.destroy, [&](void* owner, void* data) { destroySwitch((SSwitchDevice*)owner); }, PNEWDEV, "SwitchDevice"); + PNEWDEV->hyprListener_destroy.initCallback(&pDevice->events.destroy, [&](void* owner, void* data) { destroySwitch((SSwitchDevice*)owner); }, PNEWDEV, "SwitchDevice"); const auto PSWITCH = wlr_switch_from_input_device(pDevice);