From ca3791fed8df003f826144e46afa0616f4052747 Mon Sep 17 00:00:00 2001 From: Sinkerine <15cm.github@15cm.net> Date: Fri, 2 Jun 2023 04:25:33 -0700 Subject: [PATCH] [hyprctl] Expose the special workspace id and name of the monitor (#2392) * [hyprctl] Expose the special workspace id of the monitor So that we know if a special workspace is shown on a monitor * [hyprctl] Add special workspace name to the output --- src/debug/HyprCtl.cpp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index 0b2a0d48..1390c268 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -19,6 +19,15 @@ static void trimTrailingComma(std::string& str) { str.pop_back(); } +static std::string getWorkspaceNameFromSpecialID(const int workspaceID) { + if (workspaceID == 0) + return ""; + const auto* workspace = g_pCompositor->getWorkspaceByID(workspaceID); + if (!workspace) + return ""; + return workspace->m_szName; +} + std::string monitorsRequest(HyprCtl::eHyprCtlOutputFormat format) { std::string result = ""; if (format == HyprCtl::FORMAT_JSON) { @@ -45,6 +54,10 @@ std::string monitorsRequest(HyprCtl::eHyprCtlOutputFormat format) { "id": %i, "name": "%s" }, + "specialWorkspace": { + "id": %i, + "name": "%s" + }, "reserved": [%i, %i, %i, %i], "scale": %.2f, "transform": %i, @@ -55,7 +68,8 @@ std::string monitorsRequest(HyprCtl::eHyprCtlOutputFormat format) { m->ID, escapeJSONStrings(m->szName).c_str(), escapeJSONStrings(m->output->description ? m->output->description : "").c_str(), (m->output->make ? m->output->make : ""), (m->output->model ? m->output->model : ""), (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->activeWorkspace, - escapeJSONStrings(g_pCompositor->getWorkspaceByID(m->activeWorkspace)->m_szName).c_str(), (int)m->vecReservedTopLeft.x, (int)m->vecReservedTopLeft.y, + escapeJSONStrings(g_pCompositor->getWorkspaceByID(m->activeWorkspace)->m_szName).c_str(), m->specialWorkspaceID, + escapeJSONStrings(getWorkspaceNameFromSpecialID(m->specialWorkspaceID)).c_str(), (int)m->vecReservedTopLeft.x, (int)m->vecReservedTopLeft.y, (int)m->vecReservedBottomRight.x, (int)m->vecReservedBottomRight.y, m->scale, (int)m->transform, (m.get() == g_pCompositor->m_pLastMonitor ? "true" : "false"), (m->dpmsStatus ? "true" : "false"), (m->output->adaptive_sync_status == WLR_OUTPUT_ADAPTIVE_SYNC_ENABLED ? "true" : "false")); } @@ -68,14 +82,16 @@ std::string monitorsRequest(HyprCtl::eHyprCtlOutputFormat format) { if (!m->output) continue; - result += getFormat("Monitor %s (ID %i):\n\t%ix%i@%f at %ix%i\n\tdescription: %s\n\tmake: %s\n\tmodel: %s\n\tserial: %s\n\tactive workspace: %i (%s)\n\treserved: %i " + result += getFormat("Monitor %s (ID %i):\n\t%ix%i@%f at %ix%i\n\tdescription: %s\n\tmake: %s\n\tmodel: %s\n\tserial: %s\n\tactive workspace: %i (%s)\n\tspecial " + "workspace: %i (%s)\n\treserved: %i " "%i %i %i\n\tscale: %.2f\n\ttransform: " "%i\n\tfocused: %s\n\tdpmsStatus: %i\n\tvrr: %i\n\n", m->szName.c_str(), m->ID, (int)m->vecPixelSize.x, (int)m->vecPixelSize.y, m->refreshRate, (int)m->vecPosition.x, (int)m->vecPosition.y, (m->output->description ? m->output->description : ""), (m->output->make ? m->output->make : ""), (m->output->model ? m->output->model : ""), (m->output->serial ? m->output->serial : ""), m->activeWorkspace, g_pCompositor->getWorkspaceByID(m->activeWorkspace)->m_szName.c_str(), - (int)m->vecReservedTopLeft.x, (int)m->vecReservedTopLeft.y, (int)m->vecReservedBottomRight.x, (int)m->vecReservedBottomRight.y, m->scale, - (int)m->transform, (m.get() == g_pCompositor->m_pLastMonitor ? "yes" : "no"), (int)m->dpmsStatus, + m->specialWorkspaceID, getWorkspaceNameFromSpecialID(m->specialWorkspaceID).c_str(), (int)m->vecReservedTopLeft.x, (int)m->vecReservedTopLeft.y, + (int)m->vecReservedBottomRight.x, (int)m->vecReservedBottomRight.y, m->scale, (int)m->transform, + (m.get() == g_pCompositor->m_pLastMonitor ? "yes" : "no"), (int)m->dpmsStatus, (int)(m->output->adaptive_sync_status == WLR_OUTPUT_ADAPTIVE_SYNC_ENABLED)); } }