This commit is contained in:
aidansunbury
2025-08-16 15:34:43 -07:00
parent 6dc5a73a02
commit 2b552f7fb6
8 changed files with 19 additions and 12 deletions

View File

@ -31,7 +31,7 @@ class Image : public AModule {
std::string path_; std::string path_;
std::string tooltip_; std::string tooltip_;
int size_; int size_;
int interval_; std::chrono::milliseconds interval_;
util::command::res output_; util::command::res output_;
util::SleeperThread thread_; util::SleeperThread thread_;

View File

@ -11,7 +11,7 @@ The *cpu* module displays the current CPU utilization.
# CONFIGURATION # CONFIGURATION
*interval*: ++ *interval*: ++
typeof: integer ++ typeof: integer or float ++
default: 10 ++ default: 10 ++
The interval in which the information gets polled. The interval in which the information gets polled.

View File

@ -24,7 +24,7 @@ The *image* module displays an image from a path.
The width/height to render the image. The width/height to render the image.
*interval*: ++ *interval*: ++
typeof: integer ++ typeof: integer or float ++
The interval (in seconds) to re-render the image. ++ The interval (in seconds) to re-render the image. ++
This is useful if the contents of *path* changes. ++ This is useful if the contents of *path* changes. ++
If no *interval* is defined, the image will only be rendered once. If no *interval* is defined, the image will only be rendered once.

View File

@ -45,7 +45,7 @@ Addressed by *jack*
The format of information displayed in the tooltip. The format of information displayed in the tooltip.
*interval*: ++ *interval*: ++
typeof: integer ++ typeof: integer or float ++
default: 1 ++ default: 1 ++
The interval in which the information gets polled. The interval in which the information gets polled.

View File

@ -40,7 +40,7 @@ Addressed by *temperature*
The threshold before it is considered critical (Celsius). The threshold before it is considered critical (Celsius).
*interval*: ++ *interval*: ++
typeof: integer ++ typeof: integer or float ++
default: 10 ++ default: 10 ++
The interval in which the information gets polled. The interval in which the information gets polled.

View File

@ -21,7 +21,8 @@ ALabel::ALabel(const Json::Value& config, const std::string& name, const std::st
? std::chrono::milliseconds::max() ? std::chrono::milliseconds::max()
: std::chrono::milliseconds( : std::chrono::milliseconds(
static_cast<long>( static_cast<long>(
(config_["interval"].isNumeric() ? config_["interval"].asDouble() : interval) * 1000))), std::max(0.001, // Minimum 1ms to prevent performance issues
config_["interval"].isNumeric() ? config_["interval"].asDouble() : interval) * 1000))),
default_format_(format_) { default_format_(format_) {
label_.set_name(name); label_.set_name(name);
if (!id.empty()) { if (!id.empty()) {

View File

@ -92,7 +92,9 @@ void waybar::modules::Custom::continuousWorker() {
if (config_["restart-interval"].isNumeric()) { if (config_["restart-interval"].isNumeric()) {
pid_ = -1; pid_ = -1;
thread_.sleep_for(std::chrono::milliseconds( thread_.sleep_for(std::chrono::milliseconds(
static_cast<long>(config_["restart-interval"].asDouble() * 1000))); static_cast<long>(
std::max(0.001, // Minimum 1ms to prevent performance issues
config_["restart-interval"].asDouble()) * 1000)));
fp_ = util::command::open(cmd, pid_, output_name_); fp_ = util::command::open(cmd, pid_, output_name_);
if (!fp_) { if (!fp_) {
throw std::runtime_error("Unable to open " + cmd); throw std::runtime_error("Unable to open " + cmd);

View File

@ -14,14 +14,19 @@ waybar::modules::Image::Image(const std::string& id, const Json::Value& config)
size_ = config["size"].asInt(); size_ = config["size"].asInt();
interval_ = config_["interval"].asInt(); interval_ = config_["interval"] == "once"
? std::chrono::milliseconds::max()
: std::chrono::milliseconds(
static_cast<long>(
std::max(0.001, // Minimum 1ms to prevent performance issues
config_["interval"].isNumeric() ? config_["interval"].asDouble() : 0) * 1000));
if (size_ == 0) { if (size_ == 0) {
size_ = 16; size_ = 16;
} }
if (interval_ == 0) { if (interval_.count() == 0) {
interval_ = INT_MAX; interval_ = std::chrono::milliseconds::max();
} }
delayWorker(); delayWorker();
@ -30,8 +35,7 @@ waybar::modules::Image::Image(const std::string& id, const Json::Value& config)
void waybar::modules::Image::delayWorker() { void waybar::modules::Image::delayWorker() {
thread_ = [this] { thread_ = [this] {
dp.emit(); dp.emit();
auto interval = std::chrono::seconds(interval_); thread_.sleep_for(interval_);
thread_.sleep_for(interval);
}; };
} }