diff --git a/include/modules/custom.hpp b/include/modules/custom.hpp index 6c17c6e4..a00faaa5 100644 --- a/include/modules/custom.hpp +++ b/include/modules/custom.hpp @@ -42,6 +42,7 @@ class Custom : public ALabel { int pid_; util::command::res output_; util::JsonParser parser_; + int signal_; // Cached signal value to avoid JSON access in signal handler util::SleeperThread thread_; }; diff --git a/include/modules/image.hpp b/include/modules/image.hpp index 510dad94..e31de0fc 100644 --- a/include/modules/image.hpp +++ b/include/modules/image.hpp @@ -33,6 +33,7 @@ class Image : public AModule { int size_; std::chrono::milliseconds interval_; util::command::res output_; + int signal_; // Cached signal value to avoid JSON access in signal handler util::SleeperThread thread_; }; diff --git a/src/modules/custom.cpp b/src/modules/custom.cpp index d75633e9..a3ea7b27 100644 --- a/src/modules/custom.cpp +++ b/src/modules/custom.cpp @@ -13,7 +13,8 @@ waybar::modules::Custom::Custom(const std::string& name, const std::string& id, tooltip_format_enabled_{config_["tooltip-format"].isString()}, percentage_(0), fp_(nullptr), - pid_(-1) { + pid_(-1), + signal_(config_["signal"].isInt() ? config_["signal"].asInt() : -1) { if (config.isNull()) { spdlog::warn("There is no configuration for 'custom/{}', element will be hidden", name); } @@ -136,7 +137,7 @@ void waybar::modules::Custom::waitingWorker() { } void waybar::modules::Custom::refresh(int sig) { - if (sig == SIGRTMIN + config_["signal"].asInt()) { + if (signal_ != -1 && sig == SIGRTMIN + signal_) { thread_.wake_up(); } } diff --git a/src/modules/image.cpp b/src/modules/image.cpp index 173aabd3..4e830608 100644 --- a/src/modules/image.cpp +++ b/src/modules/image.cpp @@ -1,7 +1,9 @@ #include "modules/image.hpp" 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), + signal_(config_["signal"].isInt() ? config_["signal"].asInt() : -1) { box_.pack_start(image_); box_.set_name("image"); if (!id.empty()) { @@ -41,7 +43,7 @@ void waybar::modules::Image::delayWorker() { } void waybar::modules::Image::refresh(int sig) { - if (sig == SIGRTMIN + config_["signal"].asInt()) { + if (signal_ != -1 && sig == SIGRTMIN + signal_) { thread_.wake_up(); } }