From 885212dedc1710424a7bba19001147de89dbdf84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Seyfullah=20G=C3=BCndo=C4=9Fdu?= <58184332+SeyfullahGundogdu@users.noreply.github.com> Date: Tue, 3 Jan 2023 15:09:20 +0300 Subject: [PATCH] Trim support for wallpaper path. (#29) * Trim support for wallpaper path. --- src/config/ConfigManager.cpp | 10 +++++++++- src/config/ConfigManager.hpp | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index b6bfbb2..42e3fe6 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -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); +} \ No newline at end of file diff --git a/src/config/ConfigManager.hpp b/src/config/ConfigManager.hpp index 13b2d44..6bf06f4 100644 --- a/src/config/ConfigManager.hpp +++ b/src/config/ConfigManager.hpp @@ -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; };