pointer: update geometry after unplug events

fixes #6700

fixes #6740
This commit is contained in:
Vaxry 2024-07-05 23:05:03 +02:00
parent 0502c3f62b
commit cc98594c3a
4 changed files with 46 additions and 15 deletions

View file

@ -413,7 +413,7 @@ void CCompositor::initManagers(eManagersInitStage stage) {
switch (stage) {
case STAGE_PRIORITY: {
Debug::log(LOG, "Creating the EventLoopManager!");
g_pEventLoopManager = std::make_unique<CEventLoopManager>();
g_pEventLoopManager = std::make_unique<CEventLoopManager>(m_sWLDisplay, m_sWLEventLoop);
Debug::log(LOG, "Creating the HookSystem!");
g_pHookSystem = std::make_unique<CHookSystemManager>();
@ -604,7 +604,7 @@ void CCompositor::startCompositor() {
// This blocks until we are done.
Debug::log(LOG, "Hyprland is ready, running the event loop!");
g_pEventLoopManager->enterLoop(m_sWLDisplay, m_sWLEventLoop);
g_pEventLoopManager->enterLoop();
}
CMonitor* CCompositor::getMonitorFromID(const int& id) {

View file

@ -4,6 +4,7 @@
#include "../protocols/PointerGestures.hpp"
#include "../protocols/FractionalScale.hpp"
#include "../protocols/core/Compositor.hpp"
#include "eventLoop/EventLoopManager.hpp"
#include "SeatManager.hpp"
#include <wlr/interfaces/wlr_output.h>
#include <wlr/render/interface.h>
@ -139,8 +140,8 @@ CPointerManager::CPointerManager() {
onMonitorLayoutChange();
PMONITOR->events.modeChanged.registerStaticListener([this](void* owner, std::any data) { onMonitorLayoutChange(); }, nullptr);
PMONITOR->events.disconnect.registerStaticListener([this](void* owner, std::any data) { onMonitorLayoutChange(); }, nullptr);
PMONITOR->events.modeChanged.registerStaticListener([this](void* owner, std::any data) { g_pEventLoopManager->doLater([this]() { onMonitorLayoutChange(); }); }, nullptr);
PMONITOR->events.disconnect.registerStaticListener([this](void* owner, std::any data) { g_pEventLoopManager->doLater([this]() { onMonitorLayoutChange(); }); }, nullptr);
PMONITOR->events.destroy.registerStaticListener(
[this](void* owner, std::any data) {
if (g_pCompositor && !g_pCompositor->m_bIsShuttingDown)

View file

@ -9,8 +9,10 @@
#define TIMESPEC_NSEC_PER_SEC 1000000000L
CEventLoopManager::CEventLoopManager() {
m_sTimers.timerfd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC);
CEventLoopManager::CEventLoopManager(wl_display* display, wl_event_loop* wlEventLoop) {
m_sTimers.timerfd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC);
m_sWayland.loop = wlEventLoop;
m_sWayland.display = display;
}
CEventLoopManager::~CEventLoopManager() {
@ -23,13 +25,10 @@ static int timerWrite(int fd, uint32_t mask, void* data) {
return 1;
}
void CEventLoopManager::enterLoop(wl_display* display, wl_event_loop* wlEventLoop) {
m_sWayland.loop = wlEventLoop;
m_sWayland.display = display;
void CEventLoopManager::enterLoop() {
m_sWayland.eventSource = wl_event_loop_add_fd(m_sWayland.loop, m_sTimers.timerfd, WL_EVENT_READABLE, timerWrite, nullptr);
m_sWayland.eventSource = wl_event_loop_add_fd(wlEventLoop, m_sTimers.timerfd, WL_EVENT_READABLE, timerWrite, nullptr);
wl_display_run(display);
wl_display_run(m_sWayland.display);
Debug::log(LOG, "Kicked off the event loop! :(");
}
@ -86,4 +85,25 @@ void CEventLoopManager::nudgeTimers() {
itimerspec ts = {.it_value = now};
timerfd_settime(m_sTimers.timerfd, TFD_TIMER_ABSTIME, &ts, nullptr);
}
}
void CEventLoopManager::doLater(const std::function<void()>& fn) {
m_sIdle.fns.emplace_back(fn);
if (m_sIdle.eventSource)
return;
m_sIdle.eventSource = wl_event_loop_add_idle(
m_sWayland.loop,
[](void* data) {
auto IDLE = (CEventLoopManager::SIdleData*)data;
auto cpy = IDLE->fns;
IDLE->fns.clear();
IDLE->eventSource = nullptr;
for (auto& c : cpy) {
if (c)
c();
}
},
&m_sIdle);
}

View file

@ -9,10 +9,10 @@
class CEventLoopManager {
public:
CEventLoopManager();
CEventLoopManager(wl_display* display, wl_event_loop* wlEventLoop);
~CEventLoopManager();
void enterLoop(wl_display* display, wl_event_loop* wlEventLoop);
void enterLoop();
// Note: will remove the timer if the ptr is lost.
void addTimer(SP<CEventLoopTimer> timer);
@ -23,6 +23,14 @@ class CEventLoopManager {
// recalculates timers
void nudgeTimers();
// schedules a function to run later, aka in a wayland idle event.
void doLater(const std::function<void()>& fn);
struct SIdleData {
wl_event_source* eventSource = nullptr;
std::vector<std::function<void()>> fns;
};
private:
struct {
wl_event_loop* loop = nullptr;
@ -34,6 +42,8 @@ class CEventLoopManager {
std::vector<SP<CEventLoopTimer>> timers;
int timerfd = -1;
} m_sTimers;
SIdleData m_sIdle;
};
inline std::unique_ptr<CEventLoopManager> g_pEventLoopManager;