Merge pull request #4607 from zspher/feat-image-path

feat(image): expand `~` & `$HOME` in path
This commit is contained in:
Alexis Rouillard
2026-07-03 23:43:00 +02:00
committed by GitHub
+13 -5
View File
@@ -1,5 +1,7 @@
#include "modules/image.hpp" #include "modules/image.hpp"
#include <config.hpp>
waybar::modules::Image::Image(const std::string& id, const Json::Value& config) waybar::modules::Image::Image(const std::string& id, const Json::Value& config)
: AModule(config, "image", id), box_(Gtk::ORIENTATION_HORIZONTAL, 0) { : AModule(config, "image", id), box_(Gtk::ORIENTATION_HORIZONTAL, 0) {
box_.pack_start(image_); box_.pack_start(image_);
@@ -35,6 +37,13 @@ waybar::modules::Image::Image(const std::string& id, const Json::Value& config)
size_ = 16; size_ = 16;
} }
if (config_["path"].isString()) {
auto result = Config::tryExpandPath(config_["path"].asString(), "");
path_ = result.empty() ? "" : result.front();
} else {
path_.clear();
}
delayWorker(); delayWorker();
} }
@@ -54,13 +63,12 @@ void waybar::modules::Image::refresh(int sig) {
} }
auto waybar::modules::Image::update() -> void { auto waybar::modules::Image::update() -> void {
if (config_["path"].isString()) { if (config_["exec"].isString()) {
path_ = config_["path"].asString();
} else if (config_["exec"].isString()) {
output_ = util::command::exec(config_["exec"].asString(), ""); output_ = util::command::exec(config_["exec"].asString(), "");
parseOutputRaw(); parseOutputRaw();
} else { // expand path if "~" or "$HOME" is present in original path
path_ = ""; auto result = Config::tryExpandPath(path_, "");
path_ = result.empty() ? "" : result.front();
} }
if (Glib::file_test(path_, Glib::FILE_TEST_EXISTS)) { if (Glib::file_test(path_, Glib::FILE_TEST_EXISTS)) {