Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exec(-onec) with rules and execr(-once) #8953

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
i
  • Loading branch information
littleblack111 committed Jan 9, 2025
commit a30b52ba1d787cdb15bc16690a032ba0301a1bed
51 changes: 47 additions & 4 deletions src/config/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -664,8 +688,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});
Expand Down Expand Up @@ -1439,7 +1465,7 @@ void CConfigManager::dispatchExecOnce() {
isLaunchingExecOnce = true;

for (auto const& c : firstExecRequests) {
handleRawExec("", c);
c.second ? handleExec("", c.first) : handleRawExec("", c.first);
}

firstExecRequests.clear(); // free some kb of memory :P
Expand Down Expand Up @@ -1742,7 +1768,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 {};
}

Expand All @@ -1752,7 +1788,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 {};
}
Expand Down
4 changes: 3 additions & 1 deletion src/config/ConfigManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,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&);
Expand Down Expand Up @@ -280,7 +282,7 @@ class CConfigManager {

bool firstExecDispatched = false;
bool m_bManualCrashInitiated = false;
std::vector<std::string> firstExecRequests;
std::vector<std::pair<std::string, bool>> 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
Expand Down