From 0647b5449c5e5d7d314b03793232a13097fe753f Mon Sep 17 00:00:00 2001 From: Pppp1116 Date: Fri, 3 Apr 2026 13:24:22 +0100 Subject: [PATCH] protocols: avoid repeated per-client work in hot paths --- src/protocols/RelativePointer.cpp | 19 ++++++++++++++----- src/protocols/RelativePointer.hpp | 3 ++- src/protocols/core/Output.cpp | 14 ++++++++------ 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/protocols/RelativePointer.cpp b/src/protocols/RelativePointer.cpp index 67bff46ed..39a963099 100644 --- a/src/protocols/RelativePointer.cpp +++ b/src/protocols/RelativePointer.cpp @@ -22,8 +22,12 @@ wl_client* CRelativePointer::client() { } void CRelativePointer::sendRelativeMotion(uint64_t time, const Vector2D& delta, const Vector2D& deltaUnaccel) { - m_resource->sendRelativeMotion(time >> 32, time & 0xFFFFFFFF, wl_fixed_from_double(delta.x), wl_fixed_from_double(delta.y), wl_fixed_from_double(deltaUnaccel.x), - wl_fixed_from_double(deltaUnaccel.y)); + sendRelativeMotion(time >> 32, time & 0xFFFFFFFF, wl_fixed_from_double(delta.x), wl_fixed_from_double(delta.y), wl_fixed_from_double(deltaUnaccel.x), + wl_fixed_from_double(deltaUnaccel.y)); +} + +void CRelativePointer::sendRelativeMotion(uint32_t timeHi, uint32_t timeLo, wl_fixed_t dx, wl_fixed_t dy, wl_fixed_t dxUnaccel, wl_fixed_t dyUnaccel) { + m_resource->sendRelativeMotion(timeHi, timeLo, dx, dy, dxUnaccel, dyUnaccel); } CRelativePointerProtocol::CRelativePointerProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) { @@ -58,16 +62,21 @@ void CRelativePointerProtocol::onGetRelativePointer(CZwpRelativePointerManagerV1 } void CRelativePointerProtocol::sendRelativeMotion(uint64_t time, const Vector2D& delta, const Vector2D& deltaUnaccel) { - if (!g_pSeatManager->m_state.pointerFocusResource) return; - const auto FOCUSED = g_pSeatManager->m_state.pointerFocusResource->client(); + const auto FOCUSED = g_pSeatManager->m_state.pointerFocusResource->client(); + const auto TIMEHI = sc(time >> 32); + const auto TIMELO = sc(time & 0xFFFFFFFF); + const auto DX = wl_fixed_from_double(delta.x); + const auto DY = wl_fixed_from_double(delta.y); + const auto DXUNACCEL = wl_fixed_from_double(deltaUnaccel.x); + const auto DYUNACCEL = wl_fixed_from_double(deltaUnaccel.y); for (auto const& rp : m_relativePointers) { if (FOCUSED != rp->client()) continue; - rp->sendRelativeMotion(time, delta, deltaUnaccel); + rp->sendRelativeMotion(TIMEHI, TIMELO, DX, DY, DXUNACCEL, DYUNACCEL); } } diff --git a/src/protocols/RelativePointer.hpp b/src/protocols/RelativePointer.hpp index 3d6a3e30f..d422aab57 100644 --- a/src/protocols/RelativePointer.hpp +++ b/src/protocols/RelativePointer.hpp @@ -11,6 +11,7 @@ class CRelativePointer { CRelativePointer(SP resource_); void sendRelativeMotion(uint64_t time, const Vector2D& delta, const Vector2D& deltaUnaccel); + void sendRelativeMotion(uint32_t timeHi, uint32_t timeLo, wl_fixed_t dx, wl_fixed_t dy, wl_fixed_t dxUnaccel, wl_fixed_t dyUnaccel); bool good(); wl_client* client(); @@ -42,4 +43,4 @@ class CRelativePointerProtocol : public IWaylandProtocol { namespace PROTO { inline UP relativePointer; -}; \ No newline at end of file +}; diff --git a/src/protocols/core/Output.cpp b/src/protocols/core/Output.cpp index dd9c31660..9278eb955 100644 --- a/src/protocols/core/Output.cpp +++ b/src/protocols/core/Output.cpp @@ -30,7 +30,11 @@ CWLOutputResource::CWLOutputResource(SP resource_, PHLMONITOR pMonito updateState(); - PROTO::compositor->forEachSurface([](SP surf) { + const auto PMONITOR = m_monitor.lock(); + if (!PMONITOR) + return; + + PROTO::compositor->forEachSurface([PMONITOR](SP surf) { auto HLSurf = Desktop::View::CWLSurface::fromResource(surf); if (!HLSurf) @@ -41,12 +45,10 @@ CWLOutputResource::CWLOutputResource(SP resource_, PHLMONITOR pMonito if (!GEOMETRY.has_value()) return; - for (auto& m : g_pCompositor->m_monitors) { - if (!m->logicalBox().expand(-4).overlaps(*GEOMETRY)) - continue; + if (!PMONITOR->logicalBox().expand(-4).overlaps(*GEOMETRY)) + return; - surf->enter(m); - } + surf->enter(PMONITOR); }); }