diff options
| author | davc0n <dconti.dev@gmail.com> | 2025-05-01 23:57:11 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-01 23:57:11 +0200 |
| commit | 5b3e489108d8512fb5dfacf07b2aa3a71208e0f0 (patch) | |
| tree | 658b5136c8994731d858eeaedc7a09518c86e010 /src/managers/eventLoop | |
| parent | 2670b8f7724e94020f21fe81483e69d73e1337cf (diff) | |
inputs: refactor class member vars (#10230)
Diffstat (limited to 'src/managers/eventLoop')
| -rw-r--r-- | src/managers/eventLoop/EventLoopManager.cpp | 66 | ||||
| -rw-r--r-- | src/managers/eventLoop/EventLoopManager.hpp | 12 |
2 files changed, 39 insertions, 39 deletions
diff --git a/src/managers/eventLoop/EventLoopManager.cpp b/src/managers/eventLoop/EventLoopManager.cpp index 14ff75f5..338b75e3 100644 --- a/src/managers/eventLoop/EventLoopManager.cpp +++ b/src/managers/eventLoop/EventLoopManager.cpp @@ -16,25 +16,25 @@ using namespace Hyprutils::OS; #define TIMESPEC_NSEC_PER_SEC 1000000000L CEventLoopManager::CEventLoopManager(wl_display* display, wl_event_loop* wlEventLoop) { - m_sTimers.timerfd = CFileDescriptor{timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC)}; - m_sWayland.loop = wlEventLoop; - m_sWayland.display = display; + m_timers.timerfd = CFileDescriptor{timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC)}; + m_wayland.loop = wlEventLoop; + m_wayland.display = display; } CEventLoopManager::~CEventLoopManager() { - for (auto const& [_, eventSourceData] : aqEventSources) { + for (auto const& [_, eventSourceData] : m_aqEventSources) { wl_event_source_remove(eventSourceData.eventSource); } - for (auto const& w : m_vReadableWaiters) { + for (auto const& w : m_readableWaiters) { if (w->source != nullptr) wl_event_source_remove(w->source); } - if (m_sWayland.eventSource) - wl_event_source_remove(m_sWayland.eventSource); - if (m_sIdle.eventSource) - wl_event_source_remove(m_sIdle.eventSource); + if (m_wayland.eventSource) + wl_event_source_remove(m_wayland.eventSource); + if (m_idle.eventSource) + wl_event_source_remove(m_idle.eventSource); if (m_configWatcherInotifySource) wl_event_source_remove(m_configWatcherInotifySource); } @@ -68,7 +68,7 @@ static int handleWaiterFD(int fd, uint32_t mask, void* data) { } void CEventLoopManager::onFdReadable(SReadableWaiter* waiter) { - auto it = std::ranges::find_if(m_vReadableWaiters, [waiter](const UP<SReadableWaiter>& w) { return waiter == w.get() && w->fd == waiter->fd && w->source == waiter->source; }); + auto it = std::ranges::find_if(m_readableWaiters, [waiter](const UP<SReadableWaiter>& w) { return waiter == w.get() && w->fd == waiter->fd && w->source == waiter->source; }); if (waiter->source) { wl_event_source_remove(waiter->source); @@ -78,30 +78,30 @@ void CEventLoopManager::onFdReadable(SReadableWaiter* waiter) { if (waiter->fn) waiter->fn(); - if (it != m_vReadableWaiters.end()) - m_vReadableWaiters.erase(it); + if (it != m_readableWaiters.end()) + m_readableWaiters.erase(it); } void CEventLoopManager::enterLoop() { - m_sWayland.eventSource = wl_event_loop_add_fd(m_sWayland.loop, m_sTimers.timerfd.get(), WL_EVENT_READABLE, timerWrite, nullptr); + m_wayland.eventSource = wl_event_loop_add_fd(m_wayland.loop, m_timers.timerfd.get(), WL_EVENT_READABLE, timerWrite, nullptr); if (const auto& FD = g_pConfigWatcher->getInotifyFD(); FD.isValid()) - m_configWatcherInotifySource = wl_event_loop_add_fd(m_sWayland.loop, FD.get(), WL_EVENT_READABLE, configWatcherWrite, nullptr); + m_configWatcherInotifySource = wl_event_loop_add_fd(m_wayland.loop, FD.get(), WL_EVENT_READABLE, configWatcherWrite, nullptr); syncPollFDs(); - m_sListeners.pollFDsChanged = g_pCompositor->m_aqBackend->events.pollFDsChanged.registerListener([this](std::any d) { syncPollFDs(); }); + m_listeners.pollFDsChanged = g_pCompositor->m_aqBackend->events.pollFDsChanged.registerListener([this](std::any d) { syncPollFDs(); }); // if we have a session, dispatch it to get the pending input devices if (g_pCompositor->m_aqBackend->hasSession()) g_pCompositor->m_aqBackend->session->dispatchPendingEventsAsync(); - wl_display_run(m_sWayland.display); + wl_display_run(m_wayland.display); Debug::log(LOG, "Kicked off the event loop! :("); } void CEventLoopManager::onTimerFire() { - for (auto const& t : m_sTimers.timers) { + for (auto const& t : m_timers.timers) { if (t.strongRef() > 1 /* if it's 1, it was lost. Don't call it. */ && t->passed() && !t->cancelled()) t->call(t); } @@ -110,12 +110,12 @@ void CEventLoopManager::onTimerFire() { } void CEventLoopManager::addTimer(SP<CEventLoopTimer> timer) { - m_sTimers.timers.push_back(timer); + m_timers.timers.push_back(timer); nudgeTimers(); } void CEventLoopManager::removeTimer(SP<CEventLoopTimer> timer) { - std::erase_if(m_sTimers.timers, [timer](const auto& t) { return timer == t; }); + std::erase_if(m_timers.timers, [timer](const auto& t) { return timer == t; }); nudgeTimers(); } @@ -134,11 +134,11 @@ static void timespecAddNs(timespec* pTimespec, int64_t delta) { void CEventLoopManager::nudgeTimers() { // remove timers that have gone missing - std::erase_if(m_sTimers.timers, [](const auto& t) { return t.strongRef() <= 1; }); + std::erase_if(m_timers.timers, [](const auto& t) { return t.strongRef() <= 1; }); long nextTimerUs = 10L * 1000 * 1000; // 10s - for (auto const& t : m_sTimers.timers) { + for (auto const& t : m_timers.timers) { if (auto const& µs = t->leftUs(); µs < nextTimerUs) nextTimerUs = µs; } @@ -151,17 +151,17 @@ void CEventLoopManager::nudgeTimers() { itimerspec ts = {.it_value = now}; - timerfd_settime(m_sTimers.timerfd.get(), TFD_TIMER_ABSTIME, &ts, nullptr); + timerfd_settime(m_timers.timerfd.get(), TFD_TIMER_ABSTIME, &ts, nullptr); } void CEventLoopManager::doLater(const std::function<void()>& fn) { - m_sIdle.fns.emplace_back(fn); + m_idle.fns.emplace_back(fn); - if (m_sIdle.eventSource) + if (m_idle.eventSource) return; - m_sIdle.eventSource = wl_event_loop_add_idle( - m_sWayland.loop, + m_idle.eventSource = wl_event_loop_add_idle( + m_wayland.loop, [](void* data) { auto IDLE = (CEventLoopManager::SIdleData*)data; auto cpy = IDLE->fns; @@ -172,7 +172,7 @@ void CEventLoopManager::doLater(const std::function<void()>& fn) { c(); } }, - &m_sIdle); + &m_idle); } void CEventLoopManager::doOnReadable(CFileDescriptor fd, const std::function<void()>& fn) { @@ -181,14 +181,14 @@ void CEventLoopManager::doOnReadable(CFileDescriptor fd, const std::function<voi return; } - auto& waiter = m_vReadableWaiters.emplace_back(makeUnique<SReadableWaiter>(nullptr, std::move(fd), fn)); - waiter->source = wl_event_loop_add_fd(g_pEventLoopManager->m_sWayland.loop, waiter->fd.get(), WL_EVENT_READABLE, ::handleWaiterFD, waiter.get()); + auto& waiter = m_readableWaiters.emplace_back(makeUnique<SReadableWaiter>(nullptr, std::move(fd), fn)); + waiter->source = wl_event_loop_add_fd(g_pEventLoopManager->m_wayland.loop, waiter->fd.get(), WL_EVENT_READABLE, ::handleWaiterFD, waiter.get()); } void CEventLoopManager::syncPollFDs() { auto aqPollFDs = g_pCompositor->m_aqBackend->getPollFDs(); - std::erase_if(aqEventSources, [&](const auto& item) { + std::erase_if(m_aqEventSources, [&](const auto& item) { auto const& [fd, eventSourceData] = item; // If no pollFD has the same fd, remove this event source @@ -200,8 +200,8 @@ void CEventLoopManager::syncPollFDs() { return shouldRemove; }); - for (auto& fd : aqPollFDs | std::views::filter([&](SP<Aquamarine::SPollFD> fd) { return !aqEventSources.contains(fd->fd); })) { - auto eventSource = wl_event_loop_add_fd(m_sWayland.loop, fd->fd, WL_EVENT_READABLE, aquamarineFDWrite, fd.get()); - aqEventSources[fd->fd] = {.pollFD = fd, .eventSource = eventSource}; + for (auto& fd : aqPollFDs | std::views::filter([&](SP<Aquamarine::SPollFD> fd) { return !m_aqEventSources.contains(fd->fd); })) { + auto eventSource = wl_event_loop_add_fd(m_wayland.loop, fd->fd, WL_EVENT_READABLE, aquamarineFDWrite, fd.get()); + m_aqEventSources[fd->fd] = {.pollFD = fd, .eventSource = eventSource}; } } diff --git a/src/managers/eventLoop/EventLoopManager.hpp b/src/managers/eventLoop/EventLoopManager.hpp index 8a0e0439..a3c755a7 100644 --- a/src/managers/eventLoop/EventLoopManager.hpp +++ b/src/managers/eventLoop/EventLoopManager.hpp @@ -62,20 +62,20 @@ class CEventLoopManager { wl_event_loop* loop = nullptr; wl_display* display = nullptr; wl_event_source* eventSource = nullptr; - } m_sWayland; + } m_wayland; struct { std::vector<SP<CEventLoopTimer>> timers; Hyprutils::OS::CFileDescriptor timerfd; - } m_sTimers; + } m_timers; - SIdleData m_sIdle; - std::map<int, SEventSourceData> aqEventSources; - std::vector<UP<SReadableWaiter>> m_vReadableWaiters; + SIdleData m_idle; + std::map<int, SEventSourceData> m_aqEventSources; + std::vector<UP<SReadableWaiter>> m_readableWaiters; struct { CHyprSignalListener pollFDsChanged; - } m_sListeners; + } m_listeners; wl_event_source* m_configWatcherInotifySource = nullptr; |
