Trim support for wallpaper path. (#29)

* Trim support for wallpaper path.
This commit is contained in:
Seyfullah Gündoğdu 2023-01-03 15:09:20 +03:00 committed by GitHub
parent aefd63876d
commit 885212dedc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -118,7 +118,7 @@ void CConfigManager::handleWallpaper(const std::string& COMMAND, const std::stri
}
auto MONITOR = VALUE.substr(0, VALUE.find_first_of(','));
auto WALLPAPER = VALUE.substr(VALUE.find_first_of(',') + 1);
auto WALLPAPER = trimPath(VALUE.substr(VALUE.find_first_of(',') + 1));
bool contain = false;
@ -201,3 +201,11 @@ void CConfigManager::handleUnloadAll(const std::string& COMMAND, const std::stri
for (auto& tu : toUnload)
g_pHyprpaper->unloadWallpaper(tu);
}
// trim from both ends
std::string CConfigManager::trimPath(std::string path) {
//trims whitespaces, tabs and new line feeds
size_t pathStartIndex = path.find_first_not_of(" \t\r\n");
size_t pathEndIndex = path.find_last_not_of(" \t\r\n");
return path.substr(pathStartIndex, pathEndIndex - pathStartIndex + 1);
}

View File

@ -21,6 +21,7 @@ private:
void handlePreload(const std::string&, const std::string&);
void handleUnload(const std::string&, const std::string&);
void handleUnloadAll(const std::string&, const std::string&);
std::string trimPath(std::string path);
friend class CIPCSocket;
};