summaryrefslogtreecommitdiff
path: root/src/managers
diff options
context:
space:
mode:
authorPhilip Damianik <39028343+pdamianik@users.noreply.github.com>2023-10-15 20:07:23 +0200
committerGitHub <noreply@github.com>2023-10-15 19:07:23 +0100
commit442209942fdedbdded6362cafed736c327da0e1c (patch)
tree8e8b257bc9656f5364be9f56509b8bbdd88b1cdd /src/managers
parent43b39e0bc6a83ce190ff09054beb713e0431f19b (diff)
cleanup: Replace find() with C++20 starts_with(), ends_with() and contains() (#3572)
* Replace find() with C++20 starts_with() and ends_with() * Replace find() with C++20 contains()
Diffstat (limited to 'src/managers')
-rw-r--r--src/managers/AnimationManager.cpp14
-rw-r--r--src/managers/KeybindManager.cpp12
-rw-r--r--src/managers/input/InputManager.cpp4
-rw-r--r--src/managers/input/Swipe.cpp4
4 files changed, 17 insertions, 17 deletions
diff --git a/src/managers/AnimationManager.cpp b/src/managers/AnimationManager.cpp
index db3ebe52..a7d05030 100644
--- a/src/managers/AnimationManager.cpp
+++ b/src/managers/AnimationManager.cpp
@@ -256,8 +256,8 @@ void CAnimationManager::tick() {
const auto EXTENTS = PDECO->getWindowDecorationExtents();
wlr_box dmg = {PWINDOW->m_vRealPosition.vec().x - EXTENTS.topLeft.x, PWINDOW->m_vRealPosition.vec().y - EXTENTS.topLeft.y,
- PWINDOW->m_vRealSize.vec().x + EXTENTS.topLeft.x + EXTENTS.bottomRight.x,
- PWINDOW->m_vRealSize.vec().y + EXTENTS.topLeft.y + EXTENTS.bottomRight.y};
+ PWINDOW->m_vRealSize.vec().x + EXTENTS.topLeft.x + EXTENTS.bottomRight.x,
+ PWINDOW->m_vRealSize.vec().y + EXTENTS.topLeft.y + EXTENTS.bottomRight.y};
if (!*PSHADOWIGNOREWINDOW) {
// easy, damage the entire box
@@ -429,7 +429,7 @@ void CAnimationManager::onWindowPostCreateClose(CWindow* pWindow, bool close) {
if (pWindow->m_sAdditionalConfigData.animationStyle != "") {
// the window has config'd special anim
- if (pWindow->m_sAdditionalConfigData.animationStyle.find("slide") == 0) {
+ if (pWindow->m_sAdditionalConfigData.animationStyle.starts_with("slide")) {
if (pWindow->m_sAdditionalConfigData.animationStyle.contains(' ')) {
// has a direction
animationSlide(pWindow, pWindow->m_sAdditionalConfigData.animationStyle.substr(pWindow->m_sAdditionalConfigData.animationStyle.find(' ') + 1), close);
@@ -458,7 +458,7 @@ void CAnimationManager::onWindowPostCreateClose(CWindow* pWindow, bool close) {
// anim popin, fallback
float minPerc = 0.f;
- if (ANIMSTYLE.find("%") != 0) {
+ if (!ANIMSTYLE.starts_with("%")) {
try {
auto percstr = ANIMSTYLE.substr(ANIMSTYLE.find_last_of(' '));
minPerc = std::stoi(percstr.substr(0, percstr.length() - 1));
@@ -473,10 +473,10 @@ void CAnimationManager::onWindowPostCreateClose(CWindow* pWindow, bool close) {
}
std::string CAnimationManager::styleValidInConfigVar(const std::string& config, const std::string& style) {
- if (config.find("window") == 0) {
+ if (config.starts_with("window")) {
if (style == "slide") {
return "";
- } else if (style.find("popin") == 0) {
+ } else if (style.starts_with("popin")) {
// try parsing
float minPerc = 0.f;
if (style.find("%") != std::string::npos) {
@@ -497,7 +497,7 @@ std::string CAnimationManager::styleValidInConfigVar(const std::string& config,
} else if (config == "workspaces" || config == "specialWorkspace") {
if (style == "slide" || style == "slidevert" || style == "fade")
return "";
- else if (style.find("slidefade") == 0) {
+ else if (style.starts_with("slidefade")) {
// try parsing
float movePerc = 0.f;
if (style.find("%") != std::string::npos) {
diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp
index fd298d34..cd99c61f 100644
--- a/src/managers/KeybindManager.cpp
+++ b/src/managers/KeybindManager.cpp
@@ -808,9 +808,9 @@ void CKeybindManager::changeworkspace(std::string args) {
const auto PMONITOR = g_pCompositor->m_pLastMonitor;
const auto PCURRENTWORKSPACE = g_pCompositor->getWorkspaceByID(PMONITOR->activeWorkspace);
- const bool EXPLICITPREVIOUS = args.find("previous") == 0;
+ const bool EXPLICITPREVIOUS = args.starts_with("previous");
- if (args.find("previous") == 0) {
+ if (args.starts_with("previous")) {
// Do nothing if there's no previous workspace, otherwise switch to it.
if (PCURRENTWORKSPACE->m_sPrevWorkspace.iID == -1) {
Debug::log(LOG, "No previous workspace to change to");
@@ -1094,7 +1094,7 @@ void CKeybindManager::swapActive(std::string args) {
void CKeybindManager::moveActiveTo(std::string args) {
char arg = args[0];
- if (args.find("mon:") == 0) {
+ if (args.starts_with("mon:")) {
const auto PNEWMONITOR = g_pCompositor->getMonitorFromString(args.substr(4));
if (!PNEWMONITOR)
return;
@@ -1221,7 +1221,7 @@ void CKeybindManager::alterSplitRatio(std::string args) {
}
if (splitratio == 0) {
- if (args.find("exact") == 0) {
+ if (args.starts_with("exact")) {
exact = true;
splitratio = getPlusMinusKeywordResult(args.substr(5), 0);
} else {
@@ -1721,10 +1721,10 @@ void CKeybindManager::toggleOpaque(std::string unused) {
}
void CKeybindManager::dpms(std::string arg) {
- bool enable = arg.find("on") == 0;
+ bool enable = arg.starts_with("on");
std::string port = "";
- if (arg.find("toggle") == 0)
+ if (arg.starts_with("toggle"))
enable = !std::any_of(g_pCompositor->m_vMonitors.begin(), g_pCompositor->m_vMonitors.end(), [&](const auto& other) { return !other->dpmsStatus; }); // enable if any is off
if (arg.find_first_of(' ') != std::string::npos)
diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp
index f79278e3..fb93b7bc 100644
--- a/src/managers/input/InputManager.cpp
+++ b/src/managers/input/InputManager.cpp
@@ -1001,7 +1001,7 @@ void CInputManager::setPointerConfigs() {
libinput_device_config_accel_set_profile(LIBINPUTDEV, LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE);
} else if (ACCELPROFILE == "flat") {
libinput_device_config_accel_set_profile(LIBINPUTDEV, LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT);
- } else if (ACCELPROFILE.find("custom") == 0) {
+ } else if (ACCELPROFILE.starts_with("custom")) {
CVarList args = {ACCELPROFILE, 0, ' '};
try {
double step = std::stod(args[1]);
@@ -1582,7 +1582,7 @@ void CInputManager::setCursorIconOnBorder(CWindow* w) {
wlr_box box = {w->m_vRealPosition.vec().x, w->m_vRealPosition.vec().y, w->m_vRealSize.vec().x, w->m_vRealSize.vec().y};
eBorderIconDirection direction = BORDERICON_NONE;
wlr_box boxFullGrabInput = {box.x - *PEXTENDBORDERGRAB - BORDERSIZE, box.y - *PEXTENDBORDERGRAB - BORDERSIZE, box.width + 2 * (*PEXTENDBORDERGRAB + BORDERSIZE),
- box.height + 2 * (*PEXTENDBORDERGRAB + BORDERSIZE)};
+ box.height + 2 * (*PEXTENDBORDERGRAB + BORDERSIZE)};
if (!wlr_box_contains_point(&boxFullGrabInput, mouseCoords.x, mouseCoords.y) || (!m_lCurrentlyHeldButtons.empty() && !currentlyDraggedWindow)) {
direction = BORDERICON_NONE;
diff --git a/src/managers/input/Swipe.cpp b/src/managers/input/Swipe.cpp
index ebed67cd..360397eb 100644
--- a/src/managers/input/Swipe.cpp
+++ b/src/managers/input/Swipe.cpp
@@ -51,7 +51,7 @@ void CInputManager::onSwipeEnd(wlr_pointer_swipe_end_event* e) {
static auto* const PSWIPENUMBER = &g_pConfigManager->getConfigValuePtr("gestures:workspace_swipe_numbered")->intValue;
static auto* const PSWIPEUSER = &g_pConfigManager->getConfigValuePtr("gestures:workspace_swipe_use_r")->intValue;
const bool VERTANIMS = m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.getConfig()->pValues->internalStyle == "slidevert" ||
- m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.getConfig()->pValues->internalStyle.find("slidefadevert") == 0;
+ m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.getConfig()->pValues->internalStyle.starts_with("slidefadevert");
// commit
std::string wsname = "";
@@ -200,7 +200,7 @@ void CInputManager::onSwipeUpdate(wlr_pointer_swipe_update_event* e) {
static auto* const PSWIPEUSER = &g_pConfigManager->getConfigValuePtr("gestures:workspace_swipe_use_r")->intValue;
const bool VERTANIMS = m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.getConfig()->pValues->internalStyle == "slidevert" ||
- m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.getConfig()->pValues->internalStyle.find("slidefadevert") == 0;
+ m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.getConfig()->pValues->internalStyle.starts_with("slidefadevert");
m_sActiveSwipe.delta += VERTANIMS ? (*PSWIPEINVR ? -e->dy : e->dy) : (*PSWIPEINVR ? -e->dx : e->dx);