diff options
| author | Ikalco <73481042+ikalco@users.noreply.github.com> | 2024-12-01 11:14:35 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-01 17:14:35 +0000 |
| commit | 6d7544458d0fafcae410c1978a0cabce2fb4a346 (patch) | |
| tree | 77bac5cd967326e3f643cbb91fc7e7ae910d401c /src/protocols | |
| parent | d26439a0fe5594fb26d5a3c01571f9490a9a2d2c (diff) | |
cleanup: use doLater instead of adding idle event handlers (#8624)
Diffstat (limited to 'src/protocols')
| -rw-r--r-- | src/protocols/Tablet.cpp | 26 | ||||
| -rw-r--r-- | src/protocols/Tablet.hpp | 7 | ||||
| -rw-r--r-- | src/protocols/XDGShell.cpp | 18 | ||||
| -rw-r--r-- | src/protocols/XDGShell.hpp | 8 |
4 files changed, 28 insertions, 31 deletions
diff --git a/src/protocols/Tablet.cpp b/src/protocols/Tablet.cpp index d7f741b9..7768402b 100644 --- a/src/protocols/Tablet.cpp +++ b/src/protocols/Tablet.cpp @@ -2,6 +2,7 @@ #include "../devices/Tablet.hpp" #include "../Compositor.hpp" #include "../managers/SeatManager.hpp" +#include "../managers/eventLoop/EventLoopManager.hpp" #include "core/Seat.hpp" #include "core/Compositor.hpp" #include <algorithm> @@ -162,11 +163,6 @@ CTabletToolV2Resource::CTabletToolV2Resource(SP<CZwpTabletToolV2> resource_, SP< }); } -CTabletToolV2Resource::~CTabletToolV2Resource() { - if (frameSource) - wl_event_source_remove(frameSource); -} - bool CTabletToolV2Resource::good() { return resource->resource(); } @@ -205,20 +201,22 @@ void CTabletToolV2Resource::sendData() { } void CTabletToolV2Resource::queueFrame() { - if (frameSource) + if (frameQueued) 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) { - if (frameSource) { - if (removeSource) - wl_event_source_remove(frameSource); - frameSource = nullptr; - } +void CTabletToolV2Resource::sendFrame() { + frameQueued = false; - if (!current) + if (!current || !resource) return; timespec now; diff --git a/src/protocols/Tablet.hpp b/src/protocols/Tablet.hpp index 1ebcb1e5..8c99bee0 100644 --- a/src/protocols/Tablet.hpp +++ b/src/protocols/Tablet.hpp @@ -112,21 +112,20 @@ class CTabletV2Resource { class CTabletToolV2Resource { public: CTabletToolV2Resource(SP<CZwpTabletToolV2> resource_, SP<CTabletTool> tool_, SP<CTabletSeat> seat_); - ~CTabletToolV2Resource(); bool good(); void sendData(); void queueFrame(); - void sendFrame(bool removeSource = true); + void sendFrame(); bool current = false; WP<CWLSurfaceResource> lastSurf; WP<CTabletTool> tool; WP<CTabletSeat> seat; - wl_event_source* frameSource = nullptr; - bool inert = false; // removed was sent + bool frameQueued = false; + bool inert = false; // removed was sent private: SP<CZwpTabletToolV2> resource; diff --git a/src/protocols/XDGShell.cpp b/src/protocols/XDGShell.cpp index 688d0006..a542c394 100644 --- a/src/protocols/XDGShell.cpp +++ b/src/protocols/XDGShell.cpp @@ -3,6 +3,7 @@ #include <algorithm> #include "../Compositor.hpp" #include "../managers/SeatManager.hpp" +#include "../managers/eventLoop/EventLoopManager.hpp" #include "core/Seat.hpp" #include "core/Compositor.hpp" #include <cstring> @@ -469,8 +470,6 @@ CXDGSurfaceResource::CXDGSurfaceResource(SP<CXdgSurface> resource_, SP<CXDGWMBas CXDGSurfaceResource::~CXDGSurfaceResource() { events.destroy.emit(); - if (configureSource) - wl_event_source_remove(configureSource); if (surface) surface->resetRole(); } @@ -484,22 +483,23 @@ SP<CXDGSurfaceResource> CXDGSurfaceResource::fromResource(wl_resource* res) { return data ? data->self.lock() : nullptr; } -static void onConfigure(void* data) { - ((CXDGSurfaceResource*)data)->configure(); -} - uint32_t CXDGSurfaceResource::scheduleConfigure() { - if (configureSource) + if (configureScheduled) return scheduledSerial; - configureSource = wl_event_loop_add_idle(g_pCompositor->m_sWLEventLoop, onConfigure, this); scheduledSerial = wl_display_next_serial(g_pCompositor->m_sWLDisplay); + configureScheduled = true; + g_pEventLoopManager->doLater([this]() { configure(); }); + return scheduledSerial; } void CXDGSurfaceResource::configure() { - configureSource = nullptr; + if (!resource) + return; + + configureScheduled = false; resource->sendConfigure(scheduledSerial); } diff --git a/src/protocols/XDGShell.hpp b/src/protocols/XDGShell.hpp index ef847f3b..3b7d2d11 100644 --- a/src/protocols/XDGShell.hpp +++ b/src/protocols/XDGShell.hpp @@ -199,12 +199,12 @@ class CXDGSurfaceResource { void configure(); private: - SP<CXdgSurface> resource; + SP<CXdgSurface> resource; - uint32_t lastConfigureSerial = 0; - uint32_t scheduledSerial = 0; + uint32_t lastConfigureSerial = 0; + uint32_t scheduledSerial = 0; - wl_event_source* configureSource = nullptr; + bool configureScheduled = false; // std::vector<WP<CXDGPopupResource>> popups; |
