refactor: use std::ranges whenever possible (#10584)
This commit is contained in:
parent
9bf1b49144
commit
9190443d95
50 changed files with 137 additions and 146 deletions
|
|
@ -384,7 +384,7 @@ void CHyprAnimationManager::onWindowPostCreateClose(PHLWINDOW pWindow, bool clos
|
|||
}
|
||||
|
||||
std::string ANIMSTYLE = pWindow->m_realPosition->getStyle();
|
||||
transform(ANIMSTYLE.begin(), ANIMSTYLE.end(), ANIMSTYLE.begin(), ::tolower);
|
||||
std::ranges::transform(ANIMSTYLE, ANIMSTYLE.begin(), ::tolower);
|
||||
|
||||
CVarList animList(ANIMSTYLE, 0, 's');
|
||||
|
||||
|
|
|
|||
|
|
@ -186,7 +186,7 @@ void CCursorManager::setCursorFromName(const std::string& name) {
|
|||
if (m_currentCursorShapeData.images.size() < 1) {
|
||||
// try with '_' first (old hc, etc)
|
||||
std::string newName = name;
|
||||
std::replace(newName.begin(), newName.end(), '-', '_');
|
||||
std::ranges::replace(newName, '-', '_');
|
||||
|
||||
m_currentCursorShapeData = m_hyprcursor->getShape(newName.c_str(), m_currentStyleInfo);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@ int CEventManager::onClientEvent(int fd, uint32_t mask) {
|
|||
}
|
||||
|
||||
std::vector<CEventManager::SClient>::iterator CEventManager::findClientByFD(int fd) {
|
||||
return std::find_if(m_clients.begin(), m_clients.end(), [fd](const auto& client) { return client.fd.get() == fd; });
|
||||
return std::ranges::find_if(m_clients, [fd](const auto& client) { return client.fd.get() == fd; });
|
||||
}
|
||||
|
||||
std::vector<CEventManager::SClient>::iterator CEventManager::removeClientByFD(int fd) {
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ void CHookSystemManager::emit(std::vector<SCallbackFNPtr>* const callbacks, SCal
|
|||
|
||||
m_currentEventPlugin = true;
|
||||
|
||||
if (std::find(faultyHandles.begin(), faultyHandles.end(), cb.handle) != faultyHandles.end())
|
||||
if (std::ranges::find(faultyHandles, cb.handle) != faultyHandles.end())
|
||||
continue;
|
||||
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -225,7 +225,7 @@ void CKeybindManager::removeKeybind(uint32_t mod, const SParsedKey& key) {
|
|||
|
||||
uint32_t CKeybindManager::stringToModMask(std::string mods) {
|
||||
uint32_t modMask = 0;
|
||||
std::transform(mods.begin(), mods.end(), mods.begin(), ::toupper);
|
||||
std::ranges::transform(mods, mods.begin(), ::toupper);
|
||||
if (mods.contains("SHIFT"))
|
||||
modMask |= HL_MODIFIER_SHIFT;
|
||||
if (mods.contains("CAPS"))
|
||||
|
|
@ -624,10 +624,8 @@ eMultiKeyCase CKeybindManager::mkKeysymSetMatches(const std::set<xkb_keysym_t> k
|
|||
std::set<xkb_keysym_t> boundKeysNotPressed;
|
||||
std::set<xkb_keysym_t> pressedKeysNotBound;
|
||||
|
||||
std::set_difference(keybindKeysyms.begin(), keybindKeysyms.end(), pressedKeysyms.begin(), pressedKeysyms.end(),
|
||||
std::inserter(boundKeysNotPressed, boundKeysNotPressed.begin()));
|
||||
std::set_difference(pressedKeysyms.begin(), pressedKeysyms.end(), keybindKeysyms.begin(), keybindKeysyms.end(),
|
||||
std::inserter(pressedKeysNotBound, pressedKeysNotBound.begin()));
|
||||
std::ranges::set_difference(keybindKeysyms, pressedKeysyms, std::inserter(boundKeysNotPressed, boundKeysNotPressed.begin()));
|
||||
std::ranges::set_difference(pressedKeysyms, keybindKeysyms, std::inserter(pressedKeysNotBound, pressedKeysNotBound.begin()));
|
||||
|
||||
if (boundKeysNotPressed.empty() && pressedKeysNotBound.empty())
|
||||
return MK_FULL_MATCH;
|
||||
|
|
@ -670,8 +668,7 @@ SDispatchResult CKeybindManager::handleKeybinds(const uint32_t modmask, const SP
|
|||
|
||||
for (auto& k : m_keybinds) {
|
||||
const bool SPECIALDISPATCHER = k->handler == "global" || k->handler == "pass" || k->handler == "sendshortcut" || k->handler == "mouse";
|
||||
const bool SPECIALTRIGGERED =
|
||||
std::find_if(m_pressedSpecialBinds.begin(), m_pressedSpecialBinds.end(), [&](const auto& other) { return other == k; }) != m_pressedSpecialBinds.end();
|
||||
const bool SPECIALTRIGGERED = std::ranges::find_if(m_pressedSpecialBinds, [&](const auto& other) { return other == k; }) != m_pressedSpecialBinds.end();
|
||||
const bool IGNORECONDITIONS =
|
||||
SPECIALDISPATCHER && !pressed && SPECIALTRIGGERED; // ignore mods. Pass, global dispatchers should be released immediately once the key is released.
|
||||
|
||||
|
|
@ -1106,7 +1103,7 @@ SDispatchResult CKeybindManager::signalWindow(std::string args) {
|
|||
return {.success = false, .error = "signalWindow: no window"};
|
||||
}
|
||||
|
||||
if (!std::all_of(SIGNAL.begin(), SIGNAL.end(), ::isdigit))
|
||||
if (!std::ranges::all_of(SIGNAL, ::isdigit))
|
||||
return {.success = false, .error = "signalWindow: signal has to be int"};
|
||||
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ void CLayoutManager::switchToLayout(std::string layout) {
|
|||
}
|
||||
|
||||
bool CLayoutManager::addLayout(const std::string& name, IHyprLayout* layout) {
|
||||
if (std::find_if(m_layouts.begin(), m_layouts.end(), [&](const auto& other) { return other.first == name || other.second == layout; }) != m_layouts.end())
|
||||
if (std::ranges::find_if(m_layouts, [&](const auto& other) { return other.first == name || other.second == layout; }) != m_layouts.end())
|
||||
return false;
|
||||
|
||||
m_layouts.emplace_back(std::make_pair<>(name, layout));
|
||||
|
|
@ -37,7 +37,7 @@ bool CLayoutManager::addLayout(const std::string& name, IHyprLayout* layout) {
|
|||
}
|
||||
|
||||
bool CLayoutManager::removeLayout(IHyprLayout* layout) {
|
||||
const auto IT = std::find_if(m_layouts.begin(), m_layouts.end(), [&](const auto& other) { return other.second == layout; });
|
||||
const auto IT = std::ranges::find_if(m_layouts, [&](const auto& other) { return other.second == layout; });
|
||||
|
||||
if (IT == m_layouts.end() || IT->first == "dwindle" || IT->first == "master")
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ bool CPointerManager::hasCursor() {
|
|||
}
|
||||
|
||||
SP<CPointerManager::SMonitorPointerState> CPointerManager::stateFor(PHLMONITOR mon) {
|
||||
auto it = std::find_if(m_monitorStates.begin(), m_monitorStates.end(), [mon](const auto& other) { return other->monitor == mon; });
|
||||
auto it = std::ranges::find_if(m_monitorStates, [mon](const auto& other) { return other->monitor == mon; });
|
||||
if (it == m_monitorStates.end())
|
||||
return m_monitorStates.emplace_back(makeShared<CPointerManager::SMonitorPointerState>(mon));
|
||||
return *it;
|
||||
|
|
|
|||
|
|
@ -653,7 +653,7 @@ void CSeatManager::resendEnterEvents() {
|
|||
}
|
||||
|
||||
bool CSeatGrab::accepts(SP<CWLSurfaceResource> surf) {
|
||||
return std::find(m_surfs.begin(), m_surfs.end(), surf) != m_surfs.end();
|
||||
return std::ranges::find(m_surfs, surf) != m_surfs.end();
|
||||
}
|
||||
|
||||
void CSeatGrab::add(SP<CWLSurfaceResource> surf) {
|
||||
|
|
|
|||
|
|
@ -127,8 +127,8 @@ void CXCursorManager::loadTheme(std::string const& name, int size, float scale)
|
|||
for (auto const& p : paths) {
|
||||
try {
|
||||
auto dirCursors = loadAllFromDir(p, m_lastLoadSize);
|
||||
std::copy_if(dirCursors.begin(), dirCursors.end(), std::back_inserter(m_cursors),
|
||||
[this](auto const& p) { return std::none_of(m_cursors.begin(), m_cursors.end(), [&p](auto const& dp) { return dp->shape == p->shape; }); });
|
||||
std::ranges::copy_if(dirCursors, std::back_inserter(m_cursors),
|
||||
[this](auto const& p) { return std::ranges::none_of(m_cursors, [&p](auto const& dp) { return dp->shape == p->shape; }); });
|
||||
} catch (std::exception& e) { Debug::log(ERR, "XCursor path {} can't be loaded: threw error {}", p, e.what()); }
|
||||
}
|
||||
}
|
||||
|
|
@ -144,14 +144,14 @@ void CXCursorManager::loadTheme(std::string const& name, int size, float scale)
|
|||
if (legacyName.empty())
|
||||
continue;
|
||||
|
||||
auto it = std::find_if(m_cursors.begin(), m_cursors.end(), [&legacyName](auto const& c) { return c->shape == legacyName; });
|
||||
auto it = std::ranges::find_if(m_cursors, [&legacyName](auto const& c) { return c->shape == legacyName; });
|
||||
|
||||
if (it == m_cursors.end()) {
|
||||
Debug::log(LOG, "XCursor failed to find a legacy shape with name {}, skipping", legacyName);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (std::any_of(m_cursors.begin(), m_cursors.end(), [&shape](auto const& dp) { return dp->shape == shape; })) {
|
||||
if (std::ranges::any_of(m_cursors, [&shape](auto const& dp) { return dp->shape == shape; })) {
|
||||
Debug::log(LOG, "XCursor already has a shape {} loaded, skipping", shape);
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -619,7 +619,7 @@ void CInputManager::onMouseButton(IPointer::SButtonEvent e) {
|
|||
if (e.state == WL_POINTER_BUTTON_STATE_PRESSED) {
|
||||
m_currentlyHeldButtons.push_back(e.button);
|
||||
} else {
|
||||
if (std::find_if(m_currentlyHeldButtons.begin(), m_currentlyHeldButtons.end(), [&](const auto& other) { return other == e.button; }) == m_currentlyHeldButtons.end())
|
||||
if (std::ranges::find_if(m_currentlyHeldButtons, [&](const auto& other) { return other == e.button; }) == m_currentlyHeldButtons.end())
|
||||
return;
|
||||
std::erase_if(m_currentlyHeldButtons, [&](const auto& other) { return other == e.button; });
|
||||
}
|
||||
|
|
@ -1552,7 +1552,7 @@ void CInputManager::unconstrainMouse() {
|
|||
}
|
||||
|
||||
bool CInputManager::isConstrained() {
|
||||
return std::any_of(m_constraints.begin(), m_constraints.end(), [](auto const& c) {
|
||||
return std::ranges::any_of(m_constraints, [](auto const& c) {
|
||||
const auto constraint = c.lock();
|
||||
return constraint && constraint->isActive() && constraint->owner()->resource() == g_pCompositor->m_lastFocus;
|
||||
});
|
||||
|
|
@ -1773,9 +1773,9 @@ void CInputManager::unsetCursorImage() {
|
|||
}
|
||||
|
||||
std::string CInputManager::deviceNameToInternalString(std::string in) {
|
||||
std::replace(in.begin(), in.end(), ' ', '-');
|
||||
std::replace(in.begin(), in.end(), '\n', '-');
|
||||
std::transform(in.begin(), in.end(), in.begin(), ::tolower);
|
||||
std::ranges::replace(in, ' ', '-');
|
||||
std::ranges::replace(in, '\n', '-');
|
||||
std::ranges::transform(in, in.begin(), ::tolower);
|
||||
return in;
|
||||
}
|
||||
|
||||
|
|
@ -1786,7 +1786,7 @@ std::string CInputManager::getNameForNewDevice(std::string internalName) {
|
|||
|
||||
auto makeNewName = [&]() { return (proposedNewName.empty() ? "unknown-device" : proposedNewName) + (dupeno == 0 ? "" : ("-" + std::to_string(dupeno))); };
|
||||
|
||||
while (std::find_if(m_hids.begin(), m_hids.end(), [&](const auto& other) { return other->m_hlName == makeNewName(); }) != m_hids.end())
|
||||
while (std::ranges::find_if(m_hids, [&](const auto& other) { return other->m_hlName == makeNewName(); }) != m_hids.end())
|
||||
dupeno++;
|
||||
|
||||
return makeNewName();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue