From 3cec9e37d26ad9524e599808cbe8c2fe0a137bc2 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Mon, 1 Jul 2024 14:59:47 +0200 Subject: [PATCH] bring back hyprctl output --- src/debug/HyprCtl.cpp | 66 +++++++++++++++-------------------------- src/events/Monitors.cpp | 24 --------------- 2 files changed, 24 insertions(+), 66 deletions(-) diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index 557c5c0d..6e5ad046 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -1377,43 +1377,6 @@ std::string decorationRequest(eHyprCtlOutputFormat format, std::string request) return result; } -// 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) && 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(data); - - if (DATA->added) - return; - - // if (addOutput(backend, DATA->type, DATA->name)) - // DATA->added = true; -} - std::string dispatchOutput(eHyprCtlOutputFormat format, std::string request) { CVarList vars(request, 0, ' '); @@ -1422,17 +1385,36 @@ std::string dispatchOutput(eHyprCtlOutputFormat format, std::string request) { const auto MODE = vars[1]; - // FIXME: + bool added = false; + + if (!vars[3].empty()) { + for (auto& m : g_pCompositor->m_vRealMonitors) { + if (m->szName == vars[3]) + return "Name already taken"; + } + } if (MODE == "create" || MODE == "add") { if (g_pCompositor->getMonitorFromName(vars[3])) return "A real monitor already uses that name."; - outputData result{vars[2], vars[3], false}; + for (auto& impl : g_pCompositor->m_pAqBackend->getImplementations()) { + auto type = impl->type(); - // wlr_multi_for_each_backend(g_pCompositor->m_sWLRBackend, createOutputIter, &result); + if (type == Aquamarine::AQ_BACKEND_HEADLESS && (vars[2] == "headless" || vars[2] == "auto")) { + added = true; + impl->createOutput(vars[3]); + break; + } - if (!result.added) + if (type == Aquamarine::AQ_BACKEND_WAYLAND && (vars[2] == "wayland" || vars[2] == "auto")) { + added = true; + impl->createOutput(vars[3]); + break; + } + } + + if (!added) return "no backend replied to the request"; } else if (MODE == "destroy" || MODE == "remove") { @@ -1444,7 +1426,7 @@ std::string dispatchOutput(eHyprCtlOutputFormat format, std::string request) { if (!PMONITOR->createdByUser) return "cannot remove a real display. Use the monitor keyword."; - //wlr_output_destroy(PMONITOR->output); + PMONITOR->output->destroy(); } return "ok"; diff --git a/src/events/Monitors.cpp b/src/events/Monitors.cpp index e53401de..3fda1654 100644 --- a/src/events/Monitors.cpp +++ b/src/events/Monitors.cpp @@ -114,30 +114,6 @@ void Events::listener_monitorDestroy(void* owner, void* data) { std::erase_if(g_pCompositor->m_vRealMonitors, [&](SP& el) { return el.get() == pMonitor; }); } -void Events::listener_monitorStateRequest(void* owner, void* data) { - // const auto PMONITOR = (CMonitor*)owner; - // const auto E = (wlr_output_event_request_state*)data; - - // if (!PMONITOR->createdByUser) - // return; - - // const auto SIZE = E->state->mode ? Vector2D{E->state->mode->width, E->state->mode->height} : Vector2D{E->state->custom_mode.width, E->state->custom_mode.height}; - - // PMONITOR->forceSize = SIZE; - - // SMonitorRule rule = PMONITOR->activeMonitorRule; - // rule.resolution = SIZE; - - // g_pHyprRenderer->applyMonitorRule(PMONITOR, &rule); -} - -void Events::listener_monitorDamage(void* owner, void* data) { - const auto PMONITOR = (CMonitor*)owner; - const auto E = (wlr_output_event_damage*)data; - - PMONITOR->addDamage(E->damage); -} - void Events::listener_monitorNeedsFrame(void* owner, void* data) { const auto PMONITOR = (CMonitor*)owner;