From 7afcf656bd25e2ed6b33bae1cbbc4a62d66e1938 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Thu, 2 Jun 2022 13:59:33 +0200 Subject: Added hyprctl devices --- src/debug/HyprCtl.cpp | 20 ++++++++++++++++++++ src/helpers/MiscFunctions.cpp | 27 +++++++++++++++++++++++---- src/managers/InputManager.hpp | 9 ++++----- 3 files changed, 47 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index 07c388e3..c890dbb2 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -72,6 +72,24 @@ std::string layersRequest() { return result; } +std::string devicesRequest() { + std::string result = ""; + + 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", &k, k.keyboard->name); + } + + return result; +} + std::string versionRequest() { std::string result = "Hyprland, built from branch " + std::string(GIT_BRANCH) + " at commit " + GIT_COMMIT_HASH + GIT_DIRTY + " (" + GIT_COMMIT_MESSAGE + ").\nflags: (if any)\n"; @@ -186,6 +204,8 @@ std::string getReply(std::string request) { return versionRequest(); else if (request == "reload") return reloadRequest(); + else if (request == "devices") + return devicesRequest(); else if (request.find("dispatch") == 0) return dispatchRequest(request); else if (request.find("keyword") == 0) diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp index 6c53b8f2..7a947832 100644 --- a/src/helpers/MiscFunctions.cpp +++ b/src/helpers/MiscFunctions.cpp @@ -46,16 +46,35 @@ void wlr_signal_emit_safe(struct wl_signal *signal, void *data) { } std::string getFormat(const char *fmt, ...) { - char buf[2048] = ""; + char buf[LOGMESSAGESIZE] = ""; + char* outputStr; + int logLen; va_list args; va_start(args, fmt); + logLen = vsnprintf(buf, sizeof buf, fmt, args); + va_end(args); - vsprintf(buf, fmt, args); + if ((long unsigned int)logLen < sizeof buf) { + outputStr = strdup(buf); + } else { + outputStr = (char*)malloc(logLen + 1); - va_end(args); + if (!outputStr) { + printf("CRITICAL: Cannot alloc size %d for log! (Out of memory?)", logLen + 1); + return ""; + } + + va_start(args, fmt); + vsnprintf(outputStr, logLen + 1U, fmt, args); + va_end(args); + } + + std::string output = std::string(outputStr); + + free(outputStr); - return std::string(buf); + return output; } void scaleBox(wlr_box* box, float scale) { diff --git a/src/managers/InputManager.hpp b/src/managers/InputManager.hpp index 6850929b..3f5afc8a 100644 --- a/src/managers/InputManager.hpp +++ b/src/managers/InputManager.hpp @@ -36,12 +36,11 @@ public: SDrag m_sDrag; - std::list m_lConstraints; + std::list m_lConstraints; + std::list m_lKeyboards; + std::list m_lMice; -private: - - std::list m_lKeyboards; - std::list m_lMice; + private: void mouseMoveUnified(uint32_t, bool refocus = false); }; -- cgit v1.2.3