diff options
| author | vaxerski <43317083+vaxerski@users.noreply.github.com> | 2022-03-22 16:54:45 +0100 |
|---|---|---|
| committer | vaxerski <43317083+vaxerski@users.noreply.github.com> | 2022-03-22 16:54:45 +0100 |
| commit | 8a8b26a6357528a736c4a28ff70aff6b3d397190 (patch) | |
| tree | 31485c1cd2916d2c0f01488ad01152efa5ba35da /src/debug/HyprCtl.cpp | |
| parent | 7b612b46b8541ffb20757749ac7b37cf76dcf755 (diff) | |
added 2 more hyprctl commands
Diffstat (limited to 'src/debug/HyprCtl.cpp')
| -rw-r--r-- | src/debug/HyprCtl.cpp | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index 67b38a9a..052d512d 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -52,6 +52,37 @@ std::string workspacesRequest() { return result; } +std::string activeWindowRequest() { + const auto PWINDOW = g_pCompositor->getWindowFromSurface(g_pCompositor->m_pLastFocus); + + if (!g_pCompositor->windowValidMapped(PWINDOW)) + return "Invalid"; + + return getFormat("Window %x -> %s:\n\tat: %i,%i\n\tsize: %i, %i\n\tworkspace: %i\n\tfloating: %i\n\n", + PWINDOW, PWINDOW->m_szTitle.c_str(), (int)PWINDOW->m_vRealPosition.x, (int)PWINDOW->m_vRealPosition.y, (int)PWINDOW->m_vRealSize.x, (int)PWINDOW->m_vRealSize.y, PWINDOW->m_iWorkspaceID, (int)PWINDOW->m_bIsFloating); +} + +std::string layersRequest() { + std::string result = ""; + + for (auto& mon : g_pCompositor->m_lMonitors) { + result += getFormat("Monitor %s:\n"); + 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 -> %s: xywh: %i %i %i %i\n", layer, (layer->layerSurface ? layer->layerSurface->_namespace : "null"), layer->geometry.x, layer->geometry.y, layer->geometry.width, layer->geometry.height); + } + + layerLevel++; + } + result += "\n\n"; + } + + return result; +} + void HyprCtl::startHyprCtlSocket() { int port = 9187; @@ -63,9 +94,20 @@ void HyprCtl::startHyprCtlSocket() { return; } - const sockaddr_in SERVERADDRESS = {.sin_family = AF_INET, .sin_port = port, .sin_addr = (in_addr)INADDR_ANY}; + sockaddr_in SERVERADDRESS = {.sin_family = AF_INET, .sin_port = port, .sin_addr = (in_addr)INADDR_ANY}; + + bool bound = false; - if (bind(SOCKET, (sockaddr*)&SERVERADDRESS, sizeof(SERVERADDRESS)) < 0) { + while (port++ < 9200) { + if (bind(SOCKET, (sockaddr*)&SERVERADDRESS, sizeof(SERVERADDRESS)) >= 0) { + bound = true; + break; + } + + SERVERADDRESS = {.sin_family = AF_INET, .sin_port = port, .sin_addr = (in_addr)INADDR_ANY}; + } + + if (!bound) { Debug::log(ERR, "Couldn't start the Hyprland Socket. (2) IPC will not work."); return; } @@ -100,10 +142,14 @@ void HyprCtl::startHyprCtlSocket() { if (request == "monitors") reply = monitorsRequest(); if (request == "workspaces") reply = workspacesRequest(); if (request == "clients") reply = clientsRequest(); + if (request == "activewindow") reply = activeWindowRequest(); + if (request == "layers") reply = layersRequest(); write(ACCEPTEDCONNECTION, reply.c_str(), reply.length()); close(ACCEPTEDCONNECTION); } + + close(SOCKET); }).detach(); }
\ No newline at end of file |
