From e0bfec6ef2507de3f13e1d4690adfe195cf1643c Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Mon, 4 Jul 2022 17:47:31 +0200 Subject: added experimental:vfr --- src/debug/HyprCtl.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/debug/HyprCtl.cpp') diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index eb6c085c..65b45901 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -264,6 +264,14 @@ void HyprCtl::tickHyprCtl() { } std::string getRequestFromThread(std::string rq) { + // we need to do something to wake hyprland up if VFR is enabled + static auto *const VFRENABLED = &g_pConfigManager->getConfigValuePtr("experimental:vfr")->intValue; + if (*VFRENABLED) { + // TODO: is this safe...? + // this might be a race condition + wlr_output_schedule_frame(g_pCompositor->m_vMonitors.front()->output); + } + while (HyprCtl::request != "" || HyprCtl::requestMade || HyprCtl::requestReady) { std::this_thread::sleep_for(std::chrono::milliseconds(5)); } -- cgit v1.2.3 From f9756d10d4d1c5ea7737cf3a237b1f966d6b7a01 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Wed, 6 Jul 2022 16:50:11 +0200 Subject: changed C++ std to C++23, use std::string::contains --- src/debug/HyprCtl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/debug/HyprCtl.cpp') diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index 65b45901..ad72c68e 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -158,7 +158,7 @@ std::string dispatchKeyword(std::string in) { if (COMMAND == "monitor") g_pConfigManager->m_bWantsMonitorReload = true; // for monitor keywords - if (COMMAND.find("input") != std::string::npos) + if (COMMAND.contains("input")) g_pInputManager->setKeyboardLayout(); // update kb layout Debug::log(LOG, "Hyprctl: keyword %s : %s", COMMAND.c_str(), VALUE.c_str()); -- cgit v1.2.3 From a545992891668d9872bed04b76d3b35b32dc0796 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Wed, 6 Jul 2022 21:57:15 +0200 Subject: fixed hyprctl layers crash --- src/debug/HyprCtl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/debug/HyprCtl.cpp') diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index ad72c68e..9a30c54c 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -58,7 +58,7 @@ std::string layersRequest() { std::string result = ""; for (auto& mon : g_pCompositor->m_vMonitors) { - result += getFormat("Monitor %s:\n"); + result += getFormat("Monitor %s:\n", mon->szName.c_str()); int layerLevel = 0; for (auto& level : mon->m_aLayerSurfaceLists) { result += getFormat("\tLayer level %i:\n", layerLevel); -- cgit v1.2.3 From 6a16f11d63cead0b8526f442c18727a6f3dc76ea Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Wed, 6 Jul 2022 21:57:35 +0200 Subject: add namespace to hyprctl layers --- src/debug/HyprCtl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/debug/HyprCtl.cpp') diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index 9a30c54c..41bfe06c 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -64,7 +64,7 @@ std::string layersRequest() { result += getFormat("\tLayer level %i:\n", layerLevel); for (auto& layer : level) { - result += getFormat("\t\tLayer %x: xywh: %i %i %i %i\n", layer, layer->geometry.x, layer->geometry.y, layer->geometry.width, layer->geometry.height); + result += getFormat("\t\tLayer %x: xywh: %i %i %i %i, namespace: %s\n", layer, layer->geometry.x, layer->geometry.y, layer->geometry.width, layer->geometry.height, layer->szNamespace.c_str()); } layerLevel++; -- cgit v1.2.3 From 92e17f29256af4db05ebd17b9f2d013ee3ca37ab Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Fri, 8 Jul 2022 12:27:05 +0200 Subject: added rules to hyprctl devices and fixed rules --- src/debug/HyprCtl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/debug/HyprCtl.cpp') diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index 41bfe06c..84909a8e 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -87,7 +87,7 @@ std::string devicesRequest() { result += "\n\nKeyboards:\n"; for (auto& k : g_pInputManager->m_lKeyboards) { - result += getFormat("\tKeyboard at %x:\n\t\t%s\n", &k, k.keyboard->name); + result += getFormat("\tKeyboard at %x:\n\t\t%s\n\t\t\trules: r \"%s\", m \"%s\", l \"%s\", v \"%s\", o \"%s\"\n", &k, k.keyboard->name, k.currentRules.rules.c_str(), k.currentRules.model.c_str(), k.currentRules.layout.c_str(), k.currentRules.variant.c_str(), k.currentRules.options.c_str()); } result += "\n\nTablets:\n"; -- cgit v1.2.3 From 4b334594dc0d8989d8bb09c7db76694aacc71951 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Sun, 10 Jul 2022 15:41:26 +0200 Subject: Added splashes --- src/debug/HyprCtl.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/debug/HyprCtl.cpp') diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index 84909a8e..7aa0017e 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -181,6 +181,10 @@ std::string killRequest() { return "ok"; } +std::string splashRequest() { + return g_pCompositor->m_szCurrentSplash; +} + std::string getReply(std::string); std::string dispatchBatch(std::string request) { @@ -234,6 +238,8 @@ std::string getReply(std::string request) { return reloadRequest(); else if (request == "devices") return devicesRequest(); + else if (request == "splash") + return splashRequest(); else if (request.find("dispatch") == 0) return dispatchRequest(request); else if (request.find("keyword") == 0) -- cgit v1.2.3 From c0c75db62188667a4f42aef1ae6bfd8034093af7 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Mon, 11 Jul 2022 23:56:24 +0200 Subject: roll VFR for everyone --- src/debug/HyprCtl.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/debug/HyprCtl.cpp') diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index 7aa0017e..519b0ce8 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -271,12 +271,11 @@ void HyprCtl::tickHyprCtl() { std::string getRequestFromThread(std::string rq) { // we need to do something to wake hyprland up if VFR is enabled - static auto *const VFRENABLED = &g_pConfigManager->getConfigValuePtr("experimental:vfr")->intValue; - if (*VFRENABLED) { - // TODO: is this safe...? - // this might be a race condition - wlr_output_schedule_frame(g_pCompositor->m_vMonitors.front()->output); - } + + // TODO: is this safe...? + // this might be a race condition + // tested with 2 instances of `watch -n 0.1 hyprctl splash` and seems to not crash so I'll take that as a yes + wlr_output_schedule_frame(g_pCompositor->m_vMonitors.front()->output); while (HyprCtl::request != "" || HyprCtl::requestMade || HyprCtl::requestReady) { std::this_thread::sleep_for(std::chrono::milliseconds(5)); -- cgit v1.2.3 From bf8bd87d110bb88788364cb8da723531a4bb86b7 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Tue, 12 Jul 2022 00:16:28 +0200 Subject: added active monitor to hyprctl monitors --- src/debug/HyprCtl.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/debug/HyprCtl.cpp') diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index 519b0ce8..fb0e3ed4 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -16,8 +16,8 @@ std::string monitorsRequest() { std::string result = ""; for (auto& m : g_pCompositor->m_vMonitors) { - result += getFormat("Monitor %s (ID %i):\n\t%ix%i@%f at %ix%i\n\tactive workspace: %i (%s)\n\treserved: %i %i %i %i\n\tscale: %.2f\n\ttransform: %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->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); + result += getFormat("Monitor %s (ID %i):\n\t%ix%i@%f at %ix%i\n\tactive workspace: %i (%s)\n\treserved: %i %i %i %i\n\tscale: %.2f\n\ttransform: %i\n\tactive: %s\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->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")); } return result; -- cgit v1.2.3 From 29e2bb27f6073695aa4f9767f87cd653db5ce811 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Tue, 12 Jul 2022 10:02:12 +0200 Subject: added misc:no_vfr --- src/debug/HyprCtl.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/debug/HyprCtl.cpp') diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index fb0e3ed4..3dffab12 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -272,10 +272,13 @@ void HyprCtl::tickHyprCtl() { std::string getRequestFromThread(std::string rq) { // we need to do something to wake hyprland up if VFR is enabled + static auto *const PNOVFR = &g_pConfigManager->getConfigValuePtr("misc:no_vfr")->intValue; + // TODO: is this safe...? // this might be a race condition // tested with 2 instances of `watch -n 0.1 hyprctl splash` and seems to not crash so I'll take that as a yes - wlr_output_schedule_frame(g_pCompositor->m_vMonitors.front()->output); + if (!*PNOVFR) + wlr_output_schedule_frame(g_pCompositor->m_vMonitors.front()->output); while (HyprCtl::request != "" || HyprCtl::requestMade || HyprCtl::requestReady) { std::this_thread::sleep_for(std::chrono::milliseconds(5)); -- cgit v1.2.3 From 036f431206b6c530497fb6e204c9765745c2c17d Mon Sep 17 00:00:00 2001 From: bazuin-32 Date: Tue, 12 Jul 2022 11:57:33 -0600 Subject: Add hyprctl output in json when `-j` flag is used --- src/debug/HyprCtl.cpp | 400 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 348 insertions(+), 52 deletions(-) (limited to 'src/debug/HyprCtl.cpp') diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index 3dffab12..40480bd3 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -13,95 +13,386 @@ #include -std::string monitorsRequest() { +std::string monitorsRequest(bool json) { std::string result = ""; - for (auto& m : g_pCompositor->m_vMonitors) { - result += getFormat("Monitor %s (ID %i):\n\t%ix%i@%f at %ix%i\n\tactive workspace: %i (%s)\n\treserved: %i %i %i %i\n\tscale: %.2f\n\ttransform: %i\n\tactive: %s\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->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")); + if (json) { + result += "["; + + for (auto& m : g_pCompositor->m_vMonitors) { + result += getFormat( +R"#({ + "id": %i, + "name": "%s", + "width": %i, + "height": %i, + "refreshRate": %f, + "x": %i, + "y": %i, + "activeWorkspace": { + "id": %i, + "name": "%s" + }, + "reserved": [%i, %i, %i, %i], + "scale": %.2f, + "transform": %i, + "active": "%s" +},)#", + m->ID, + m->szName.c_str(), + (int)m->vecPixelSize.x, (int)m->vecPixelSize.y, + m->refreshRate, + (int)m->vecPosition.x, (int)m->vecPosition.y, + 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") + ); + } + + // remove trailing comma + result.pop_back(); + + result += "]"; + } else { + for (auto& m : g_pCompositor->m_vMonitors) { + result += getFormat("Monitor %s (ID %i):\n\t%ix%i@%f at %ix%i\n\tactive workspace: %i (%s)\n\treserved: %i %i %i %i\n\tscale: %.2f\n\ttransform: %i\n\tactive: %s\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->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")); + } } return result; } -std::string clientsRequest() { +std::string clientsRequest(bool json) { std::string result = ""; - for (auto& w : g_pCompositor->m_vWindows) { - if (w->m_bIsMapped) { - result += getFormat("Window %x -> %s:\n\tat: %i,%i\n\tsize: %i,%i\n\tworkspace: %i (%s)\n\tfloating: %i\n\tmonitor: %i\n\tclass: %s\n\ttitle: %s\n\tpid: %i\n\n", - &w, w->m_szTitle.c_str(), (int)w->m_vRealPosition.vec().x, (int)w->m_vRealPosition.vec().y, (int)w->m_vRealSize.vec().x, (int)w->m_vRealSize.vec().y, w->m_iWorkspaceID, (w->m_iWorkspaceID == -1 ? "" : g_pCompositor->getWorkspaceByID(w->m_iWorkspaceID) ? g_pCompositor->getWorkspaceByID(w->m_iWorkspaceID)->m_szName.c_str() : std::string("Invalid workspace " + std::to_string(w->m_iWorkspaceID)).c_str()), (int)w->m_bIsFloating, w->m_iMonitorID, g_pXWaylandManager->getAppIDClass(w.get()).c_str(), g_pXWaylandManager->getTitle(w.get()).c_str(), w->getPID()); - + if (json) { + result += "["; + + for (auto& w : g_pCompositor->m_vWindows) { + if (w->m_bIsMapped) { + result += getFormat( +R"#({ + "address": "0x%x", + "at": [%i, %i], + "size": [%i, %i], + "workspace": { + "id": %i, + "name": "%s" + }, + "floating": %i, + "monitor": %i, + "class": "%s", + "title": "%s", + "pid": %i +},)#", + &w, + (int)w->m_vRealPosition.vec().x, (int)w->m_vRealPosition.vec().y, + (int)w->m_vRealSize.vec().x, (int)w->m_vRealSize.vec().y, + w->m_iWorkspaceID, (w->m_iWorkspaceID == -1 ? "" : g_pCompositor->getWorkspaceByID(w->m_iWorkspaceID) ? g_pCompositor->getWorkspaceByID(w->m_iWorkspaceID)->m_szName.c_str() : std::string("Invalid workspace " + std::to_string(w->m_iWorkspaceID)).c_str()), + (int)w->m_bIsFloating, + w->m_iMonitorID, + g_pXWaylandManager->getAppIDClass(w.get()).c_str(), + g_pXWaylandManager->getTitle(w.get()).c_str(), + w->getPID() + ); + } + } + + // remove trailing comma + result.pop_back(); + + result += "]"; + } else { + for (auto& w : g_pCompositor->m_vWindows) { + if (w->m_bIsMapped) { + result += getFormat("Window %x -> %s:\n\tat: %i,%i\n\tsize: %i,%i\n\tworkspace: %i (%s)\n\tfloating: %i\n\tmonitor: %i\n\tclass: %s\n\ttitle: %s\n\tpid: %i\n\n", + &w, w->m_szTitle.c_str(), (int)w->m_vRealPosition.vec().x, (int)w->m_vRealPosition.vec().y, (int)w->m_vRealSize.vec().x, (int)w->m_vRealSize.vec().y, w->m_iWorkspaceID, (w->m_iWorkspaceID == -1 ? "" : g_pCompositor->getWorkspaceByID(w->m_iWorkspaceID) ? g_pCompositor->getWorkspaceByID(w->m_iWorkspaceID)->m_szName.c_str() : std::string("Invalid workspace " + std::to_string(w->m_iWorkspaceID)).c_str()), (int)w->m_bIsFloating, w->m_iMonitorID, g_pXWaylandManager->getAppIDClass(w.get()).c_str(), g_pXWaylandManager->getTitle(w.get()).c_str(), w->getPID()); + + } } } return result; } -std::string workspacesRequest() { +std::string workspacesRequest(bool json) { std::string result = ""; - for (auto& w : g_pCompositor->m_vWorkspaces) { - result += getFormat("workspace ID %i (%s) on monitor %s:\n\twindows: %i\n\thasfullscreen: %i\n\n", - w->m_iID, w->m_szName.c_str(), g_pCompositor->getMonitorFromID(w->m_iMonitorID)->szName.c_str(), g_pCompositor->getWindowsOnWorkspace(w->m_iID), (int)w->m_bHasFullscreenWindow); + if (json) { + result += "["; + + for (auto& w : g_pCompositor->m_vWorkspaces) { + result += getFormat( +R"#({ + "id": %i, + "name": "%s", + "monitor": "%s", + "windows": %i, + "hasfullscreen": %i +},)#", + w->m_iID, + w->m_szName.c_str(), + g_pCompositor->getMonitorFromID(w->m_iMonitorID)->szName.c_str(), + g_pCompositor->getWindowsOnWorkspace(w->m_iID), + (int)w->m_bHasFullscreenWindow + ); + } + + // remove trailing comma + result.pop_back(); + + result += "]"; + } else { + for (auto& w : g_pCompositor->m_vWorkspaces) { + result += getFormat("workspace ID %i (%s) on monitor %s:\n\twindows: %i\n\thasfullscreen: %i\n\n", + w->m_iID, w->m_szName.c_str(), g_pCompositor->getMonitorFromID(w->m_iMonitorID)->szName.c_str(), g_pCompositor->getWindowsOnWorkspace(w->m_iID), (int)w->m_bHasFullscreenWindow); + } } return result; } -std::string activeWindowRequest() { +std::string activeWindowRequest(bool json) { const auto PWINDOW = g_pCompositor->m_pLastWindow; if (!g_pCompositor->windowValidMapped(PWINDOW)) return "Invalid"; - return getFormat("Window %x -> %s:\n\tat: %i,%i\n\tsize: %i,%i\n\tworkspace: %i (%s)\n\tfloating: %i\n\tmonitor: %i\n\tclass: %s\n\ttitle: %s\n\tpid: %i\n\n", - PWINDOW, PWINDOW->m_szTitle.c_str(), (int)PWINDOW->m_vRealPosition.vec().x, (int)PWINDOW->m_vRealPosition.vec().y, (int)PWINDOW->m_vRealSize.vec().x, (int)PWINDOW->m_vRealSize.vec().y, PWINDOW->m_iWorkspaceID, (PWINDOW->m_iWorkspaceID == -1 ? "" : g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID)->m_szName.c_str()), (int)PWINDOW->m_bIsFloating, (int)PWINDOW->m_iMonitorID, g_pXWaylandManager->getAppIDClass(PWINDOW).c_str(), g_pXWaylandManager->getTitle(PWINDOW).c_str(), PWINDOW->getPID()); + if (json) { + return getFormat( +R"#({ + "address": "0x%x", + "at": [%i, %i], + "size": [%i, %i], + "workspace": { + "id": %i, + "name": "%s" + }, + "floating": %i, + "monitor": %i, + "class": "%s", + "title": "%s", + "pid": %i +})#", + PWINDOW, + (int)PWINDOW->m_vRealPosition.vec().x, (int)PWINDOW->m_vRealPosition.vec().y, + (int)PWINDOW->m_vRealSize.vec().x, (int)PWINDOW->m_vRealSize.vec().y, + PWINDOW->m_iWorkspaceID, (PWINDOW->m_iWorkspaceID == -1 ? "" : g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID)->m_szName.c_str()), + (int)PWINDOW->m_bIsFloating, + PWINDOW->m_iMonitorID, + g_pXWaylandManager->getAppIDClass(PWINDOW).c_str(), + g_pXWaylandManager->getTitle(PWINDOW).c_str(), + PWINDOW->getPID() + ); + } else { + return getFormat("Window %x -> %s:\n\tat: %i,%i\n\tsize: %i,%i\n\tworkspace: %i (%s)\n\tfloating: %i\n\tmonitor: %i\n\tclass: %s\n\ttitle: %s\n\tpid: %i\n\n", + PWINDOW, PWINDOW->m_szTitle.c_str(), (int)PWINDOW->m_vRealPosition.vec().x, (int)PWINDOW->m_vRealPosition.vec().y, (int)PWINDOW->m_vRealSize.vec().x, (int)PWINDOW->m_vRealSize.vec().y, PWINDOW->m_iWorkspaceID, (PWINDOW->m_iWorkspaceID == -1 ? "" : g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID)->m_szName.c_str()), (int)PWINDOW->m_bIsFloating, (int)PWINDOW->m_iMonitorID, g_pXWaylandManager->getAppIDClass(PWINDOW).c_str(), g_pXWaylandManager->getTitle(PWINDOW).c_str(), PWINDOW->getPID()); + } } -std::string layersRequest() { +std::string layersRequest(bool json) { std::string result = ""; - for (auto& mon : g_pCompositor->m_vMonitors) { - result += getFormat("Monitor %s:\n", mon->szName.c_str()); - int layerLevel = 0; - for (auto& level : mon->m_aLayerSurfaceLists) { - result += getFormat("\tLayer level %i:\n", layerLevel); - - for (auto& layer : level) { - result += getFormat("\t\tLayer %x: xywh: %i %i %i %i, namespace: %s\n", layer, layer->geometry.x, layer->geometry.y, layer->geometry.width, layer->geometry.height, layer->szNamespace.c_str()); + if (json) { + result += "{\n"; + + for (auto& mon : g_pCompositor->m_vMonitors) { + result += getFormat( +R"#("%s": { + "levels": { +)#", + mon->szName.c_str() + ); + + int layerLevel = 0; + for (auto& level : mon->m_aLayerSurfaceLists) { + result += getFormat( +R"#( + "%i": [ +)#", + layerLevel + ); + for (auto& layer : level) { + result += getFormat( +R"#( { + "address": "0x%x", + "x": %i, + "y": %i, + "w": %i, + "h": %i, + "namespace": "%s" + },)#", + layer, + layer->geometry.x, + layer->geometry.y, + layer->geometry.width, + layer->geometry.height, + layer->szNamespace.c_str() + ); + } + + // remove trailing comma + result.pop_back(); + + if (level.size() > 0) + result += "\n "; + + result += "],"; + + layerLevel++; } - layerLevel++; + // remove trailing comma + result.pop_back(); + + result += "\n }\n},"; + } + + // remove trailing comma + result.pop_back(); + + result += "\n}\n"; + + } else { + for (auto& mon : g_pCompositor->m_vMonitors) { + result += getFormat("Monitor %s:\n", mon->szName.c_str()); + int layerLevel = 0; + for (auto& level : mon->m_aLayerSurfaceLists) { + result += getFormat("\tLayer level %i:\n", layerLevel); + + for (auto& layer : level) { + result += getFormat("\t\tLayer %x: xywh: %i %i %i %i, namespace: %s\n", layer, layer->geometry.x, layer->geometry.y, layer->geometry.width, layer->geometry.height, layer->szNamespace.c_str()); + } + + layerLevel++; + } + result += "\n\n"; } - result += "\n\n"; } return result; } -std::string devicesRequest() { +std::string devicesRequest(bool json) { std::string result = ""; - result += "mice:\n"; + if (json) { + result += "{\n"; + result += "\"mice\": [\n"; + + for (auto& m : g_pInputManager->m_lMice) { + result += getFormat( +R"#( { + "address": "0x%x", + "name": "%s" + },)#", + &m, + m.mouse->name + ); + } - for (auto& m : g_pInputManager->m_lMice) { - result += getFormat("\tMouse at %x:\n\t\t%s\n", &m, m.mouse->name); - } + // remove trailing comma + result.pop_back(); + result += "\n],\n"; + + result += "\"keyboards\": [\n"; + for (auto& k : g_pInputManager->m_lKeyboards) { + result += getFormat( +R"#( { + "address": "0x%x", + "name": "%s", + "rules": "%s", + "model": "%s", + "layout": "%s", + "variant": "%s", + "options": "%s" + },)#", + &k, + k.keyboard->name, + k.currentRules.rules.c_str(), + k.currentRules.model.c_str(), + k.currentRules.layout.c_str(), + k.currentRules.variant.c_str(), + k.currentRules.options.c_str() + ); + } - result += "\n\nKeyboards:\n"; + // remove trailing comma + result.pop_back(); + result += "\n],\n"; - for (auto& k : g_pInputManager->m_lKeyboards) { - result += getFormat("\tKeyboard at %x:\n\t\t%s\n\t\t\trules: r \"%s\", m \"%s\", l \"%s\", v \"%s\", o \"%s\"\n", &k, k.keyboard->name, k.currentRules.rules.c_str(), k.currentRules.model.c_str(), k.currentRules.layout.c_str(), k.currentRules.variant.c_str(), k.currentRules.options.c_str()); - } + result += "\"tablets\": [\n"; - result += "\n\nTablets:\n"; + for (auto& d : g_pInputManager->m_lTabletPads) { + result += getFormat( +R"#( { + "address": "0x%x", + "type": "tabletPad", + "belongsTo": { + "address": "0x%x", + "name": "%s" + } + },)#", + &d, + d.pTabletParent, + d.pTabletParent ? d.pTabletParent->wlrDevice ? d.pTabletParent->wlrDevice->name : "" : "" + ); + } - for (auto& d : g_pInputManager->m_lTabletPads) { - result += getFormat("\tTablet Pad at %x (belongs to %x -> %s)\n", &d, d.pTabletParent, d.pTabletParent ? d.pTabletParent->wlrDevice ? d.pTabletParent->wlrDevice->name : "" : ""); - } + for (auto& d : g_pInputManager->m_lTablets) { + result += getFormat( +R"#( { + "address": "0x%x", + "name": "%s" + },)#", + &d, + d.wlrDevice ? d.wlrDevice->name : "" + ); + } - for (auto& d : g_pInputManager->m_lTablets) { - result += getFormat("\tTablet at %x:\n\t\t%s\n", &d, d.wlrDevice ? d.wlrDevice->name : ""); - } + for (auto& d : g_pInputManager->m_lTabletTools) { + result += getFormat( +R"#( { + "address": "0x%x", + "type": "tabletTool", + "belongsTo": "0x%x" + },)#", + &d, + d.wlrTabletTool ? d.wlrTabletTool->data : 0 + ); + } + + // remove trailing comma + if (result[result.size() - 1] == ',') + result.pop_back(); + result += "\n]\n"; - for (auto& d : g_pInputManager->m_lTabletTools) { - result += getFormat("\tTablet Tool at %x (belongs to %x)\n", &d, d.wlrTabletTool ? d.wlrTabletTool->data : 0); + result += "}\n"; + + } else { + result += "mice:\n"; + + for (auto& m : g_pInputManager->m_lMice) { + result += getFormat("\tMouse at %x:\n\t\t%s\n", &m, m.mouse->name); + } + + result += "\n\nKeyboards:\n"; + + for (auto& k : g_pInputManager->m_lKeyboards) { + result += getFormat("\tKeyboard at %x:\n\t\t%s\n\t\t\trules: r \"%s\", m \"%s\", l \"%s\", v \"%s\", o \"%s\"\n", &k, k.keyboard->name, k.currentRules.rules.c_str(), k.currentRules.model.c_str(), k.currentRules.layout.c_str(), k.currentRules.variant.c_str(), k.currentRules.options.c_str()); + } + + result += "\n\nTablets:\n"; + + for (auto& d : g_pInputManager->m_lTabletPads) { + result += getFormat("\tTablet Pad at %x (belongs to %x -> %s)\n", &d, d.pTabletParent, d.pTabletParent ? d.pTabletParent->wlrDevice ? d.pTabletParent->wlrDevice->name : "" : ""); + } + + for (auto& d : g_pInputManager->m_lTablets) { + result += getFormat("\tTablet at %x:\n\t\t%s\n", &d, d.wlrDevice ? d.wlrDevice->name : ""); + } + + for (auto& d : g_pInputManager->m_lTabletTools) { + result += getFormat("\tTablet Tool at %x (belongs to %x)\n", &d, d.wlrTabletTool ? d.wlrTabletTool->data : 0); + } } return result; @@ -220,24 +511,29 @@ std::string dispatchBatch(std::string request) { } std::string getReply(std::string request) { + std::size_t jpos = request.find(" -j"); + bool json = jpos != std::string::npos; + if (json) + request.erase(jpos, 3); // remove the `-j` flag so `==` still works + if (request == "monitors") - return monitorsRequest(); + return monitorsRequest(json); else if (request == "workspaces") - return workspacesRequest(); + return workspacesRequest(json); else if (request == "clients") - return clientsRequest(); + return clientsRequest(json); else if (request == "kill") return killRequest(); else if (request == "activewindow") - return activeWindowRequest(); + return activeWindowRequest(json); else if (request == "layers") - return layersRequest(); + return layersRequest(json); else if (request == "version") return versionRequest(); else if (request == "reload") return reloadRequest(); else if (request == "devices") - return devicesRequest(); + return devicesRequest(json); else if (request == "splash") return splashRequest(); else if (request.find("dispatch") == 0) -- cgit v1.2.3 From 2402f2e36498686dfebe7c06f1203f595b888252 Mon Sep 17 00:00:00 2001 From: bazuin-32 Date: Tue, 12 Jul 2022 14:59:36 -0600 Subject: Use enum for specifying hyprctl output format and change the way flags are passed for json output --- src/debug/HyprCtl.cpp | 56 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 22 deletions(-) (limited to 'src/debug/HyprCtl.cpp') diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index 40480bd3..76fe3c56 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -13,9 +13,9 @@ #include -std::string monitorsRequest(bool json) { +std::string monitorsRequest(HyprCtl::eHyprCtlOutputFormat format) { std::string result = ""; - if (json) { + if (format == HyprCtl::FORMAT_JSON) { result += "["; for (auto& m : g_pCompositor->m_vMonitors) { @@ -64,9 +64,9 @@ R"#({ return result; } -std::string clientsRequest(bool json) { +std::string clientsRequest(HyprCtl::eHyprCtlOutputFormat format) { std::string result = ""; - if (json) { + if (format == HyprCtl::FORMAT_JSON) { result += "["; for (auto& w : g_pCompositor->m_vWindows) { @@ -115,9 +115,9 @@ R"#({ return result; } -std::string workspacesRequest(bool json) { +std::string workspacesRequest(HyprCtl::eHyprCtlOutputFormat format) { std::string result = ""; - if (json) { + if (format == HyprCtl::FORMAT_JSON) { result += "["; for (auto& w : g_pCompositor->m_vWorkspaces) { @@ -150,13 +150,13 @@ R"#({ return result; } -std::string activeWindowRequest(bool json) { +std::string activeWindowRequest(HyprCtl::eHyprCtlOutputFormat format) { const auto PWINDOW = g_pCompositor->m_pLastWindow; if (!g_pCompositor->windowValidMapped(PWINDOW)) return "Invalid"; - if (json) { + if (format == HyprCtl::FORMAT_JSON) { return getFormat( R"#({ "address": "0x%x", @@ -188,10 +188,10 @@ R"#({ } } -std::string layersRequest(bool json) { +std::string layersRequest(HyprCtl::eHyprCtlOutputFormat format) { std::string result = ""; - if (json) { + if (format == HyprCtl::FORMAT_JSON) { result += "{\n"; for (auto& mon : g_pCompositor->m_vMonitors) { @@ -271,10 +271,10 @@ R"#( { return result; } -std::string devicesRequest(bool json) { +std::string devicesRequest(HyprCtl::eHyprCtlOutputFormat format) { std::string result = ""; - if (json) { + if (format == HyprCtl::FORMAT_JSON) { result += "{\n"; result += "\"mice\": [\n"; @@ -511,29 +511,41 @@ std::string dispatchBatch(std::string request) { } std::string getReply(std::string request) { - std::size_t jpos = request.find(" -j"); - bool json = jpos != std::string::npos; - if (json) - request.erase(jpos, 3); // remove the `-j` flag so `==` still works + auto format = HyprCtl::FORMAT_NORMAL; + + // process flags + int sepIndex = 0; + for (const auto& c : request) { + if (c == '/') { // stop at separator + break; + } + + sepIndex++; + + if (c == 'j') + format = HyprCtl::FORMAT_JSON; + } + + request = request.substr(sepIndex + 1); // remove flags and separator so we can compare the rest of the string if (request == "monitors") - return monitorsRequest(json); + return monitorsRequest(format); else if (request == "workspaces") - return workspacesRequest(json); + return workspacesRequest(format); else if (request == "clients") - return clientsRequest(json); + return clientsRequest(format); else if (request == "kill") return killRequest(); else if (request == "activewindow") - return activeWindowRequest(json); + return activeWindowRequest(format); else if (request == "layers") - return layersRequest(json); + return layersRequest(format); else if (request == "version") return versionRequest(); else if (request == "reload") return reloadRequest(); else if (request == "devices") - return devicesRequest(json); + return devicesRequest(format); else if (request == "splash") return splashRequest(); else if (request.find("dispatch") == 0) -- cgit v1.2.3 From ac9ff795cdfd25c37b9b9be44f3d034bfa3284d3 Mon Sep 17 00:00:00 2001 From: bazuin-32 Date: Tue, 12 Jul 2022 15:38:50 -0600 Subject: Fix calls to `substr` with invalid `pos` --- src/debug/HyprCtl.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/debug/HyprCtl.cpp') diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index 76fe3c56..684bca9c 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -526,7 +526,8 @@ std::string getReply(std::string request) { format = HyprCtl::FORMAT_JSON; } - request = request.substr(sepIndex + 1); // remove flags and separator so we can compare the rest of the string + if (sepIndex < request.size()) + request = request.substr(sepIndex + 1); // remove flags and separator so we can compare the rest of the string if (request == "monitors") return monitorsRequest(format); -- cgit v1.2.3 From ab859ec9fcd749f3f898684710085ff8dc1303d4 Mon Sep 17 00:00:00 2001 From: bazuin-32 Date: Tue, 12 Jul 2022 16:34:28 -0600 Subject: Fix issues with batch requests --- src/debug/HyprCtl.cpp | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'src/debug/HyprCtl.cpp') diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index 684bca9c..ab72d86e 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -513,22 +513,24 @@ std::string dispatchBatch(std::string request) { std::string getReply(std::string request) { auto format = HyprCtl::FORMAT_NORMAL; - // process flags - int sepIndex = 0; - for (const auto& c : request) { - if (c == '/') { // stop at separator - break; + // process flags for non-batch requests + if (!(request.find("[[BATCH]]") == 0)) { + int sepIndex = 0; + for (const auto& c : request) { + if (c == '/') { // stop at separator + break; + } + + sepIndex++; + + if (c == 'j') + format = HyprCtl::FORMAT_JSON; } - sepIndex++; - - if (c == 'j') - format = HyprCtl::FORMAT_JSON; + if (sepIndex < request.size()) + request = request.substr(sepIndex + 1); // remove flags and separator so we can compare the rest of the string } - if (sepIndex < request.size()) - request = request.substr(sepIndex + 1); // remove flags and separator so we can compare the rest of the string - if (request == "monitors") return monitorsRequest(format); else if (request == "workspaces") -- cgit v1.2.3 From 0a16513946c94483e008b3d0073db9fcc84b201e Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Wed, 13 Jul 2022 15:48:47 +0200 Subject: fix warning --- src/debug/HyprCtl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/debug/HyprCtl.cpp') diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index ab72d86e..67a20910 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -515,7 +515,7 @@ std::string getReply(std::string request) { // process flags for non-batch requests if (!(request.find("[[BATCH]]") == 0)) { - int sepIndex = 0; + long unsigned int sepIndex = 0; for (const auto& c : request) { if (c == '/') { // stop at separator break; -- cgit v1.2.3 From ef7ee2fd0f64a1a0a0088b90d3cbaeb6b3436c32 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Wed, 13 Jul 2022 16:02:14 +0200 Subject: added active keymap prop --- src/debug/HyprCtl.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/debug/HyprCtl.cpp') diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index 67a20910..cdc04ff4 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -295,6 +295,7 @@ R"#( { result += "\"keyboards\": [\n"; for (auto& k : g_pInputManager->m_lKeyboards) { + const auto KM = xkb_keymap_layout_get_name(wlr_keyboard_from_input_device(k.keyboard)->keymap, 0); result += getFormat( R"#( { "address": "0x%x", @@ -303,7 +304,8 @@ R"#( { "model": "%s", "layout": "%s", "variant": "%s", - "options": "%s" + "options": "%s", + "active_keymap": "%s" },)#", &k, k.keyboard->name, @@ -311,7 +313,8 @@ R"#( { k.currentRules.model.c_str(), k.currentRules.layout.c_str(), k.currentRules.variant.c_str(), - k.currentRules.options.c_str() + k.currentRules.options.c_str(), + KM ); } @@ -377,7 +380,8 @@ R"#( { result += "\n\nKeyboards:\n"; for (auto& k : g_pInputManager->m_lKeyboards) { - result += getFormat("\tKeyboard at %x:\n\t\t%s\n\t\t\trules: r \"%s\", m \"%s\", l \"%s\", v \"%s\", o \"%s\"\n", &k, k.keyboard->name, k.currentRules.rules.c_str(), k.currentRules.model.c_str(), k.currentRules.layout.c_str(), k.currentRules.variant.c_str(), k.currentRules.options.c_str()); + const auto KM = xkb_keymap_layout_get_name(wlr_keyboard_from_input_device(k.keyboard)->keymap, 0); + result += getFormat("\tKeyboard at %x:\n\t\t%s\n\t\t\trules: r \"%s\", m \"%s\", l \"%s\", v \"%s\", o \"%s\"\n\t\t\tactive keymap: %s\n", &k, k.keyboard->name, k.currentRules.rules.c_str(), k.currentRules.model.c_str(), k.currentRules.layout.c_str(), k.currentRules.variant.c_str(), k.currentRules.options.c_str(), KM); } result += "\n\nTablets:\n"; -- cgit v1.2.3 From 6708f3b1334e8b6a966f424fe04713a4e74d5fdb Mon Sep 17 00:00:00 2001 From: Vaxry <43317083+vaxerski@users.noreply.github.com> Date: Wed, 13 Jul 2022 18:18:23 +0200 Subject: Fixed TTY switching (#364) --- src/debug/HyprCtl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/debug/HyprCtl.cpp') diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index cdc04ff4..6b94ce1d 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -593,7 +593,7 @@ std::string getRequestFromThread(std::string rq) { // this might be a race condition // tested with 2 instances of `watch -n 0.1 hyprctl splash` and seems to not crash so I'll take that as a yes if (!*PNOVFR) - wlr_output_schedule_frame(g_pCompositor->m_vMonitors.front()->output); + g_pCompositor->scheduleFrameForMonitor(g_pCompositor->m_vMonitors.front().get()); while (HyprCtl::request != "" || HyprCtl::requestMade || HyprCtl::requestReady) { std::this_thread::sleep_for(std::chrono::milliseconds(5)); -- cgit v1.2.3 From 65e75c0b4427965a0fa3386e2bd27e58f195d2d6 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Thu, 14 Jul 2022 11:43:15 +0200 Subject: fix backwards hyprctl compat --- src/debug/HyprCtl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/debug/HyprCtl.cpp') diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index 6b94ce1d..1e6a8e32 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -518,7 +518,7 @@ std::string getReply(std::string request) { auto format = HyprCtl::FORMAT_NORMAL; // process flags for non-batch requests - if (!(request.find("[[BATCH]]") == 0)) { + if (!request.contains("[[BATCH]]") && request.contains("/")) { long unsigned int sepIndex = 0; for (const auto& c : request) { if (c == '/') { // stop at separator -- cgit v1.2.3