mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-26 06:05:59 +01:00
hyprctl: Allow setting name for custom/headless outputs (#6319)
This commit is contained in:
parent
155fe6f165
commit
82099fd1c0
1 changed files with 42 additions and 51 deletions
|
@ -1374,73 +1374,64 @@ std::string decorationRequest(eHyprCtlOutputFormat format, std::string request)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void createOutputIter(wlr_backend* backend, void* data) {
|
static bool addOutput(wlr_backend* backend, const std::string& type, const std::string& name) {
|
||||||
const auto DATA = (std::pair<std::string, bool>*)data;
|
wlr_output* output = nullptr;
|
||||||
|
|
||||||
if (DATA->second)
|
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) && 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (output && !name.empty())
|
||||||
|
g_pCompositor->getMonitorFromOutput(output)->szName = name;
|
||||||
|
|
||||||
|
return output != nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct outputData {
|
||||||
|
std::string type;
|
||||||
|
std::string name;
|
||||||
|
bool added;
|
||||||
|
};
|
||||||
|
|
||||||
|
void createOutputIter(wlr_backend* backend, void* data) {
|
||||||
|
const auto DATA = static_cast<outputData*>(data);
|
||||||
|
|
||||||
|
if (DATA->added)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (DATA->first.empty() || DATA->first == "auto") {
|
if (addOutput(backend, DATA->type, DATA->name))
|
||||||
if (wlr_backend_is_wl(backend)) {
|
DATA->added = true;
|
||||||
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;
|
|
||||||
}
|
|
||||||
} 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string dispatchOutput(eHyprCtlOutputFormat format, std::string request) {
|
std::string dispatchOutput(eHyprCtlOutputFormat format, std::string request) {
|
||||||
std::string curitem = "";
|
CVarList vars(request, 0, ' ');
|
||||||
|
|
||||||
auto nextItem = [&]() {
|
if (vars.size() < 2)
|
||||||
auto idx = request.find_first_of(' ');
|
return "not enough args";
|
||||||
|
|
||||||
if (idx != std::string::npos) {
|
const auto MODE = vars[1];
|
||||||
curitem = request.substr(0, idx);
|
|
||||||
request = request.substr(idx + 1);
|
|
||||||
} else {
|
|
||||||
curitem = request;
|
|
||||||
request = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
curitem = removeBeginEndSpacesTabs(curitem);
|
|
||||||
};
|
|
||||||
|
|
||||||
nextItem();
|
|
||||||
nextItem();
|
|
||||||
|
|
||||||
const auto MODE = curitem;
|
|
||||||
|
|
||||||
nextItem();
|
|
||||||
|
|
||||||
const auto NAME = curitem;
|
|
||||||
|
|
||||||
if (MODE == "create" || MODE == "add") {
|
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);
|
wlr_multi_for_each_backend(g_pCompositor->m_sWLRBackend, createOutputIter, &result);
|
||||||
|
|
||||||
if (!result.second)
|
if (!result.added)
|
||||||
return "no backend replied to the request";
|
return "no backend replied to the request";
|
||||||
|
|
||||||
} else if (MODE == "destroy" || MODE == "remove") {
|
} else if (MODE == "destroy" || MODE == "remove") {
|
||||||
const auto PMONITOR = g_pCompositor->getMonitorFromName(NAME);
|
const auto PMONITOR = g_pCompositor->getMonitorFromName(vars[2]);
|
||||||
|
|
||||||
if (!PMONITOR)
|
if (!PMONITOR)
|
||||||
return "output not found";
|
return "output not found";
|
||||||
|
|
Loading…
Reference in a new issue