diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2025-01-11 23:58:05 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-11 15:58:05 +0000 |
| commit | 3b85690aa6d9c14bb926692e25cc4480b85200ab (patch) | |
| tree | 481cf8f136a61aeb5429280e8dccd240cbf99668 /src | |
| parent | cef09fbfe6624d2133d81be863bd48bcfc5939d3 (diff) | |
config: add exec(-onec) with rules and execr(-once) (#8953)
Diffstat (limited to 'src')
| -rw-r--r-- | src/config/ConfigManager.cpp | 51 | ||||
| -rw-r--r-- | src/config/ConfigManager.hpp | 10 |
2 files changed, 56 insertions, 5 deletions
diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 299dfbc3..60723220 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -130,6 +130,18 @@ static void configHandleGapDestroy(void** data) { delete reinterpret_cast<CCssGapData*>(*data); } +static Hyprlang::CParseResult handleExec(const char* c, const char* v) { + const std::string VALUE = v; + const std::string COMMAND = c; + + const auto RESULT = g_pConfigManager->handleExec(COMMAND, VALUE); + + Hyprlang::CParseResult result; + if (RESULT.has_value()) + result.setError(RESULT.value().c_str()); + return result; +} + static Hyprlang::CParseResult handleRawExec(const char* c, const char* v) { const std::string VALUE = v; const std::string COMMAND = c; @@ -154,6 +166,18 @@ static Hyprlang::CParseResult handleExecOnce(const char* c, const char* v) { return result; } +static Hyprlang::CParseResult handleExecRawOnce(const char* c, const char* v) { + const std::string VALUE = v; + const std::string COMMAND = c; + + const auto RESULT = g_pConfigManager->handleExecRawOnce(COMMAND, VALUE); + + Hyprlang::CParseResult result; + if (RESULT.has_value()) + result.setError(RESULT.value().c_str()); + return result; +} + static Hyprlang::CParseResult handleExecShutdown(const char* c, const char* v) { const std::string VALUE = v; const std::string COMMAND = c; @@ -666,8 +690,10 @@ CConfigManager::CConfigManager() { m_pConfig->addSpecialConfigValue("device", "active_area_size", Hyprlang::VEC2{0, 0}); // only for tablets // keywords - m_pConfig->registerHandler(&::handleRawExec, "exec", {false}); + m_pConfig->registerHandler(&::handleExec, "exec", {false}); + m_pConfig->registerHandler(&::handleRawExec, "execr", {false}); m_pConfig->registerHandler(&::handleExecOnce, "exec-once", {false}); + m_pConfig->registerHandler(&::handleExecRawOnce, "execr-once", {false}); m_pConfig->registerHandler(&::handleExecShutdown, "exec-shutdown", {false}); m_pConfig->registerHandler(&::handleMonitor, "monitor", {false}); m_pConfig->registerHandler(&::handleBind, "bind", {true}); @@ -1441,7 +1467,7 @@ void CConfigManager::dispatchExecOnce() { isLaunchingExecOnce = true; for (auto const& c : firstExecRequests) { - handleRawExec("", c); + c.withRules ? handleExec("", c.exec) : handleRawExec("", c.exec); } firstExecRequests.clear(); // free some kb of memory :P @@ -1744,7 +1770,17 @@ std::string CConfigManager::getDefaultWorkspaceFor(const std::string& name) { std::optional<std::string> CConfigManager::handleRawExec(const std::string& command, const std::string& args) { if (isFirstLaunch) { - firstExecRequests.push_back(args); + firstExecRequests.push_back({args, false}); + return {}; + } + + g_pKeybindManager->spawnRaw(args); + return {}; +} + +std::optional<std::string> CConfigManager::handleExec(const std::string& command, const std::string& args) { + if (isFirstLaunch) { + firstExecRequests.push_back({args, true}); return {}; } @@ -1754,7 +1790,14 @@ std::optional<std::string> CConfigManager::handleRawExec(const std::string& comm std::optional<std::string> CConfigManager::handleExecOnce(const std::string& command, const std::string& args) { if (isFirstLaunch) - firstExecRequests.push_back(args); + firstExecRequests.push_back({args, true}); + + return {}; +} + +std::optional<std::string> CConfigManager::handleExecRawOnce(const std::string& command, const std::string& args) { + if (isFirstLaunch) + firstExecRequests.push_back({args, false}); return {}; } diff --git a/src/config/ConfigManager.hpp b/src/config/ConfigManager.hpp index 53772401..a27ee7ab 100644 --- a/src/config/ConfigManager.hpp +++ b/src/config/ConfigManager.hpp @@ -132,6 +132,11 @@ struct SConfigOptionDescription { std::variant<SBoolData, SRangeData, SFloatData, SStringData, SColorData, SChoiceData, SGradientData, SVectorData> data; }; +struct SFirstExecRequest { + std::string exec = ""; + bool withRules = false; +}; + class CConfigManager { public: CConfigManager(); @@ -196,7 +201,9 @@ class CConfigManager { // keywords std::optional<std::string> handleRawExec(const std::string&, const std::string&); + std::optional<std::string> handleExec(const std::string&, const std::string&); std::optional<std::string> handleExecOnce(const std::string&, const std::string&); + std::optional<std::string> handleExecRawOnce(const std::string&, const std::string&); std::optional<std::string> handleExecShutdown(const std::string&, const std::string&); std::optional<std::string> handleMonitor(const std::string&, const std::string&); std::optional<std::string> handleBind(const std::string&, const std::string&); @@ -280,7 +287,8 @@ class CConfigManager { bool firstExecDispatched = false; bool m_bManualCrashInitiated = false; - std::vector<std::string> firstExecRequests; + + std::vector<SFirstExecRequest> firstExecRequests; // bool is for if with rules std::vector<std::string> finalExecRequests; std::vector<std::pair<std::string, std::string>> m_vFailedPluginConfigValues; // for plugin values of unloaded plugins |
