mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-25 03:25:57 +01:00
Make the thread manager into a wl event loop timer
This commit is contained in:
parent
189cbe9f09
commit
75ce01b1a7
2 changed files with 19 additions and 26 deletions
|
@ -1,34 +1,29 @@
|
|||
#include "ThreadManager.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() {
|
||||
m_tMainThread = new std::thread([&]() {
|
||||
// Call the handle method.
|
||||
this->handle();
|
||||
});
|
||||
g_pConfigManager->init();
|
||||
|
||||
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() {
|
||||
//
|
||||
}
|
||||
|
||||
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")));
|
||||
}
|
||||
}
|
|
@ -9,11 +9,9 @@ public:
|
|||
CThreadManager();
|
||||
~CThreadManager();
|
||||
|
||||
private:
|
||||
wl_event_source* m_esConfigTimer;
|
||||
|
||||
void handle();
|
||||
|
||||
std::thread* m_tMainThread;
|
||||
private:
|
||||
};
|
||||
|
||||
inline std::unique_ptr<CThreadManager> g_pThreadManager;
|
Loading…
Reference in a new issue