Merge pull request #4838 from khaneliman/image

fix(image): treat missing interval as once
This commit is contained in:
Alexis Rouillard
2026-02-10 14:55:45 +01:00
committed by GitHub
5 changed files with 22 additions and 22 deletions

View File

@ -172,8 +172,6 @@ inline int32_t forkExec(const std::string& cmd, const std::string& output_name)
return pid;
}
inline int32_t forkExec(const std::string& cmd) {
return forkExec(cmd, "");
}
inline int32_t forkExec(const std::string& cmd) { return forkExec(cmd, ""); }
} // namespace waybar::util::command

View File

@ -26,7 +26,8 @@ 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. ++
If set to a positive value, the minimum is 0.001 (1ms). Values smaller than 1ms will be set to 1ms. ++
Zero or negative values are treated as "once". ++
This is useful if the contents of *path* changes. ++
If no *interval* is defined, the image will only be rendered once.

View File

@ -237,9 +237,7 @@ void Window::queryActiveWorkspace() {
}
}
void Window::onEvent(const std::string& ev) {
dp.emit();
}
void Window::onEvent(const std::string& ev) { dp.emit(); }
void Window::setClass(const std::string& classname, bool enable) {
if (enable) {

View File

@ -38,7 +38,7 @@ WindowCount::~WindowCount() {
auto WindowCount::update() -> void {
std::lock_guard<std::mutex> lg(mutex_);
queryActiveWorkspace();
std::string format = config_["format"].asString();
@ -125,9 +125,7 @@ void WindowCount::queryActiveWorkspace() {
}
}
void WindowCount::onEvent(const std::string& ev) {
dp.emit();
}
void WindowCount::onEvent(const std::string& ev) { dp.emit(); }
void WindowCount::setClass(const std::string& classname, bool enable) {
if (enable) {

View File

@ -14,22 +14,27 @@ waybar::modules::Image::Image(const std::string& id, const Json::Value& config)
size_ = config["size"].asInt();
interval_ = config_["interval"] == "once"
? std::chrono::milliseconds::max()
: std::chrono::milliseconds(std::max(
1L, // Minimum 1ms due to millisecond precision
static_cast<long>(
(config_["interval"].isNumeric() ? config_["interval"].asDouble() : 0) *
1000)));
const auto once = std::chrono::milliseconds::max();
if (!config_.isMember("interval") || config_["interval"].isNull() ||
config_["interval"] == "once") {
interval_ = once;
} else if (config_["interval"].isNumeric()) {
const auto interval_seconds = config_["interval"].asDouble();
if (interval_seconds <= 0) {
interval_ = once;
} else {
interval_ =
std::chrono::milliseconds(std::max(1L, // Minimum 1ms due to millisecond precision
static_cast<long>(interval_seconds * 1000)));
}
} else {
interval_ = once;
}
if (size_ == 0) {
size_ = 16;
}
if (interval_.count() == 0) {
interval_ = std::chrono::milliseconds::max();
}
delayWorker();
}