Make the thread manager into a wl event loop timer

This commit is contained in:
vaxerski 2022-07-21 12:33:22 +02:00
parent 189cbe9f09
commit 75ce01b1a7
2 changed files with 19 additions and 26 deletions

View file

@ -1,34 +1,29 @@
#include "ThreadManager.hpp" #include "ThreadManager.hpp"
#include "../debug/HyprCtl.hpp" #include "../debug/HyprCtl.hpp"
#include "../Compositor.hpp"
int slowUpdate = 0;
int handleTimer(void* data) {
const auto PTM = (CThreadManager*)data;
g_pConfigManager->tick();
wl_event_source_timer_update(PTM->m_esConfigTimer, 1000);
return 0;
}
CThreadManager::CThreadManager() { CThreadManager::CThreadManager() {
m_tMainThread = new std::thread([&]() { g_pConfigManager->init();
// Call the handle method.
this->handle();
});
m_tMainThread->detach(); // detach and continue. HyprCtl::startHyprCtlSocket();
m_esConfigTimer = wl_event_loop_add_timer(g_pCompositor->m_sWLEventLoop, handleTimer, this);
wl_event_source_timer_update(m_esConfigTimer, 1000);
} }
CThreadManager::~CThreadManager() { CThreadManager::~CThreadManager() {
// //
} }
int slowUpdate = 0;
void CThreadManager::handle() {
g_pConfigManager->init();
HyprCtl::startHyprCtlSocket();
while (3.1415f) {
slowUpdate++;
if (slowUpdate >= g_pConfigManager->getInt("general:max_fps")){
g_pConfigManager->tick();
slowUpdate = 0;
}
std::this_thread::sleep_for(std::chrono::microseconds(1000000 / g_pConfigManager->getInt("general:max_fps")));
}
}

View file

@ -9,11 +9,9 @@ public:
CThreadManager(); CThreadManager();
~CThreadManager(); ~CThreadManager();
private: wl_event_source* m_esConfigTimer;
void handle(); private:
std::thread* m_tMainThread;
}; };
inline std::unique_ptr<CThreadManager> g_pThreadManager; inline std::unique_ptr<CThreadManager> g_pThreadManager;