hyprctl: add -r argument

This commit is contained in:
Vaxry 2024-02-24 14:01:58 +00:00
parent d92da7959a
commit 6f83856025
2 changed files with 49 additions and 9 deletions

View file

@ -58,6 +58,7 @@ commands:
flags:
-j -> output in JSON
-r -> refresh state after issuing command (e.g. for updating variables)
--batch -> execute a batch of commands, separated by ';'
--instance (-i) -> use a specific instance. Can be either signature or index in hyprctl instances (0, 1, etc)
)#";
@ -305,6 +306,8 @@ int main(int argc, char** argv) {
if (ARGS[i] == "-j" && !fullArgs.contains("j")) {
fullArgs += "j";
json = true;
} else if (ARGS[i] == "-r" && !fullArgs.contains("r")) {
fullArgs += "r";
} else if (ARGS[i] == "--batch") {
fullRequest = "--batch ";
} else if (ARGS[i] == "--instance" || ARGS[i] == "-i") {

View file

@ -1476,7 +1476,8 @@ void CHyprCtl::unregisterCommand(const std::shared_ptr<SHyprCtlCommand>& cmd) {
}
std::string CHyprCtl::getReply(std::string request) {
auto format = eHyprCtlOutputFormat::FORMAT_NORMAL;
auto format = eHyprCtlOutputFormat::FORMAT_NORMAL;
bool reloadAll = false;
// process flags for non-batch requests
if (!request.starts_with("[[BATCH]]") && request.contains("/")) {
@ -1497,30 +1498,66 @@ std::string CHyprCtl::getReply(std::string request) {
if (c == 'j')
format = eHyprCtlOutputFormat::FORMAT_JSON;
if (c == 'r')
reloadAll = true;
}
if (sepIndex < request.size())
request = request.substr(sepIndex + 1); // remove flags and separator so we can compare the rest of the string
}
std::string result = "";
// parse exact cmds first, then non-exact.
for (auto& cmd : m_vCommands) {
if (!cmd->exact)
continue;
if (cmd->name == request)
return cmd->fn(format, request);
if (cmd->name == request) {
result = cmd->fn(format, request);
break;
}
}
for (auto& cmd : m_vCommands) {
if (cmd->exact)
continue;
if (result.empty())
for (auto& cmd : m_vCommands) {
if (cmd->exact)
continue;
if (request.starts_with(cmd->name))
return cmd->fn(format, request);
if (request.starts_with(cmd->name)) {
result = cmd->fn(format, request);
break;
}
}
if (result.empty())
return "unknown request";
if (reloadAll) {
g_pConfigManager->m_bWantsMonitorReload = true; // for monitor keywords
g_pInputManager->setKeyboardLayout(); // update kb layout
g_pInputManager->setPointerConfigs(); // update mouse cfgs
g_pInputManager->setTouchDeviceConfigs(); // update touch device cfgs
g_pInputManager->setTabletConfigs(); // update tablets
static auto* const PLAYOUT = (Hyprlang::STRING const*)g_pConfigManager->getConfigValuePtr("general:layout");
g_pLayoutManager->switchToLayout(*PLAYOUT); // update layout
g_pHyprOpenGL->m_bReloadScreenShader = true;
for (auto& [m, rd] : g_pHyprOpenGL->m_mMonitorRenderResources) {
rd.blurFBDirty = true;
}
for (auto& m : g_pCompositor->m_vMonitors) {
g_pHyprRenderer->damageMonitor(m.get());
g_pLayoutManager->getCurrentLayout()->recalculateMonitor(m->ID);
}
}
return "unknown request";
return result;
}
std::string CHyprCtl::makeDynamicCall(const std::string& input) {