Skip to content

Commit 81720f4

Browse files
committed
config: add wallpaper#paths
1 parent 0ca403a commit 81720f4

1 file changed

Lines changed: 41 additions & 7 deletions

File tree

src/config/ConfigManager.cpp

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ bool CConfigManager::init() {
6262
m_config.addSpecialCategory("wallpaper", Hyprlang::SSpecialCategoryOptions{.key = "monitor"});
6363
m_config.addSpecialConfigValue("wallpaper", "monitor", Hyprlang::STRING{""});
6464
m_config.addSpecialConfigValue("wallpaper", "path", Hyprlang::STRING{""});
65+
m_config.addSpecialConfigValue("wallpaper", "paths", Hyprlang::STRING{""});
6566
m_config.addSpecialConfigValue("wallpaper", "fit_mode", Hyprlang::STRING{"cover"});
6667
m_config.addSpecialConfigValue("wallpaper", "timeout", Hyprlang::INT{0});
6768
m_config.addSpecialConfigValue("wallpaper", "order", Hyprlang::STRING{"default"});
@@ -166,20 +167,47 @@ static std::expected<std::vector<std::string>, std::string> getFullPath(const st
166167
return result;
167168
}
168169

170+
static std::expected<std::vector<std::string>, std::string> getFullPaths(const std::string& sv, const bool recursive) {
171+
std::vector<std::string> result;
172+
size_t pos = 0;
173+
174+
while (pos < sv.size()) {
175+
const auto next = sv.find(',', pos);
176+
const auto path = Hyprutils::String::trim(std::string_view{sv}.substr(pos, next == std::string::npos ? sv.size() - pos : next - pos));
177+
178+
if (path.empty())
179+
return std::unexpected("empty path in paths");
180+
181+
const auto RESOLVED_PATH = getFullPath(std::string{path}, recursive);
182+
if (!RESOLVED_PATH)
183+
return std::unexpected(RESOLVED_PATH.error());
184+
185+
result.append_range(RESOLVED_PATH.value());
186+
187+
if (next == std::string::npos)
188+
break;
189+
190+
pos = next + 1;
191+
}
192+
193+
return result;
194+
}
195+
169196
std::vector<CConfigManager::SSetting> CConfigManager::getSettings() {
170197
std::vector<CConfigManager::SSetting> result;
171198

172199
auto keys = m_config.listKeysForSpecialCategory("wallpaper");
173200
result.reserve(keys.size());
174201

175202
for (auto& key : keys) {
176-
std::string monitor, fitMode, path, order;
203+
std::string monitor, fitMode, path, paths, order;
177204
int timeout, recursive;
178205

179206
try {
180207
monitor = std::any_cast<Hyprlang::STRING>(m_config.getSpecialConfigValue("wallpaper", "monitor", key.c_str()));
181208
fitMode = std::any_cast<Hyprlang::STRING>(m_config.getSpecialConfigValue("wallpaper", "fit_mode", key.c_str()));
182209
path = std::any_cast<Hyprlang::STRING>(m_config.getSpecialConfigValue("wallpaper", "path", key.c_str()));
210+
paths = std::any_cast<Hyprlang::STRING>(m_config.getSpecialConfigValue("wallpaper", "paths", key.c_str()));
183211
timeout = std::any_cast<Hyprlang::INT>(m_config.getSpecialConfigValue("wallpaper", "timeout", key.c_str()));
184212
order = std::any_cast<Hyprlang::STRING>(m_config.getSpecialConfigValue("wallpaper", "order", key.c_str()));
185213
recursive = std::any_cast<Hyprlang::INT>(m_config.getSpecialConfigValue("wallpaper", "recursive", key.c_str()));
@@ -188,19 +216,25 @@ std::vector<CConfigManager::SSetting> CConfigManager::getSettings() {
188216
continue;
189217
}
190218

191-
const auto RESOLVE_PATH = getFullPath(path, recursive != 0);
219+
if (!path.empty() && !paths.empty()) {
220+
g_logger->log(LOG_ERR, "Wallpaper {} has both path and paths set", key);
221+
continue;
222+
}
223+
224+
const auto& PATHS_TO_RESOLVE = !paths.empty() ? paths : path;
225+
const auto RESOLVE_PATHS = !paths.empty() ? getFullPaths(paths, recursive != 0) : getFullPath(path, recursive != 0);
192226

193-
if (!RESOLVE_PATH) {
194-
g_logger->log(LOG_ERR, "Failed to resolve path {}: {}", path, RESOLVE_PATH.error());
227+
if (!RESOLVE_PATHS) {
228+
g_logger->log(LOG_ERR, "Failed to resolve path {}: {}", PATHS_TO_RESOLVE, RESOLVE_PATHS.error());
195229
continue;
196230
}
197231

198-
if (RESOLVE_PATH.value().empty()) {
199-
g_logger->log(LOG_ERR, "Provided path(s) '{}' does not contain a valid image", path);
232+
if (RESOLVE_PATHS.value().empty()) {
233+
g_logger->log(LOG_ERR, "Provided path(s) '{}' does not contain a valid image", PATHS_TO_RESOLVE);
200234
continue;
201235
}
202236

203-
auto resolvedPaths = RESOLVE_PATH.value();
237+
auto resolvedPaths = RESOLVE_PATHS.value();
204238

205239
if (resolvedPaths.size() > 1) {
206240
if (order != "default" && order != "random" && order != "random-shuffle") {

0 commit comments

Comments
 (0)