mirror of
https://github.com/hyprwm/Hyprland
synced 2025-01-24 14:09:49 +01:00
core/renderer: Add GPU hotplug support (#8980)
This commit is contained in:
parent
fda5626594
commit
f1bd62806e
2 changed files with 47 additions and 14 deletions
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
#include <ranges>
|
||||||
|
|
||||||
#include <sys/timerfd.h>
|
#include <sys/timerfd.h>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
@ -20,8 +21,8 @@ CEventLoopManager::CEventLoopManager(wl_display* display, wl_event_loop* wlEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
CEventLoopManager::~CEventLoopManager() {
|
CEventLoopManager::~CEventLoopManager() {
|
||||||
for (auto const& eventSource : m_sWayland.aqEventSources) {
|
for (auto const& [_, eventSourceData] : aqEventSources) {
|
||||||
wl_event_source_remove(eventSource);
|
wl_event_source_remove(eventSourceData.eventSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_sWayland.eventSource)
|
if (m_sWayland.eventSource)
|
||||||
|
@ -56,10 +57,8 @@ void CEventLoopManager::enterLoop() {
|
||||||
if (const auto FD = g_pConfigWatcher->getInotifyFD(); FD >= 0)
|
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);
|
m_configWatcherInotifySource = wl_event_loop_add_fd(m_sWayland.loop, FD, WL_EVENT_READABLE, configWatcherWrite, nullptr);
|
||||||
|
|
||||||
aqPollFDs = g_pCompositor->m_pAqBackend->getPollFDs();
|
syncPollFDs();
|
||||||
for (auto const& fd : aqPollFDs) {
|
m_sListeners.pollFDsChanged = g_pCompositor->m_pAqBackend->events.pollFDsChanged.registerListener([this](std::any d) { syncPollFDs(); });
|
||||||
m_sWayland.aqEventSources.emplace_back(wl_event_loop_add_fd(m_sWayland.loop, fd->fd, WL_EVENT_READABLE, aquamarineFDWrite, fd.get()));
|
|
||||||
}
|
|
||||||
|
|
||||||
// if we have a session, dispatch it to get the pending input devices
|
// if we have a session, dispatch it to get the pending input devices
|
||||||
if (g_pCompositor->m_pAqBackend->hasSession())
|
if (g_pCompositor->m_pAqBackend->hasSession())
|
||||||
|
@ -144,3 +143,24 @@ void CEventLoopManager::doLater(const std::function<void()>& fn) {
|
||||||
},
|
},
|
||||||
&m_sIdle);
|
&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};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
|
#include <map>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <wayland-server.h>
|
#include <wayland-server.h>
|
||||||
|
#include "helpers/signal/Signal.hpp"
|
||||||
|
|
||||||
#include "EventLoopTimer.hpp"
|
#include "EventLoopTimer.hpp"
|
||||||
|
|
||||||
|
@ -36,11 +38,18 @@ class CEventLoopManager {
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// Manages the event sources after AQ pollFDs change.
|
||||||
|
void syncPollFDs();
|
||||||
|
|
||||||
|
struct SEventSourceData {
|
||||||
|
SP<Aquamarine::SPollFD> pollFD;
|
||||||
|
wl_event_source* eventSource = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
wl_event_loop* loop = nullptr;
|
wl_event_loop* loop = nullptr;
|
||||||
wl_display* display = nullptr;
|
wl_display* display = nullptr;
|
||||||
wl_event_source* eventSource = nullptr;
|
wl_event_source* eventSource = nullptr;
|
||||||
std::vector<wl_event_source*> aqEventSources;
|
|
||||||
} m_sWayland;
|
} m_sWayland;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
|
@ -48,10 +57,14 @@ class CEventLoopManager {
|
||||||
int timerfd = -1;
|
int timerfd = -1;
|
||||||
} m_sTimers;
|
} m_sTimers;
|
||||||
|
|
||||||
SIdleData m_sIdle;
|
SIdleData m_sIdle;
|
||||||
std::vector<SP<Aquamarine::SPollFD>> aqPollFDs;
|
std::map<int, SEventSourceData> aqEventSources;
|
||||||
|
|
||||||
wl_event_source* m_configWatcherInotifySource = nullptr;
|
struct {
|
||||||
|
CHyprSignalListener pollFDsChanged;
|
||||||
|
} m_sListeners;
|
||||||
|
|
||||||
|
wl_event_source* m_configWatcherInotifySource = nullptr;
|
||||||
|
|
||||||
friend class CSyncTimeline;
|
friend class CSyncTimeline;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue