From f824ae9334f3991ecc82d5ffbcf6582b75a92747 Mon Sep 17 00:00:00 2001 From: Arkoniak Date: Tue, 29 Jul 2025 10:45:31 +0300 Subject: [PATCH 1/2] Relative paths in included configs --- include/config.hpp | 1 + src/bar.cpp | 6 +++++- src/config.cpp | 22 ++++++++++++++++++---- src/modules/custom.cpp | 3 +++ 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/include/config.hpp b/include/config.hpp index 5256bb46..3dd699ae 100644 --- a/include/config.hpp +++ b/include/config.hpp @@ -35,6 +35,7 @@ class Config { void setupConfig(Json::Value &dst, const std::string &config_file, int depth); void resolveConfigIncludes(Json::Value &config, int depth); void mergeConfig(Json::Value &a_config_, Json::Value &b_config_); + std::optional findIncludePath(const std::string name); std::string config_file_; diff --git a/src/bar.cpp b/src/bar.cpp index 3c3ab690..0d4f632f 100644 --- a/src/bar.cpp +++ b/src/bar.cpp @@ -496,7 +496,11 @@ void waybar::Bar::getModules(const Factory& factory, const std::string& pos, auto vertical = (group != nullptr ? group->getBox().get_orientation() : box_.get_orientation()) == Gtk::ORIENTATION_VERTICAL; - auto* group_module = new waybar::Group(id_name, class_name, config[ref], vertical); + auto group_config = config[ref]; + if (group_config["modules"].isNull()) { + spdlog::warn("Group definition '{}' has not been found, group will be hidden", ref); + } + auto* group_module = new waybar::Group(id_name, class_name, group_config, vertical); getModules(factory, ref, group_module); module = group_module; } else { diff --git a/src/config.cpp b/src/config.cpp index 7096ba89..29a55e7c 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -89,19 +89,33 @@ void Config::setupConfig(Json::Value &dst, const std::string &config_file, int d mergeConfig(dst, tmp_config); } +std::optional Config::findIncludePath(const std::string name) { + auto match1 = tryExpandPath(name, ""); + if (!match1.empty()) { + return match1.front(); + } + return findConfigPath({name}); +} + void Config::resolveConfigIncludes(Json::Value &config, int depth) { Json::Value includes = config["include"]; if (includes.isArray()) { for (const auto &include : includes) { spdlog::info("Including resource file: {}", include.asString()); - for (const auto &match : tryExpandPath(include.asString(), "")) { - setupConfig(config, match, depth + 1); + auto match = findIncludePath(include.asString()); + if (match.has_value()) { + setupConfig(config, match.value(), depth + 1); + } else { + spdlog::warn("Unable to find resource file: {}", include.asString()); } } } else if (includes.isString()) { spdlog::info("Including resource file: {}", includes.asString()); - for (const auto &match : tryExpandPath(includes.asString(), "")) { - setupConfig(config, match, depth + 1); + auto match = findIncludePath(includes.asString()); + if (match.has_value()) { + setupConfig(config, match.value(), depth + 1); + } else { + spdlog::warn("Unable to find resource file: {}", includes.asString()); } } } diff --git a/src/modules/custom.cpp b/src/modules/custom.cpp index db5c6db3..f9fd621e 100644 --- a/src/modules/custom.cpp +++ b/src/modules/custom.cpp @@ -14,6 +14,9 @@ waybar::modules::Custom::Custom(const std::string& name, const std::string& id, percentage_(0), fp_(nullptr), pid_(-1) { + if (config.isNull()) { + spdlog::warn("There is no configuration for 'custom/{}', element will be hidden", name); + } dp.emit(); if (!config_["signal"].empty() && config_["interval"].empty() && config_["restart-interval"].empty()) { From 1e0037a873e5809ad91fea7f1881f415bca1ca56 Mon Sep 17 00:00:00 2001 From: Arkoniak Date: Thu, 31 Jul 2025 21:29:20 +0300 Subject: [PATCH 2/2] fixed extra copy --- include/config.hpp | 2 +- src/config.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/config.hpp b/include/config.hpp index 3dd699ae..3490c3f1 100644 --- a/include/config.hpp +++ b/include/config.hpp @@ -35,7 +35,7 @@ class Config { void setupConfig(Json::Value &dst, const std::string &config_file, int depth); void resolveConfigIncludes(Json::Value &config, int depth); void mergeConfig(Json::Value &a_config_, Json::Value &b_config_); - std::optional findIncludePath(const std::string name); + static std::optional findIncludePath(const std::string &name); std::string config_file_; diff --git a/src/config.cpp b/src/config.cpp index 29a55e7c..5f14df5e 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -89,7 +89,7 @@ void Config::setupConfig(Json::Value &dst, const std::string &config_file, int d mergeConfig(dst, tmp_config); } -std::optional Config::findIncludePath(const std::string name) { +std::optional Config::findIncludePath(const std::string &name) { auto match1 = tryExpandPath(name, ""); if (!match1.empty()) { return match1.front();