diff options
| author | Kamikadze <40305144+Kam1k4dze@users.noreply.github.com> | 2025-05-30 18:25:59 +0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-30 14:25:59 +0100 |
| commit | 9190443d951c21ab24201d033accf90b4d172f46 (patch) | |
| tree | 28a5e4a1fa9c7424733ac7065a71cead7e141b6f /src/protocols/core | |
| parent | 9bf1b491440eac6f9c0d6853013ad5666c12d1d9 (diff) | |
refactor: use std::ranges whenever possible (#10584)
Diffstat (limited to 'src/protocols/core')
| -rw-r--r-- | src/protocols/core/Compositor.cpp | 4 | ||||
| -rw-r--r-- | src/protocols/core/DataDevice.cpp | 6 | ||||
| -rw-r--r-- | src/protocols/core/Seat.cpp | 4 | ||||
| -rw-r--r-- | src/protocols/core/Shm.cpp | 2 | ||||
| -rw-r--r-- | src/protocols/core/Subcompositor.cpp | 14 |
5 files changed, 14 insertions, 16 deletions
diff --git a/src/protocols/core/Compositor.cpp b/src/protocols/core/Compositor.cpp index 07bad77b..d1efe2e8 100644 --- a/src/protocols/core/Compositor.cpp +++ b/src/protocols/core/Compositor.cpp @@ -268,7 +268,7 @@ wl_client* CWLSurfaceResource::client() { } void CWLSurfaceResource::enter(PHLMONITOR monitor) { - if (std::find(m_enteredOutputs.begin(), m_enteredOutputs.end(), monitor) != m_enteredOutputs.end()) + if (std::ranges::find(m_enteredOutputs, monitor) != m_enteredOutputs.end()) return; if UNLIKELY (!PROTO::outputs.contains(monitor->m_name)) { @@ -295,7 +295,7 @@ void CWLSurfaceResource::enter(PHLMONITOR monitor) { } void CWLSurfaceResource::leave(PHLMONITOR monitor) { - if UNLIKELY (std::find(m_enteredOutputs.begin(), m_enteredOutputs.end(), monitor) == m_enteredOutputs.end()) + if UNLIKELY (std::ranges::find(m_enteredOutputs, monitor) == m_enteredOutputs.end()) return; auto output = PROTO::outputs.at(monitor->m_name)->outputResourceFrom(m_client); diff --git a/src/protocols/core/DataDevice.cpp b/src/protocols/core/DataDevice.cpp index ad580ed1..ec075e8b 100644 --- a/src/protocols/core/DataDevice.cpp +++ b/src/protocols/core/DataDevice.cpp @@ -171,7 +171,7 @@ void CWLDataSourceResource::accepted(const std::string& mime) { return; } - if (std::find(m_mimeTypes.begin(), m_mimeTypes.end(), mime) == m_mimeTypes.end()) { + if (std::ranges::find(m_mimeTypes, mime) == m_mimeTypes.end()) { LOGM(ERR, "Compositor/App bug: CWLDataSourceResource::sendAccepted with non-existent mime"); return; } @@ -184,7 +184,7 @@ std::vector<std::string> CWLDataSourceResource::mimes() { } void CWLDataSourceResource::send(const std::string& mime, CFileDescriptor fd) { - if (std::find(m_mimeTypes.begin(), m_mimeTypes.end(), mime) == m_mimeTypes.end()) { + if (std::ranges::find(m_mimeTypes, mime) == m_mimeTypes.end()) { LOGM(ERR, "Compositor/App bug: CWLDataSourceResource::sendAskSend with non-existent mime"); return; } @@ -424,7 +424,7 @@ SP<IDataDevice> CWLDataDeviceProtocol::dataDeviceForClient(wl_client* c) { return g_pXWayland->m_wm->getDataDevice(); #endif - auto it = std::find_if(m_devices.begin(), m_devices.end(), [c](const auto& e) { return e->client() == c; }); + auto it = std::ranges::find_if(m_devices, [c](const auto& e) { return e->client() == c; }); if (it == m_devices.end()) return nullptr; return *it; diff --git a/src/protocols/core/Seat.cpp b/src/protocols/core/Seat.cpp index bc224043..c341f95a 100644 --- a/src/protocols/core/Seat.cpp +++ b/src/protocols/core/Seat.cpp @@ -204,10 +204,10 @@ void CWLPointerResource::sendButton(uint32_t timeMs, uint32_t button, wl_pointer if (!(PROTO::seat->m_currentCaps & eHIDCapabilityType::HID_INPUT_CAPABILITY_POINTER)) return; - if (state == WL_POINTER_BUTTON_STATE_RELEASED && std::find(m_pressedButtons.begin(), m_pressedButtons.end(), button) == m_pressedButtons.end()) { + if (state == WL_POINTER_BUTTON_STATE_RELEASED && std::ranges::find(m_pressedButtons, button) == m_pressedButtons.end()) { LOGM(ERR, "sendButton release on a non-pressed button"); return; - } else if (state == WL_POINTER_BUTTON_STATE_PRESSED && std::find(m_pressedButtons.begin(), m_pressedButtons.end(), button) != m_pressedButtons.end()) { + } else if (state == WL_POINTER_BUTTON_STATE_PRESSED && std::ranges::find(m_pressedButtons, button) != m_pressedButtons.end()) { LOGM(ERR, "sendButton press on a non-pressed button"); return; } diff --git a/src/protocols/core/Shm.cpp b/src/protocols/core/Shm.cpp index 228884b9..8d610fe0 100644 --- a/src/protocols/core/Shm.cpp +++ b/src/protocols/core/Shm.cpp @@ -137,7 +137,7 @@ CWLSHMPoolResource::CWLSHMPoolResource(SP<CWlShmPool> resource_, CFileDescriptor return; } - if UNLIKELY (std::find(PROTO::shm->m_shmFormats.begin(), PROTO::shm->m_shmFormats.end(), fmt) == PROTO::shm->m_shmFormats.end()) { + if UNLIKELY (std::ranges::find(PROTO::shm->m_shmFormats, fmt) == PROTO::shm->m_shmFormats.end()) { r->error(WL_SHM_ERROR_INVALID_FORMAT, "Format invalid"); return; } diff --git a/src/protocols/core/Subcompositor.cpp b/src/protocols/core/Subcompositor.cpp index 4111b5dc..85a0edc4 100644 --- a/src/protocols/core/Subcompositor.cpp +++ b/src/protocols/core/Subcompositor.cpp @@ -30,7 +30,7 @@ CWLSubsurfaceResource::CWLSubsurfaceResource(SP<CWlSubsurface> resource_, SP<CWL std::erase_if(m_parent->m_subsurfaces, [this](const auto& e) { return e == m_self || !e; }); - auto it = std::find(m_parent->m_subsurfaces.begin(), m_parent->m_subsurfaces.end(), SURF); + auto it = std::ranges::find(m_parent->m_subsurfaces, SURF); if (it == m_parent->m_subsurfaces.end()) { LOGM(ERR, "Invalid surface reference in placeAbove, likely parent"); @@ -43,7 +43,7 @@ CWLSubsurfaceResource::CWLSubsurfaceResource(SP<CWlSubsurface> resource_, SP<CWL m_parent->m_subsurfaces.emplace_back(m_self); } - std::sort(m_parent->m_subsurfaces.begin(), m_parent->m_subsurfaces.end(), [](const auto& a, const auto& b) { return a->m_zIndex < b->m_zIndex; }); + std::ranges::sort(m_parent->m_subsurfaces, [](const auto& a, const auto& b) { return a->m_zIndex < b->m_zIndex; }); }); m_resource->setPlaceBelow([this](CWlSubsurface* r, wl_resource* surf) { @@ -61,7 +61,7 @@ CWLSubsurfaceResource::CWLSubsurfaceResource(SP<CWlSubsurface> resource_, SP<CWL std::erase_if(m_parent->m_subsurfaces, [this](const auto& e) { return e == m_self || !e; }); - auto it = std::find(m_parent->m_subsurfaces.begin(), m_parent->m_subsurfaces.end(), SURF); + auto it = std::ranges::find(m_parent->m_subsurfaces, SURF); if (it == m_parent->m_subsurfaces.end()) { LOGM(ERR, "Invalid surface reference in placeBelow, likely parent"); @@ -74,7 +74,7 @@ CWLSubsurfaceResource::CWLSubsurfaceResource(SP<CWlSubsurface> resource_, SP<CWL m_parent->m_subsurfaces.emplace_back(m_self); } - std::sort(m_parent->m_subsurfaces.begin(), m_parent->m_subsurfaces.end(), [](const auto& a, const auto& b) { return a->m_zIndex < b->m_zIndex; }); + std::ranges::sort(m_parent->m_subsurfaces, [](const auto& a, const auto& b) { return a->m_zIndex < b->m_zIndex; }); }); m_listeners.commitSurface = m_surface->m_events.commit.registerListener([this](std::any d) { @@ -116,8 +116,7 @@ Vector2D CWLSubsurfaceResource::posRelativeToParent() { // surfaces we've visited and if we hit a surface we've visited we bail out. std::vector<SP<CWLSurfaceResource>> surfacesVisited; - while (surf->m_role->role() == SURFACE_ROLE_SUBSURFACE && - std::find_if(surfacesVisited.begin(), surfacesVisited.end(), [surf](const auto& other) { return surf == other; }) == surfacesVisited.end()) { + while (surf->m_role->role() == SURFACE_ROLE_SUBSURFACE && std::ranges::find_if(surfacesVisited, [surf](const auto& other) { return surf == other; }) == surfacesVisited.end()) { surfacesVisited.emplace_back(surf); auto subsurface = ((CSubsurfaceRole*)m_parent->m_role.get())->m_subsurface.lock(); pos += subsurface->m_position; @@ -134,8 +133,7 @@ SP<CWLSurfaceResource> CWLSubsurfaceResource::t1Parent() { SP<CWLSurfaceResource> surf = m_parent.lock(); std::vector<SP<CWLSurfaceResource>> surfacesVisited; - while (surf->m_role->role() == SURFACE_ROLE_SUBSURFACE && - std::find_if(surfacesVisited.begin(), surfacesVisited.end(), [surf](const auto& other) { return surf == other; }) == surfacesVisited.end()) { + while (surf->m_role->role() == SURFACE_ROLE_SUBSURFACE && std::ranges::find_if(surfacesVisited, [surf](const auto& other) { return surf == other; }) == surfacesVisited.end()) { surfacesVisited.emplace_back(surf); auto subsurface = ((CSubsurfaceRole*)m_parent->m_role.get())->m_subsurface.lock(); surf = subsurface->m_parent.lock(); |
