summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorvaxerski <43317083+vaxerski@users.noreply.github.com>2022-03-20 16:51:14 +0100
committervaxerski <43317083+vaxerski@users.noreply.github.com>2022-03-20 16:51:14 +0100
commitc32917a5bac6919fbb419d299f1ebab82bbce5ba (patch)
tree5a958e0ed7b9eae3b94edb11ae481d5d2c2589f8 /src
parent5644e668ef55d4ceb8b34ec21a89984d5edefba7 (diff)
added hyprctl
Diffstat (limited to 'src')
-rw-r--r--src/Compositor.cpp3
-rw-r--r--src/debug/HyprCtl.cpp76
-rw-r--r--src/debug/HyprCtl.hpp10
-rw-r--r--src/main.cpp4
-rw-r--r--src/managers/ThreadManager.cpp3
5 files changed, 92 insertions, 4 deletions
diff --git a/src/Compositor.cpp b/src/Compositor.cpp
index 27e0d2fd..294ea753 100644
--- a/src/Compositor.cpp
+++ b/src/Compositor.cpp
@@ -1,6 +1,9 @@
#include "Compositor.hpp"
CCompositor::CCompositor() {
+ unlink("/tmp/hypr/hyprland.log");
+ unlink("/tmp/hypr/hyprlandd.log");
+ unlink("/tmp/hypr/.hyprlandrq");
m_sWLDisplay = wl_display_create();
diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp
new file mode 100644
index 00000000..1b06617a
--- /dev/null
+++ b/src/debug/HyprCtl.cpp
@@ -0,0 +1,76 @@
+#include "HyprCtl.hpp"
+
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include <string>
+
+std::string getFormat(const char* fmt, ...) {
+ char buf[2048] = "";
+
+ va_list args;
+ va_start(args, fmt);
+
+ vsprintf(buf, fmt , args);
+
+ va_end(args);
+
+ return std::string(buf);
+}
+
+std::string monitorsRequest() {
+ std::string result = "";
+ for (auto& m : g_pCompositor->m_lMonitors) {
+ result += getFormat("Monitor %s (ID %i):\n\t%ix%i@%f at %ix%i\n\tactive workspace: %i\n\treserved: %i %i %i %i\n\n",
+ m.szName.c_str(), m.ID, (int)m.vecSize.x, (int)m.vecSize.y, m.refreshRate, (int)m.vecPosition.x, (int)m.vecPosition.y, m.activeWorkspace, (int)m.vecReservedTopLeft.x, (int)m.vecReservedTopLeft.y, (int)m.vecReservedBottomRight.x, (int)m.vecReservedBottomRight.y);
+ }
+
+ return result;
+}
+
+std::string clientsRequest() {
+ std::string result = "";
+ for (auto& w : g_pCompositor->m_lWindows) {
+ result += getFormat("Window %x -> %s:\n\tat: %i,%i\n\tsize: %i, %i\n\tworkspace: %i\n\tfloating: %i\n\n",
+ &w, w.m_szTitle.c_str(), (int)w.m_vRealPosition.x, (int)w.m_vRealPosition.y, (int)w.m_vRealSize.x, (int)w.m_vRealSize.y, w.m_iWorkspaceID, (int)w.m_bIsFloating);
+ }
+ return result;
+}
+
+std::string workspacesRequest() {
+ std::string result = "";
+ for (auto& w : g_pCompositor->m_lWorkspaces) {
+ result += getFormat("workspace ID %i on monitor %s:\n\twindows: %i\n\thasfullscreen: %i\n\n",
+ w.ID, g_pCompositor->getMonitorFromID(w.monitorID)->szName.c_str(), g_pCompositor->getWindowsOnWorkspace(w.ID), (int)w.hasFullscreenWindow);
+ }
+ return result;
+}
+
+void HyprCtl::tickHyprCtl() {
+ struct stat buf;
+
+ if (stat("/tmp/hypr/.hyprlandrq", &buf) == 0) {
+ // file exists, let's open it
+
+ requestStream.open("/tmp/hypr/.hyprlandrq");
+
+ std::string request = "";
+ std::getline(requestStream, request);
+
+ requestStream.close();
+
+ std::string reply = "";
+ if (request == "R>monitors") reply = monitorsRequest();
+ if (request == "R>workspaces") reply = workspacesRequest();
+ if (request == "R>clients") reply = clientsRequest();
+
+ if (reply != "") {
+ std::ofstream ofs;
+ ofs.open("/tmp/hypr/.hyprlandrq", std::ios::trunc);
+ ofs << "RPLY:\n" << reply;
+ ofs.close();
+ }
+
+ // the hyprctl app deletes the file when done.
+ }
+} \ No newline at end of file
diff --git a/src/debug/HyprCtl.hpp b/src/debug/HyprCtl.hpp
new file mode 100644
index 00000000..41303364
--- /dev/null
+++ b/src/debug/HyprCtl.hpp
@@ -0,0 +1,10 @@
+#pragma once
+
+#include "../Compositor.hpp"
+#include <fstream>
+
+namespace HyprCtl {
+ void tickHyprCtl();
+
+ inline std::ifstream requestStream;
+}; \ No newline at end of file
diff --git a/src/main.cpp b/src/main.cpp
index 3784b342..57016425 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -4,10 +4,6 @@
#include "config/ConfigManager.hpp"
int main(int argc, char** argv) {
- const std::string DEBUGPATH = "/tmp/hypr/hyprland.log";
- const std::string DEBUGPATH2 = "/tmp/hypr/hyprlandd.log";
- unlink(DEBUGPATH2.c_str());
- unlink(DEBUGPATH.c_str());
if (!getenv("XDG_RUNTIME_DIR"))
RIP("XDG_RUNTIME_DIR not set!");
diff --git a/src/managers/ThreadManager.cpp b/src/managers/ThreadManager.cpp
index 003cb947..0e2e962c 100644
--- a/src/managers/ThreadManager.cpp
+++ b/src/managers/ThreadManager.cpp
@@ -1,4 +1,5 @@
#include "ThreadManager.hpp"
+#include "../debug/HyprCtl.hpp"
CThreadManager::CThreadManager() {
m_tMainThread = new std::thread([&]() {
@@ -20,6 +21,8 @@ void CThreadManager::handle() {
while (3.1415f) {
g_pConfigManager->tick();
+ HyprCtl::tickHyprCtl();
+
std::this_thread::sleep_for(std::chrono::microseconds(1000000 / g_pConfigManager->getInt("max_fps")));
}
} \ No newline at end of file