Pass WAYBAR_OUTPUT_NAME environment variable to custom exec scripts

Signed-off-by: Jo De Boeck <deboeck.jo@gmail.com>
This commit is contained in:
Jo De Boeck
2023-12-19 22:54:12 +02:00
parent f5370fcff5
commit 0ea5143493
5 changed files with 17 additions and 12 deletions

View File

@ -5,9 +5,10 @@
#include "util/scope_guard.hpp"
waybar::modules::Custom::Custom(const std::string& name, const std::string& id,
const Json::Value& config)
const Json::Value& config, const std::string& output_name)
: ALabel(config, "custom-" + name, id, "{}"),
name_(name),
output_name_(output_name),
id_(id),
percentage_(0),
fp_(nullptr),
@ -42,7 +43,7 @@ void waybar::modules::Custom::delayWorker() {
}
if (can_update) {
if (config_["exec"].isString()) {
output_ = util::command::exec(config_["exec"].asString());
output_ = util::command::exec(config_["exec"].asString(), output_name_);
}
dp.emit();
}
@ -53,7 +54,7 @@ void waybar::modules::Custom::delayWorker() {
void waybar::modules::Custom::continuousWorker() {
auto cmd = config_["exec"].asString();
pid_ = -1;
fp_ = util::command::open(cmd, pid_);
fp_ = util::command::open(cmd, pid_, output_name_);
if (!fp_) {
throw std::runtime_error("Unable to open " + cmd);
}
@ -79,7 +80,7 @@ void waybar::modules::Custom::continuousWorker() {
if (config_["restart-interval"].isUInt()) {
pid_ = -1;
thread_.sleep_for(std::chrono::seconds(config_["restart-interval"].asUInt()));
fp_ = util::command::open(cmd, pid_);
fp_ = util::command::open(cmd, pid_, output_name_);
if (!fp_) {
throw std::runtime_error("Unable to open " + cmd);
}
@ -112,7 +113,7 @@ void waybar::modules::Custom::waitingWorker() {
}
if (can_update) {
if (config_["exec"].isString()) {
output_ = util::command::exec(config_["exec"].asString());
output_ = util::command::exec(config_["exec"].asString(), output_name_);
}
dp.emit();
}

View File

@ -45,7 +45,7 @@ auto waybar::modules::Image::update() -> void {
if (config_["path"].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();
} else {
path_ = "";