Simplify fix: only add isInt() check in refresh methods
Changed approach per maintainer feedback - instead of caching signal values, just add isInt() check before accessing config_["signal"].asInt() in refresh() methods. This is simpler and more minimal. Co-authored-by: Alexays <13947260+Alexays@users.noreply.github.com>
This commit is contained in:
@@ -42,7 +42,6 @@ class Custom : public ALabel {
|
|||||||
int pid_;
|
int pid_;
|
||||||
util::command::res output_;
|
util::command::res output_;
|
||||||
util::JsonParser parser_;
|
util::JsonParser parser_;
|
||||||
int signal_; // Cached signal value (-1 = disabled) to avoid JSON access in signal handler
|
|
||||||
|
|
||||||
util::SleeperThread thread_;
|
util::SleeperThread thread_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ class Image : public AModule {
|
|||||||
int size_;
|
int size_;
|
||||||
std::chrono::milliseconds interval_;
|
std::chrono::milliseconds interval_;
|
||||||
util::command::res output_;
|
util::command::res output_;
|
||||||
int signal_; // Cached signal value (-1 = disabled) to avoid JSON access in signal handler
|
|
||||||
|
|
||||||
util::SleeperThread thread_;
|
util::SleeperThread thread_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -13,8 +13,7 @@ waybar::modules::Custom::Custom(const std::string& name, const std::string& id,
|
|||||||
tooltip_format_enabled_{config_["tooltip-format"].isString()},
|
tooltip_format_enabled_{config_["tooltip-format"].isString()},
|
||||||
percentage_(0),
|
percentage_(0),
|
||||||
fp_(nullptr),
|
fp_(nullptr),
|
||||||
pid_(-1),
|
pid_(-1) {
|
||||||
signal_(config_["signal"].isInt() ? config_["signal"].asInt() : -1) {
|
|
||||||
if (config.isNull()) {
|
if (config.isNull()) {
|
||||||
spdlog::warn("There is no configuration for 'custom/{}', element will be hidden", name);
|
spdlog::warn("There is no configuration for 'custom/{}', element will be hidden", name);
|
||||||
}
|
}
|
||||||
@@ -137,7 +136,7 @@ void waybar::modules::Custom::waitingWorker() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void waybar::modules::Custom::refresh(int sig) {
|
void waybar::modules::Custom::refresh(int sig) {
|
||||||
if (signal_ != -1 && sig == SIGRTMIN + signal_) {
|
if (config_["signal"].isInt() && sig == SIGRTMIN + config_["signal"].asInt()) {
|
||||||
thread_.wake_up();
|
thread_.wake_up();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
#include "modules/image.hpp"
|
#include "modules/image.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),
|
: AModule(config, "image", id), box_(Gtk::ORIENTATION_HORIZONTAL, 0) {
|
||||||
box_(Gtk::ORIENTATION_HORIZONTAL, 0),
|
|
||||||
signal_(config_["signal"].isInt() ? config_["signal"].asInt() : -1) {
|
|
||||||
box_.pack_start(image_);
|
box_.pack_start(image_);
|
||||||
box_.set_name("image");
|
box_.set_name("image");
|
||||||
if (!id.empty()) {
|
if (!id.empty()) {
|
||||||
@@ -43,7 +41,7 @@ void waybar::modules::Image::delayWorker() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void waybar::modules::Image::refresh(int sig) {
|
void waybar::modules::Image::refresh(int sig) {
|
||||||
if (signal_ != -1 && sig == SIGRTMIN + signal_) {
|
if (config_["signal"].isInt() && sig == SIGRTMIN + config_["signal"].asInt()) {
|
||||||
thread_.wake_up();
|
thread_.wake_up();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user