diff options
| author | Tom Englund <tomenglund26@gmail.com> | 2024-10-27 18:51:26 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-27 17:51:26 +0000 |
| commit | f9b52203f58bcb716144d89ee9f85fe12ebfe94d (patch) | |
| tree | 4ecf23106134d32a5411a185d7081f986cd0c33c /src/managers/input/InputManager.cpp | |
| parent | a3d3b4fd64a51a8c1663b450bd2a408f1f0fa9b3 (diff) | |
internal: optimize cursor move a bit (#8264)
* window: inline and const getWindowMainSurfaceBox
getWindowMainSurfaceBox gets called a lot of times from deep down from
mousemoveunified, profiling mousemoveunified it spends quite a lot of
cpu time in here, let the compiler optimize the call to
getWindowMainSurfaceBox by inlining and making it const. reducing the
overhead.
* inputmgr: return early and use std::any_of
return early in mousemoveunified to reduce the amount of unnecessery
calls to various pointers when not needed, also make isconstrained use
std::any_of instead of for loop to use the STL optimized paths with
hopes and dreams marginally faster.
* decoration: return early, reduce temporar copy
return earlier and reduce the temp copies by using one .lock instead of
two
Diffstat (limited to 'src/managers/input/InputManager.cpp')
| -rw-r--r-- | src/managers/input/InputManager.cpp | 35 |
1 files changed, 13 insertions, 22 deletions
diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index 6f7d8017..028286bf 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -139,6 +139,15 @@ void CInputManager::sendMotionEventsToFocused() { } void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { + if (!g_pCompositor->m_bReadyToProcess || g_pCompositor->m_bIsShuttingDown || g_pCompositor->m_bUnsafeState) + return; + + Vector2D const mouseCoords = getMouseCoordsInternal(); + auto const MOUSECOORDSFLOORED = mouseCoords.floor(); + + if (MOUSECOORDSFLOORED == m_vLastCursorPosFloored && !refocus) + return; + static auto PFOLLOWMOUSE = CConfigValue<Hyprlang::INT>("input:follow_mouse"); static auto PMOUSEREFOCUS = CConfigValue<Hyprlang::INT>("input:mouse_refocus"); static auto PFOLLOWONDND = CConfigValue<Hyprlang::INT>("misc:always_follow_on_dnd"); @@ -159,15 +168,6 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { PHLWINDOW pFoundWindow; PHLLS pFoundLayerSurface; - if (!g_pCompositor->m_bReadyToProcess || g_pCompositor->m_bIsShuttingDown || g_pCompositor->m_bUnsafeState) - return; - - Vector2D mouseCoords = getMouseCoordsInternal(); - const auto MOUSECOORDSFLOORED = mouseCoords.floor(); - - if (MOUSECOORDSFLOORED == m_vLastCursorPosFloored && !refocus) - return; - EMIT_HOOK_EVENT_CANCELLABLE("mouseMove", MOUSECOORDSFLOORED); m_vLastCursorPosFloored = MOUSECOORDSFLOORED; @@ -1418,19 +1418,10 @@ void CInputManager::unconstrainMouse() { } bool CInputManager::isConstrained() { - for (auto const& c : m_vConstraints) { - const auto C = c.lock(); - - if (!C) - continue; - - if (!C->isActive() || C->owner()->resource() != g_pCompositor->m_pLastFocus) - continue; - - return true; - } - - return false; + return std::any_of(m_vConstraints.begin(), m_vConstraints.end(), [](auto const& c) { + const auto constraint = c.lock(); + return constraint && constraint->isActive() && constraint->owner()->resource() == g_pCompositor->m_pLastFocus; + }); } bool CInputManager::isLocked() { |
