cleanup: use doLater instead of adding idle event handlers (#8624)

This commit is contained in:
Ikalco 2024-12-01 11:14:35 -06:00 committed by GitHub
parent d26439a0fe
commit 6d7544458d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 32 additions and 39 deletions

View file

@ -2,6 +2,7 @@
#include "../devices/Tablet.hpp" #include "../devices/Tablet.hpp"
#include "../Compositor.hpp" #include "../Compositor.hpp"
#include "../managers/SeatManager.hpp" #include "../managers/SeatManager.hpp"
#include "../managers/eventLoop/EventLoopManager.hpp"
#include "core/Seat.hpp" #include "core/Seat.hpp"
#include "core/Compositor.hpp" #include "core/Compositor.hpp"
#include <algorithm> #include <algorithm>
@ -162,11 +163,6 @@ CTabletToolV2Resource::CTabletToolV2Resource(SP<CZwpTabletToolV2> resource_, SP<
}); });
} }
CTabletToolV2Resource::~CTabletToolV2Resource() {
if (frameSource)
wl_event_source_remove(frameSource);
}
bool CTabletToolV2Resource::good() { bool CTabletToolV2Resource::good() {
return resource->resource(); return resource->resource();
} }
@ -205,20 +201,22 @@ void CTabletToolV2Resource::sendData() {
} }
void CTabletToolV2Resource::queueFrame() { void CTabletToolV2Resource::queueFrame() {
if (frameSource) if (frameQueued)
return; return;
frameSource = wl_event_loop_add_idle(g_pCompositor->m_sWLEventLoop, [](void* data) { ((CTabletToolV2Resource*)data)->sendFrame(false); }, this); frameQueued = true;
g_pEventLoopManager->doLater([this]() {
if (!frameQueued || tool.expired() || inert)
return;
sendFrame();
});
} }
void CTabletToolV2Resource::sendFrame(bool removeSource) { void CTabletToolV2Resource::sendFrame() {
if (frameSource) { frameQueued = false;
if (removeSource)
wl_event_source_remove(frameSource);
frameSource = nullptr;
}
if (!current) if (!current || !resource)
return; return;
timespec now; timespec now;

View file

@ -112,21 +112,20 @@ class CTabletV2Resource {
class CTabletToolV2Resource { class CTabletToolV2Resource {
public: public:
CTabletToolV2Resource(SP<CZwpTabletToolV2> resource_, SP<CTabletTool> tool_, SP<CTabletSeat> seat_); CTabletToolV2Resource(SP<CZwpTabletToolV2> resource_, SP<CTabletTool> tool_, SP<CTabletSeat> seat_);
~CTabletToolV2Resource();
bool good(); bool good();
void sendData(); void sendData();
void queueFrame(); void queueFrame();
void sendFrame(bool removeSource = true); void sendFrame();
bool current = false; bool current = false;
WP<CWLSurfaceResource> lastSurf; WP<CWLSurfaceResource> lastSurf;
WP<CTabletTool> tool; WP<CTabletTool> tool;
WP<CTabletSeat> seat; WP<CTabletSeat> seat;
wl_event_source* frameSource = nullptr;
bool inert = false; // removed was sent bool frameQueued = false;
bool inert = false; // removed was sent
private: private:
SP<CZwpTabletToolV2> resource; SP<CZwpTabletToolV2> resource;

View file

@ -3,6 +3,7 @@
#include <algorithm> #include <algorithm>
#include "../Compositor.hpp" #include "../Compositor.hpp"
#include "../managers/SeatManager.hpp" #include "../managers/SeatManager.hpp"
#include "../managers/eventLoop/EventLoopManager.hpp"
#include "core/Seat.hpp" #include "core/Seat.hpp"
#include "core/Compositor.hpp" #include "core/Compositor.hpp"
#include <cstring> #include <cstring>
@ -469,8 +470,6 @@ CXDGSurfaceResource::CXDGSurfaceResource(SP<CXdgSurface> resource_, SP<CXDGWMBas
CXDGSurfaceResource::~CXDGSurfaceResource() { CXDGSurfaceResource::~CXDGSurfaceResource() {
events.destroy.emit(); events.destroy.emit();
if (configureSource)
wl_event_source_remove(configureSource);
if (surface) if (surface)
surface->resetRole(); surface->resetRole();
} }
@ -484,22 +483,23 @@ SP<CXDGSurfaceResource> CXDGSurfaceResource::fromResource(wl_resource* res) {
return data ? data->self.lock() : nullptr; return data ? data->self.lock() : nullptr;
} }
static void onConfigure(void* data) {
((CXDGSurfaceResource*)data)->configure();
}
uint32_t CXDGSurfaceResource::scheduleConfigure() { uint32_t CXDGSurfaceResource::scheduleConfigure() {
if (configureSource) if (configureScheduled)
return scheduledSerial; return scheduledSerial;
configureSource = wl_event_loop_add_idle(g_pCompositor->m_sWLEventLoop, onConfigure, this);
scheduledSerial = wl_display_next_serial(g_pCompositor->m_sWLDisplay); scheduledSerial = wl_display_next_serial(g_pCompositor->m_sWLDisplay);
configureScheduled = true;
g_pEventLoopManager->doLater([this]() { configure(); });
return scheduledSerial; return scheduledSerial;
} }
void CXDGSurfaceResource::configure() { void CXDGSurfaceResource::configure() {
configureSource = nullptr; if (!resource)
return;
configureScheduled = false;
resource->sendConfigure(scheduledSerial); resource->sendConfigure(scheduledSerial);
} }

View file

@ -199,12 +199,12 @@ class CXDGSurfaceResource {
void configure(); void configure();
private: private:
SP<CXdgSurface> resource; SP<CXdgSurface> resource;
uint32_t lastConfigureSerial = 0; uint32_t lastConfigureSerial = 0;
uint32_t scheduledSerial = 0; uint32_t scheduledSerial = 0;
wl_event_source* configureSource = nullptr; bool configureScheduled = false;
// //
std::vector<WP<CXDGPopupResource>> popups; std::vector<WP<CXDGPopupResource>> popups;

View file

@ -176,11 +176,6 @@ static bool openSockets(std::array<int, 2>& sockets, int display) {
return true; return true;
} }
static void startServer(void* data) {
if (!g_pXWayland->pServer->start())
Debug::log(ERR, "The XWayland server could not start! XWayland will not work...");
}
static int xwaylandReady(int fd, uint32_t mask, void* data) { static int xwaylandReady(int fd, uint32_t mask, void* data) {
return g_pXWayland->pServer->ready(fd, mask); return g_pXWayland->pServer->ready(fd, mask);
} }
@ -308,9 +303,10 @@ bool CXWaylandServer::create() {
setenv("DISPLAY", displayName.c_str(), true); setenv("DISPLAY", displayName.c_str(), true);
// TODO: lazy mode g_pEventLoopManager->doLater([this]() {
if (!start())
idleSource = wl_event_loop_add_idle(g_pCompositor->m_sWLEventLoop, ::startServer, nullptr); Debug::log(ERR, "The XWayland server could not start! XWayland will not work...");
});
return true; return true;
} }