summaryrefslogtreecommitdiff
path: root/src/managers/eventLoop/EventLoopManager.cpp
diff options
context:
space:
mode:
authormaround95 <39220886+maround95@users.noreply.github.com>2025-01-23 13:08:19 +0200
committerGitHub <noreply@github.com>2025-01-23 11:08:19 +0000
commitf1bd62806e538fa2bfa7899c2b2ad02d6a5ca2db (patch)
treed5d43d42f7ab977a090db3b626288f0638ece427 /src/managers/eventLoop/EventLoopManager.cpp
parentfda5626594c3f31bbab08e877a797a623c98c450 (diff)
core/renderer: Add GPU hotplug support (#8980)
Diffstat (limited to 'src/managers/eventLoop/EventLoopManager.cpp')
-rw-r--r--src/managers/eventLoop/EventLoopManager.cpp32
1 files changed, 26 insertions, 6 deletions
diff --git a/src/managers/eventLoop/EventLoopManager.cpp b/src/managers/eventLoop/EventLoopManager.cpp
index f98efc92..4021c171 100644
--- a/src/managers/eventLoop/EventLoopManager.cpp
+++ b/src/managers/eventLoop/EventLoopManager.cpp
@@ -5,6 +5,7 @@
#include <algorithm>
#include <limits>
+#include <ranges>
#include <sys/timerfd.h>
#include <ctime>
@@ -20,8 +21,8 @@ CEventLoopManager::CEventLoopManager(wl_display* display, wl_event_loop* wlEvent
}
CEventLoopManager::~CEventLoopManager() {
- for (auto const& eventSource : m_sWayland.aqEventSources) {
- wl_event_source_remove(eventSource);
+ for (auto const& [_, eventSourceData] : aqEventSources) {
+ wl_event_source_remove(eventSourceData.eventSource);
}
if (m_sWayland.eventSource)
@@ -56,10 +57,8 @@ void CEventLoopManager::enterLoop() {
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()));
- }
+ syncPollFDs();
+ m_sListeners.pollFDsChanged = g_pCompositor->m_pAqBackend->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_pAqBackend->hasSession())
@@ -144,3 +143,24 @@ void CEventLoopManager::doLater(const std::function<void()>& fn) {
},
&m_sIdle);
}
+
+void CEventLoopManager::syncPollFDs() {
+ auto aqPollFDs = g_pCompositor->m_pAqBackend->getPollFDs();
+
+ std::erase_if(aqEventSources, [&](const auto& item) {
+ auto const& [fd, eventSourceData] = item;
+
+ // If no pollFD has the same fd, remove this event source
+ const bool shouldRemove = std::ranges::none_of(aqPollFDs, [&](const auto& pollFD) { return pollFD->fd == fd; });
+
+ if (shouldRemove)
+ wl_event_source_remove(eventSourceData.eventSource);
+
+ 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};
+ }
+}