core: move to inotify for monitoring the config files

instead of manually polling every second which is not efficient, use inotify.

an added bonus is that inotify is much much faster
This commit is contained in:
vaxerski 2025-01-19 15:39:19 +01:00
parent 0a0e56d99c
commit 8dd2cd41fb
13 changed files with 143 additions and 116 deletions

View file

@ -1,26 +0,0 @@
#include "ThreadManager.hpp"
#include "../debug/HyprCtl.hpp"
#include "../Compositor.hpp"
#include "../config/ConfigValue.hpp"
static int handleTimer(void* data) {
const auto PTM = (CThreadManager*)data;
static auto PDISABLECFGRELOAD = CConfigValue<Hyprlang::INT>("misc:disable_autoreload");
if (*PDISABLECFGRELOAD != 1)
g_pConfigManager->tick();
wl_event_source_timer_update(PTM->m_esConfigTimer, 1000);
return 0;
}
CThreadManager::CThreadManager() : m_esConfigTimer(wl_event_loop_add_timer(g_pCompositor->m_sWLEventLoop, handleTimer, this)) {
wl_event_source_timer_update(m_esConfigTimer, 1000);
}
CThreadManager::~CThreadManager() {
if (m_esConfigTimer)
wl_event_source_remove(m_esConfigTimer);
}

View file

@ -1,16 +0,0 @@
#pragma once
#include "../defines.hpp"
struct wl_event_source;
class CThreadManager {
public:
CThreadManager();
~CThreadManager();
wl_event_source* m_esConfigTimer = nullptr;
private:
};
inline std::unique_ptr<CThreadManager> g_pThreadManager;

View file

@ -1,6 +1,7 @@
#include "EventLoopManager.hpp"
#include "../../debug/Log.hpp"
#include "../../Compositor.hpp"
#include "../../config/ConfigWatcher.hpp"
#include <algorithm>
#include <limits>
@ -27,6 +28,8 @@ CEventLoopManager::~CEventLoopManager() {
wl_event_source_remove(m_sWayland.eventSource);
if (m_sIdle.eventSource)
wl_event_source_remove(m_sIdle.eventSource);
if (m_configWatcherInotifySource)
wl_event_source_remove(m_configWatcherInotifySource);
if (m_sTimers.timerfd >= 0)
close(m_sTimers.timerfd);
}
@ -42,9 +45,17 @@ static int aquamarineFDWrite(int fd, uint32_t mask, void* data) {
return 1;
}
static int configWatcherWrite(int fd, uint32_t mask, void* data) {
g_pConfigWatcher->onInotifyEvent();
return 0;
}
void CEventLoopManager::enterLoop() {
m_sWayland.eventSource = wl_event_loop_add_fd(m_sWayland.loop, m_sTimers.timerfd, WL_EVENT_READABLE, timerWrite, nullptr);
if (const auto FD = g_pConfigWatcher->getInotifyFD(); FD >= 0)
m_configWatcherInotifySource = wl_event_loop_add_fd(m_sWayland.loop, FD, WL_EVENT_READABLE, configWatcherWrite, nullptr);
aqPollFDs = g_pCompositor->m_pAqBackend->getPollFDs();
for (auto const& fd : aqPollFDs) {
m_sWayland.aqEventSources.emplace_back(wl_event_loop_add_fd(m_sWayland.loop, fd->fd, WL_EVENT_READABLE, aquamarineFDWrite, fd.get()));

View file

@ -51,6 +51,8 @@ class CEventLoopManager {
SIdleData m_sIdle;
std::vector<SP<Aquamarine::SPollFD>> aqPollFDs;
wl_event_source* m_configWatcherInotifySource = nullptr;
friend class CSyncTimeline;
};