From c3eba7ea3c0e8a291a11c3773c643e5808d03551 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Sun, 31 Jul 2022 17:28:37 +0200 Subject: [PATCH] performance fixes + disabling ipc --- src/Hyprpaper.cpp | 44 +++++++++++++++++++++--------------- src/Hyprpaper.hpp | 3 +++ src/config/ConfigManager.cpp | 2 ++ src/ipc/Socket.cpp | 12 ++++++---- src/ipc/Socket.hpp | 2 +- 5 files changed, 39 insertions(+), 24 deletions(-) diff --git a/src/Hyprpaper.cpp b/src/Hyprpaper.cpp index 43e79ff..6a9b2ed 100644 --- a/src/Hyprpaper.cpp +++ b/src/Hyprpaper.cpp @@ -19,41 +19,49 @@ void CHyprpaper::init() { preloadAllWallpapersFromConfig(); - g_pIPCSocket->initialize(); + if (m_bIPCEnabled) + g_pIPCSocket->initialize(); // run wl_registry *registry = wl_display_get_registry(m_sDisplay); wl_registry_add_listener(registry, &Events::registryListener, nullptr); - std::thread([&]() { // we dispatch wl events cuz we have to + if (m_bIPCEnabled) { + std::thread([&]() { // we dispatch wl events cuz we have to + while (wl_display_dispatch(m_sDisplay) != -1) { + tick(); + } + + m_bShouldExit = true; + }).detach(); + + while (1) { // we also tick every 1ms for socket and other shit's updates + tick(); + + std::this_thread::sleep_for(std::chrono::milliseconds(1)); + + if (m_bShouldExit) + break; + } + } else { while (wl_display_dispatch(m_sDisplay) != -1) { tick(); } - - m_bShouldExit = true; - }).detach(); - - while (1) { // we also tick every 1ms for socket and other shit's updates - tick(); - - std::this_thread::sleep_for(std::chrono::milliseconds(1)); - - if (m_bShouldExit) - break; } } void CHyprpaper::tick() { - m_mtTickMutex.lock(); + std::lock_guard lg(m_mtTickMutex); + + bool reload = g_pIPCSocket->mainThreadParseRequest(); + + if (!reload) + return; preloadAllWallpapersFromConfig(); ensurePoolBuffersPresent(); recheckAllMonitors(); - - g_pIPCSocket->mainThreadParseRequest(); - - m_mtTickMutex.unlock(); } bool CHyprpaper::isPreloaded(const std::string& path) { diff --git a/src/Hyprpaper.hpp b/src/Hyprpaper.hpp index f87ffed..b698258 100644 --- a/src/Hyprpaper.hpp +++ b/src/Hyprpaper.hpp @@ -28,6 +28,8 @@ public: std::vector> m_vBuffers; std::vector> m_vMonitors; + bool m_bIPCEnabled = true; + void removeOldHyprpaperImages(); void preloadAllWallpapersFromConfig(); void recheckAllMonitors(); @@ -48,6 +50,7 @@ public: std::mutex m_mtTickMutex; private: + bool m_bShouldExit = false; }; diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 4bb7d7b..4617b89 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -95,6 +95,8 @@ void CConfigManager::parseKeyword(const std::string& COMMAND, const std::string& handlePreload(COMMAND, VALUE); else if (COMMAND == "unload") handleUnload(COMMAND, VALUE); + else if (COMMAND == "ipc") + g_pHyprpaper->m_bIPCEnabled = VALUE == "1" || VALUE == "yes" || VALUE == "on" || VALUE == "true"; else parseError = "unknown keyword " + COMMAND; } diff --git a/src/ipc/Socket.cpp b/src/ipc/Socket.cpp index ad42af0..367c342 100644 --- a/src/ipc/Socket.cpp +++ b/src/ipc/Socket.cpp @@ -84,17 +84,17 @@ void CIPCSocket::initialize() { }).detach(); } -void CIPCSocket::mainThreadParseRequest() { +bool CIPCSocket::mainThreadParseRequest() { if (!m_bRequestReady) - return; + return false; std::string copy = m_szRequest; // now we can work on the copy if (copy == "") - return; + return false; Debug::log(LOG, "Received a request: %s", copy.c_str()); @@ -108,17 +108,19 @@ void CIPCSocket::mainThreadParseRequest() { m_szReply = g_pConfigManager->parseError; m_bReplyReady = true; m_bRequestReady = false; - return; + return false; } } else { m_szReply = "invalid command"; m_bReplyReady = true; m_bRequestReady = false; - return; + return false; } m_szReply = "ok"; m_bReplyReady = true; m_bRequestReady = false; + + return true; } \ No newline at end of file diff --git a/src/ipc/Socket.hpp b/src/ipc/Socket.hpp index 985e53a..a616455 100644 --- a/src/ipc/Socket.hpp +++ b/src/ipc/Socket.hpp @@ -7,7 +7,7 @@ class CIPCSocket { public: void initialize(); - void mainThreadParseRequest(); + bool mainThreadParseRequest(); private: