diff options
author | Yusuf <[email protected]> | 2024-07-07 17:52:56 +0200 |
---|---|---|
committer | GitHub <[email protected]> | 2024-07-07 17:52:56 +0200 |
commit | 19fb13e6cf7c9125b471780156fc423118914fb7 (patch) | |
tree | 89340b13f74436bb0c432963622001f8f88f0180 /src/debug | |
parent | ede1e63f69e0356eaef10e3da30b86862df38e8c (diff) | |
download | Hyprland-19fb13e6cf7c9125b471780156fc423118914fb7.tar.gz Hyprland-19fb13e6cf7c9125b471780156fc423118914fb7.zip |
internal: Add functions to hyprctl header (#6745)
* add functions to hyprctl header
* refactor monitor json into own function and add it to header
* format hyprctl.hpp
* move functions to namespace
* move helper functions to class
Diffstat (limited to 'src/debug')
-rw-r--r-- | src/debug/HyprCtl.cpp | 76 | ||||
-rw-r--r-- | src/debug/HyprCtl.hpp | 4 |
2 files changed, 45 insertions, 35 deletions
diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index 571aa6d1..f96c071a 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -70,26 +70,13 @@ static std::string availableModesForOutput(CMonitor* pMonitor, eHyprCtlOutputFor return result; } -std::string monitorsRequest(eHyprCtlOutputFormat format, std::string request) { - CVarList vars(request, 0, ' '); - auto allMonitors = false; - - if (vars.size() > 2) - return "too many args"; - - if (vars.size() == 2 && vars[1] == "all") - allMonitors = true; - - std::string result = ""; - if (format == eHyprCtlOutputFormat::FORMAT_JSON) { - result += "["; - - for (auto& m : allMonitors ? g_pCompositor->m_vRealMonitors : g_pCompositor->m_vMonitors) { - if (!m->output || m->ID == -1ull) - continue; +std::string CHyprCtl::getMonitorData(Hyprutils::Memory::CSharedPointer<CMonitor> m, eHyprCtlOutputFormat format) { + std::string result; + if (!m->output || m->ID == -1ull) + return ""; - result += std::format( - R"#({{ + result += std::format( + R"#({{ "id": {}, "name": "{}", "description": "{}", @@ -120,14 +107,33 @@ std::string monitorsRequest(eHyprCtlOutputFormat format, std::string request) { "currentFormat": "{}", "availableModes": [{}] }},)#", - m->ID, escapeJSONStrings(m->szName), escapeJSONStrings(m->szShortDescription), escapeJSONStrings(m->output->make ? m->output->make : ""), - escapeJSONStrings(m->output->model ? m->output->model : ""), escapeJSONStrings(m->output->serial ? m->output->serial : ""), (int)m->vecPixelSize.x, - (int)m->vecPixelSize.y, m->refreshRate, (int)m->vecPosition.x, (int)m->vecPosition.y, m->activeWorkspaceID(), - (!m->activeWorkspace ? "" : escapeJSONStrings(m->activeWorkspace->m_szName)), m->activeSpecialWorkspaceID(), - escapeJSONStrings(m->activeSpecialWorkspace ? m->activeSpecialWorkspace->m_szName : ""), (int)m->vecReservedTopLeft.x, (int)m->vecReservedTopLeft.y, - (int)m->vecReservedBottomRight.x, (int)m->vecReservedBottomRight.y, m->scale, (int)m->transform, (m == g_pCompositor->m_pLastMonitor ? "true" : "false"), - (m->dpmsStatus ? "true" : "false"), (m->output->adaptive_sync_status == WLR_OUTPUT_ADAPTIVE_SYNC_ENABLED ? "true" : "false"), - (m->tearingState.activelyTearing ? "true" : "false"), (m->m_bEnabled ? "false" : "true"), formatToString(m->drmFormat), availableModesForOutput(m.get(), format)); + m->ID, escapeJSONStrings(m->szName), escapeJSONStrings(m->szShortDescription), escapeJSONStrings(m->output->make ? m->output->make : ""), + escapeJSONStrings(m->output->model ? m->output->model : ""), escapeJSONStrings(m->output->serial ? m->output->serial : ""), (int)m->vecPixelSize.x, (int)m->vecPixelSize.y, + m->refreshRate, (int)m->vecPosition.x, (int)m->vecPosition.y, m->activeWorkspaceID(), (!m->activeWorkspace ? "" : escapeJSONStrings(m->activeWorkspace->m_szName)), + m->activeSpecialWorkspaceID(), escapeJSONStrings(m->activeSpecialWorkspace ? m->activeSpecialWorkspace->m_szName : ""), (int)m->vecReservedTopLeft.x, + (int)m->vecReservedTopLeft.y, (int)m->vecReservedBottomRight.x, (int)m->vecReservedBottomRight.y, m->scale, (int)m->transform, + (m == g_pCompositor->m_pLastMonitor ? "true" : "false"), (m->dpmsStatus ? "true" : "false"), + (m->output->adaptive_sync_status == WLR_OUTPUT_ADAPTIVE_SYNC_ENABLED ? "true" : "false"), (m->tearingState.activelyTearing ? "true" : "false"), + (m->m_bEnabled ? "false" : "true"), formatToString(m->drmFormat), availableModesForOutput(m.get(), format)); + return result; +} + +std::string monitorsRequest(eHyprCtlOutputFormat format, std::string request) { + CVarList vars(request, 0, ' '); + auto allMonitors = false; + + if (vars.size() > 2) + return "too many args"; + + if (vars.size() == 2 && vars[1] == "all") + allMonitors = true; + + std::string result = ""; + if (format == eHyprCtlOutputFormat::FORMAT_JSON) { + result += "["; + + for (auto& m : allMonitors ? g_pCompositor->m_vRealMonitors : g_pCompositor->m_vMonitors) { + result += CHyprCtl::getMonitorData(m, format); } trimTrailingComma(result); @@ -188,7 +194,7 @@ static std::string getGroupedData(PHLWINDOW w, eHyprCtlOutputFormat format) { return result.str(); } -static std::string getWindowData(PHLWINDOW w, eHyprCtlOutputFormat format) { +std::string CHyprCtl::getWindowData(PHLWINDOW w, eHyprCtlOutputFormat format) { auto getFocusHistoryID = [](PHLWINDOW wnd) -> int { for (size_t i = 0; i < g_pCompositor->m_vWindowFocusHistory.size(); ++i) { if (g_pCompositor->m_vWindowFocusHistory[i].lock() == wnd) @@ -257,7 +263,7 @@ std::string clientsRequest(eHyprCtlOutputFormat format, std::string request) { if (!w->m_bIsMapped && !g_pHyprCtl->m_sCurrentRequestParams.all) continue; - result += getWindowData(w, format); + result += CHyprCtl::getWindowData(w, format); } trimTrailingComma(result); @@ -268,13 +274,13 @@ std::string clientsRequest(eHyprCtlOutputFormat format, std::string request) { if (!w->m_bIsMapped && !g_pHyprCtl->m_sCurrentRequestParams.all) continue; - result += getWindowData(w, format); + result += CHyprCtl::getWindowData(w, format); } } return result; } -static std::string getWorkspaceData(PHLWORKSPACE w, eHyprCtlOutputFormat format) { +std::string CHyprCtl::getWorkspaceData(PHLWORKSPACE w, eHyprCtlOutputFormat format) { const auto PLASTW = w->getLastFocusedWindow(); const auto PMONITOR = g_pCompositor->getMonitorFromID(w->m_iMonitorID); if (format == eHyprCtlOutputFormat::FORMAT_JSON) { @@ -354,7 +360,7 @@ std::string activeWorkspaceRequest(eHyprCtlOutputFormat format, std::string requ if (!valid(w)) return "internal error"; - return getWorkspaceData(w, format); + return CHyprCtl::getWorkspaceData(w, format); } std::string workspacesRequest(eHyprCtlOutputFormat format, std::string request) { @@ -363,7 +369,7 @@ std::string workspacesRequest(eHyprCtlOutputFormat format, std::string request) if (format == eHyprCtlOutputFormat::FORMAT_JSON) { result += "["; for (auto& w : g_pCompositor->m_vWorkspaces) { - result += getWorkspaceData(w, format); + result += CHyprCtl::getWorkspaceData(w, format); result += ","; } @@ -371,7 +377,7 @@ std::string workspacesRequest(eHyprCtlOutputFormat format, std::string request) result += "]"; } else { for (auto& w : g_pCompositor->m_vWorkspaces) { - result += getWorkspaceData(w, format); + result += CHyprCtl::getWorkspaceData(w, format); } } @@ -404,7 +410,7 @@ std::string activeWindowRequest(eHyprCtlOutputFormat format, std::string request if (!validMapped(PWINDOW)) return format == eHyprCtlOutputFormat::FORMAT_JSON ? "{}" : "Invalid"; - auto result = getWindowData(PWINDOW, format); + auto result = CHyprCtl::getWindowData(PWINDOW, format); if (format == eHyprCtlOutputFormat::FORMAT_JSON) result.pop_back(); diff --git a/src/debug/HyprCtl.hpp b/src/debug/HyprCtl.hpp index 21a2c5f8..ccbd40cd 100644 --- a/src/debug/HyprCtl.hpp +++ b/src/debug/HyprCtl.hpp @@ -22,6 +22,10 @@ class CHyprCtl { bool sysInfoConfig = false; } m_sCurrentRequestParams; + static std::string getWindowData(PHLWINDOW w, eHyprCtlOutputFormat format); + static std::string getWorkspaceData(PHLWORKSPACE w, eHyprCtlOutputFormat format); + static std::string getMonitorData(Hyprutils::Memory::CSharedPointer<CMonitor> m, eHyprCtlOutputFormat format); + private: void startHyprCtlSocket(); |