From 6dc5a73a02af12fccf8eac8494da7d91db23400b Mon Sep 17 00:00:00 2001 From: aidansunbury Date: Sat, 16 Aug 2025 15:29:59 -0700 Subject: [PATCH 1/3] initial changes --- include/ALabel.hpp | 2 +- man/waybar-custom.5.scd | 4 ++-- src/ALabel.cpp | 7 ++++--- src/modules/custom.cpp | 5 +++-- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/include/ALabel.hpp b/include/ALabel.hpp index a1aae9da..92fc2e0f 100644 --- a/include/ALabel.hpp +++ b/include/ALabel.hpp @@ -21,7 +21,7 @@ class ALabel : public AModule { protected: Gtk::Label label_; std::string format_; - const std::chrono::seconds interval_; + const std::chrono::milliseconds interval_; bool alt_ = false; std::string default_format_; diff --git a/man/waybar-custom.5.scd b/man/waybar-custom.5.scd index 309fc184..5707010c 100644 --- a/man/waybar-custom.5.scd +++ b/man/waybar-custom.5.scd @@ -35,14 +35,14 @@ Addressed by *custom/* See *return-type* *interval*: ++ - typeof: integer ++ + typeof: integer or float ++ The interval (in seconds) in which the information gets polled. ++ Use *once* if you want to execute the module only on startup. ++ You can update it manually with a signal. If no *interval* or *signal* is defined, it is assumed that the out script loops itself. ++ If a *signal* is defined then the script will run once on startup and will only update with a signal. *restart-interval*: ++ - typeof: integer ++ + typeof: integer or float ++ The restart interval (in seconds). ++ Can't be used with the *interval* option, so only with continuous scripts. ++ Once the script exits, it'll be re-executed after the *restart-interval*. diff --git a/src/ALabel.cpp b/src/ALabel.cpp index 6df80e46..2262ad1f 100644 --- a/src/ALabel.cpp +++ b/src/ALabel.cpp @@ -18,9 +18,10 @@ ALabel::ALabel(const Json::Value& config, const std::string& name, const std::st enable_scroll), format_(config_["format"].isString() ? config_["format"].asString() : format), interval_(config_["interval"] == "once" - ? std::chrono::seconds::max() - : std::chrono::seconds( - config_["interval"].isUInt() ? config_["interval"].asUInt() : interval)), + ? std::chrono::milliseconds::max() + : std::chrono::milliseconds( + static_cast( + (config_["interval"].isNumeric() ? config_["interval"].asDouble() : interval) * 1000))), default_format_(format_) { label_.set_name(name); if (!id.empty()) { diff --git a/src/modules/custom.cpp b/src/modules/custom.cpp index f9fd621e..0a7b7dd4 100644 --- a/src/modules/custom.cpp +++ b/src/modules/custom.cpp @@ -89,9 +89,10 @@ void waybar::modules::Custom::continuousWorker() { dp.emit(); spdlog::error("{} stopped unexpectedly, is it endless?", name_); } - if (config_["restart-interval"].isUInt()) { + if (config_["restart-interval"].isNumeric()) { pid_ = -1; - thread_.sleep_for(std::chrono::seconds(config_["restart-interval"].asUInt())); + thread_.sleep_for(std::chrono::milliseconds( + static_cast(config_["restart-interval"].asDouble() * 1000))); fp_ = util::command::open(cmd, pid_, output_name_); if (!fp_) { throw std::runtime_error("Unable to open " + cmd); From 2b552f7fb679f1677121b263ac485fef5e040ceb Mon Sep 17 00:00:00 2001 From: aidansunbury Date: Sat, 16 Aug 2025 15:34:43 -0700 Subject: [PATCH 2/3] compat --- include/modules/image.hpp | 2 +- man/waybar-cpu.5.scd | 2 +- man/waybar-image.5.scd | 2 +- man/waybar-jack.5.scd | 2 +- man/waybar-temperature.5.scd | 2 +- src/ALabel.cpp | 3 ++- src/modules/custom.cpp | 4 +++- src/modules/image.cpp | 14 +++++++++----- 8 files changed, 19 insertions(+), 12 deletions(-) diff --git a/include/modules/image.hpp b/include/modules/image.hpp index 7c0d014f..510dad94 100644 --- a/include/modules/image.hpp +++ b/include/modules/image.hpp @@ -31,7 +31,7 @@ class Image : public AModule { std::string path_; std::string tooltip_; int size_; - int interval_; + std::chrono::milliseconds interval_; util::command::res output_; util::SleeperThread thread_; diff --git a/man/waybar-cpu.5.scd b/man/waybar-cpu.5.scd index 287bf123..b9c1ca6a 100644 --- a/man/waybar-cpu.5.scd +++ b/man/waybar-cpu.5.scd @@ -11,7 +11,7 @@ The *cpu* module displays the current CPU utilization. # CONFIGURATION *interval*: ++ - typeof: integer ++ + typeof: integer or float ++ default: 10 ++ The interval in which the information gets polled. diff --git a/man/waybar-image.5.scd b/man/waybar-image.5.scd index a2dcc938..0fe0deff 100644 --- a/man/waybar-image.5.scd +++ b/man/waybar-image.5.scd @@ -24,7 +24,7 @@ The *image* module displays an image from a path. The width/height to render the image. *interval*: ++ - typeof: integer ++ + typeof: integer or float ++ The interval (in seconds) to re-render the image. ++ This is useful if the contents of *path* changes. ++ If no *interval* is defined, the image will only be rendered once. diff --git a/man/waybar-jack.5.scd b/man/waybar-jack.5.scd index 85ce7180..98adc8db 100644 --- a/man/waybar-jack.5.scd +++ b/man/waybar-jack.5.scd @@ -45,7 +45,7 @@ Addressed by *jack* The format of information displayed in the tooltip. *interval*: ++ - typeof: integer ++ + typeof: integer or float ++ default: 1 ++ The interval in which the information gets polled. diff --git a/man/waybar-temperature.5.scd b/man/waybar-temperature.5.scd index 923d643d..554ead19 100644 --- a/man/waybar-temperature.5.scd +++ b/man/waybar-temperature.5.scd @@ -40,7 +40,7 @@ Addressed by *temperature* The threshold before it is considered critical (Celsius). *interval*: ++ - typeof: integer ++ + typeof: integer or float ++ default: 10 ++ The interval in which the information gets polled. diff --git a/src/ALabel.cpp b/src/ALabel.cpp index 2262ad1f..ddd737b1 100644 --- a/src/ALabel.cpp +++ b/src/ALabel.cpp @@ -21,7 +21,8 @@ ALabel::ALabel(const Json::Value& config, const std::string& name, const std::st ? std::chrono::milliseconds::max() : std::chrono::milliseconds( static_cast( - (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_) { label_.set_name(name); if (!id.empty()) { diff --git a/src/modules/custom.cpp b/src/modules/custom.cpp index 0a7b7dd4..426b97fd 100644 --- a/src/modules/custom.cpp +++ b/src/modules/custom.cpp @@ -92,7 +92,9 @@ void waybar::modules::Custom::continuousWorker() { if (config_["restart-interval"].isNumeric()) { pid_ = -1; thread_.sleep_for(std::chrono::milliseconds( - static_cast(config_["restart-interval"].asDouble() * 1000))); + static_cast( + std::max(0.001, // Minimum 1ms to prevent performance issues + config_["restart-interval"].asDouble()) * 1000))); fp_ = util::command::open(cmd, pid_, output_name_); if (!fp_) { throw std::runtime_error("Unable to open " + cmd); diff --git a/src/modules/image.cpp b/src/modules/image.cpp index 71e93b94..0c5590e0 100644 --- a/src/modules/image.cpp +++ b/src/modules/image.cpp @@ -14,14 +14,19 @@ waybar::modules::Image::Image(const std::string& id, const Json::Value& config) size_ = config["size"].asInt(); - interval_ = config_["interval"].asInt(); + interval_ = config_["interval"] == "once" + ? std::chrono::milliseconds::max() + : std::chrono::milliseconds( + static_cast( + std::max(0.001, // Minimum 1ms to prevent performance issues + config_["interval"].isNumeric() ? config_["interval"].asDouble() : 0) * 1000)); if (size_ == 0) { size_ = 16; } - if (interval_ == 0) { - interval_ = INT_MAX; + if (interval_.count() == 0) { + interval_ = std::chrono::milliseconds::max(); } delayWorker(); @@ -30,8 +35,7 @@ waybar::modules::Image::Image(const std::string& id, const Json::Value& config) void waybar::modules::Image::delayWorker() { thread_ = [this] { dp.emit(); - auto interval = std::chrono::seconds(interval_); - thread_.sleep_for(interval); + thread_.sleep_for(interval_); }; } From 2b81782fa9122802e1ffe4bf1a723f427c6341e5 Mon Sep 17 00:00:00 2001 From: aidansunbury Date: Sat, 16 Aug 2025 16:01:41 -0700 Subject: [PATCH 3/3] more changes --- man/waybar-cpu.5.scd | 3 ++- man/waybar-custom.5.scd | 2 ++ man/waybar-image.5.scd | 1 + src/ALabel.cpp | 6 +++--- src/modules/custom.cpp | 5 ++--- src/modules/image.cpp | 6 +++--- 6 files changed, 13 insertions(+), 10 deletions(-) diff --git a/man/waybar-cpu.5.scd b/man/waybar-cpu.5.scd index b9c1ca6a..40682372 100644 --- a/man/waybar-cpu.5.scd +++ b/man/waybar-cpu.5.scd @@ -13,7 +13,8 @@ The *cpu* module displays the current CPU utilization. *interval*: ++ typeof: integer or float ++ default: 10 ++ - The interval in which the information gets polled. + The interval in which the information gets polled. ++ + Minimum value is 0.001 (1ms). Values smaller than 1ms will be set to 1ms. *format*: ++ typeof: string ++ diff --git a/man/waybar-custom.5.scd b/man/waybar-custom.5.scd index 5707010c..37b4c42c 100644 --- a/man/waybar-custom.5.scd +++ b/man/waybar-custom.5.scd @@ -37,6 +37,7 @@ Addressed by *custom/* *interval*: ++ typeof: integer or float ++ The interval (in seconds) in which the information gets polled. ++ + Minimum value is 0.001 (1ms). Values smaller than 1ms will be set to 1ms. ++ Use *once* if you want to execute the module only on startup. ++ You can update it manually with a signal. If no *interval* or *signal* is defined, it is assumed that the out script loops itself. ++ If a *signal* is defined then the script will run once on startup and will only update with a signal. @@ -44,6 +45,7 @@ Addressed by *custom/* *restart-interval*: ++ typeof: integer or float ++ The restart interval (in seconds). ++ + Minimum value is 0.001 (1ms). Values smaller than 1ms will be set to 1ms. ++ Can't be used with the *interval* option, so only with continuous scripts. ++ Once the script exits, it'll be re-executed after the *restart-interval*. diff --git a/man/waybar-image.5.scd b/man/waybar-image.5.scd index 0fe0deff..8c991265 100644 --- a/man/waybar-image.5.scd +++ b/man/waybar-image.5.scd @@ -26,6 +26,7 @@ The *image* module displays an image from a path. *interval*: ++ typeof: integer or float ++ The interval (in seconds) to re-render the image. ++ + Minimum value is 0.001 (1ms). Values smaller than 1ms will be set to 1ms. ++ This is useful if the contents of *path* changes. ++ If no *interval* is defined, the image will only be rendered once. diff --git a/src/ALabel.cpp b/src/ALabel.cpp index ddd737b1..7f9143b3 100644 --- a/src/ALabel.cpp +++ b/src/ALabel.cpp @@ -20,9 +20,9 @@ ALabel::ALabel(const Json::Value& config, const std::string& name, const std::st interval_(config_["interval"] == "once" ? std::chrono::milliseconds::max() : std::chrono::milliseconds( - static_cast( - std::max(0.001, // Minimum 1ms to prevent performance issues - config_["interval"].isNumeric() ? config_["interval"].asDouble() : interval) * 1000))), + std::max(1L, // Minimum 1ms due to millisecond precision + static_cast( + (config_["interval"].isNumeric() ? config_["interval"].asDouble() : interval) * 1000)))), default_format_(format_) { label_.set_name(name); if (!id.empty()) { diff --git a/src/modules/custom.cpp b/src/modules/custom.cpp index 426b97fd..2fbc9a16 100644 --- a/src/modules/custom.cpp +++ b/src/modules/custom.cpp @@ -92,9 +92,8 @@ void waybar::modules::Custom::continuousWorker() { if (config_["restart-interval"].isNumeric()) { pid_ = -1; thread_.sleep_for(std::chrono::milliseconds( - static_cast( - std::max(0.001, // Minimum 1ms to prevent performance issues - config_["restart-interval"].asDouble()) * 1000))); + std::max(1L, // Minimum 1ms due to millisecond precision + static_cast(config_["restart-interval"].asDouble() * 1000)))); fp_ = util::command::open(cmd, pid_, output_name_); if (!fp_) { throw std::runtime_error("Unable to open " + cmd); diff --git a/src/modules/image.cpp b/src/modules/image.cpp index 0c5590e0..9529ee35 100644 --- a/src/modules/image.cpp +++ b/src/modules/image.cpp @@ -17,9 +17,9 @@ waybar::modules::Image::Image(const std::string& id, const Json::Value& config) interval_ = config_["interval"] == "once" ? std::chrono::milliseconds::max() : std::chrono::milliseconds( - static_cast( - std::max(0.001, // Minimum 1ms to prevent performance issues - config_["interval"].isNumeric() ? config_["interval"].asDouble() : 0) * 1000)); + std::max(1L, // Minimum 1ms due to millisecond precision + static_cast( + (config_["interval"].isNumeric() ? config_["interval"].asDouble() : 0) * 1000))); if (size_ == 0) { size_ = 16;