diff options
author | phonetic112 <[email protected]> | 2024-06-05 12:26:38 -0400 |
---|---|---|
committer | GitHub <[email protected]> | 2024-06-05 18:26:38 +0200 |
commit | 82099fd1c0ab5b0bee022a45949556e7e1084835 (patch) | |
tree | ee2662af913caf5ef9ac9c8852316aad0ad71c89 /src/debug | |
parent | 155fe6f165f70ea69a44cbd6989fc01a473e6946 (diff) | |
download | Hyprland-82099fd1c0ab5b0bee022a45949556e7e1084835.tar.gz Hyprland-82099fd1c0ab5b0bee022a45949556e7e1084835.zip |
hyprctl: Allow setting name for custom/headless outputs (#6319)
Diffstat (limited to 'src/debug')
-rw-r--r-- | src/debug/HyprCtl.cpp | 89 |
1 files changed, 40 insertions, 49 deletions
diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index 4563c5a1..bdb12e58 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -1374,73 +1374,64 @@ std::string decorationRequest(eHyprCtlOutputFormat format, std::string request) return result; } -void createOutputIter(wlr_backend* backend, void* data) { - const auto DATA = (std::pair<std::string, bool>*)data; - - if (DATA->second) - return; - - if (DATA->first.empty() || DATA->first == "auto") { - if (wlr_backend_is_wl(backend)) { - wlr_wl_output_create(backend); - DATA->second = true; - } else if (wlr_backend_is_x11(backend)) { - wlr_x11_output_create(backend); - DATA->second = true; - } else if (wlr_backend_is_headless(backend)) { - wlr_headless_add_output(backend, 1920, 1080); - DATA->second = true; - } +static bool addOutput(wlr_backend* backend, const std::string& type, const std::string& name) { + wlr_output* output = nullptr; + + if (type.empty() || type == "auto") { + if (wlr_backend_is_wl(backend)) + output = wlr_wl_output_create(backend); + else if (wlr_backend_is_headless(backend)) + output = wlr_headless_add_output(backend, 1920, 1080); } else { - if (wlr_backend_is_wl(backend) && DATA->first == "wayland") { - wlr_wl_output_create(backend); - DATA->second = true; - } else if (wlr_backend_is_x11(backend) && DATA->first == "x11") { - wlr_x11_output_create(backend); - DATA->second = true; - } else if (wlr_backend_is_headless(backend) && DATA->first == "headless") { - wlr_headless_add_output(backend, 1920, 1080); - DATA->second = true; - } + if (wlr_backend_is_wl(backend) && type == "wayland") + output = wlr_wl_output_create(backend); + else if (wlr_backend_is_headless(backend) && type == "headless") + output = wlr_headless_add_output(backend, 1920, 1080); } -} -std::string dispatchOutput(eHyprCtlOutputFormat format, std::string request) { - std::string curitem = ""; + if (output && !name.empty()) + g_pCompositor->getMonitorFromOutput(output)->szName = name; - auto nextItem = [&]() { - auto idx = request.find_first_of(' '); + return output != nullptr; +} - if (idx != std::string::npos) { - curitem = request.substr(0, idx); - request = request.substr(idx + 1); - } else { - curitem = request; - request = ""; - } +struct outputData { + std::string type; + std::string name; + bool added; +}; - curitem = removeBeginEndSpacesTabs(curitem); - }; +void createOutputIter(wlr_backend* backend, void* data) { + const auto DATA = static_cast<outputData*>(data); - nextItem(); - nextItem(); + if (DATA->added) + return; - const auto MODE = curitem; + if (addOutput(backend, DATA->type, DATA->name)) + DATA->added = true; +} - nextItem(); +std::string dispatchOutput(eHyprCtlOutputFormat format, std::string request) { + CVarList vars(request, 0, ' '); - const auto NAME = curitem; + if (vars.size() < 2) + return "not enough args"; + + const auto MODE = vars[1]; if (MODE == "create" || MODE == "add") { - std::pair<std::string, bool> result = {NAME, false}; + if (g_pCompositor->getMonitorFromName(vars[3])) + return "A real monitor already uses that name."; + + outputData result{vars[2], vars[3], false}; wlr_multi_for_each_backend(g_pCompositor->m_sWLRBackend, createOutputIter, &result); - if (!result.second) + if (!result.added) return "no backend replied to the request"; } else if (MODE == "destroy" || MODE == "remove") { - const auto PMONITOR = g_pCompositor->getMonitorFromName(NAME); + const auto PMONITOR = g_pCompositor->getMonitorFromName(vars[2]); if (!PMONITOR) return "output not found"; |