77#include " ../helpers/Logger.hpp"
88#include " WallpaperMatcher.hpp"
99
10+ using namespace std ::string_literals;
11+
1012static std::string getMainConfigPath () {
1113 static const auto paths = Hyprutils::Path::findConfig (" hyprpaper" );
1214
@@ -42,6 +44,31 @@ Hyprlang::CConfig* CConfigManager::hyprlang() {
4244 return &m_config;
4345}
4446
47+ static std::expected<std::string, std::string> resolvePath (const std::string_view& sv) {
48+ std::error_code ec;
49+ const auto CAN = std::filesystem::canonical (sv, ec);
50+
51+ if (ec)
52+ return std::unexpected (std::format (" invalid path: {}" , ec.message ()));
53+
54+ return CAN ;
55+ }
56+
57+ static std::expected<std::string, std::string> getFullPath (const std::string_view& sv) {
58+ if (sv.empty ())
59+ return std::unexpected (" empty path" );
60+
61+ if (sv[0 ] == ' ~' ) {
62+ static auto HOME = getenv (" HOME" );
63+ if (!HOME || HOME [0 ] == ' \0 ' )
64+ return std::unexpected (" home path but no $HOME" );
65+
66+ return resolvePath (std::string{HOME } + " /" s + std::string{sv.substr (1 )});
67+ }
68+
69+ return resolvePath (sv);
70+ }
71+
4572std::vector<CConfigManager::SSetting> CConfigManager::getSettings () {
4673 std::vector<CConfigManager::SSetting> result;
4774
@@ -60,14 +87,14 @@ std::vector<CConfigManager::SSetting> CConfigManager::getSettings() {
6087 continue ;
6188 }
6289
63- std::error_code ec ;
64- auto canonical = std::filesystem::canonical (path, ec);
65- if (ec ) {
66- g_logger->log (LOG_ERR , " Failed parsing wallpaper for key {}: path {} is not valid " , key, path );
90+ const auto RESOLVE_PATH = getFullPath (path) ;
91+
92+ if (! RESOLVE_PATH ) {
93+ g_logger->log (LOG_ERR , " Failed to resolve path {}: {} " , path, RESOLVE_PATH . error () );
6794 continue ;
6895 }
6996
70- result.emplace_back (SSetting{.monitor = std::move (monitor), .fitMode = std::move (fitMode), .path = std::move (canonical ), .id = ++m_maxId});
97+ result.emplace_back (SSetting{.monitor = std::move (monitor), .fitMode = std::move (fitMode), .path = RESOLVE_PATH . value ( ), .id = ++m_maxId});
7198 }
7299
73100 return result;
0 commit comments