From 6f838560252045be5bac2e7492ff8d1e250cf937 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sat, 24 Feb 2024 14:01:58 +0000 Subject: [PATCH] hyprctl: add -r argument --- hyprctl/main.cpp | 3 +++ src/debug/HyprCtl.cpp | 55 ++++++++++++++++++++++++++++++++++++------- 2 files changed, 49 insertions(+), 9 deletions(-) diff --git a/hyprctl/main.cpp b/hyprctl/main.cpp index 6126c514..9d3c98d1 100644 --- a/hyprctl/main.cpp +++ b/hyprctl/main.cpp @@ -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") { diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index 842a5ce6..8f29ae72 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -1476,7 +1476,8 @@ void CHyprCtl::unregisterCommand(const std::shared_ptr& 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) {