From 38af4a6f16bb24086a5e50f73dea3b589aad15b3 Mon Sep 17 00:00:00 2001 From: "Ruan E. Formigoni" Date: Thu, 10 Nov 2022 02:36:54 -0300 Subject: [PATCH 1/3] exec runs after on-* events --- include/AModule.hpp | 2 +- src/AModule.cpp | 10 +++++----- src/modules/custom.cpp | 3 +++ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/include/AModule.hpp b/include/AModule.hpp index 357f70ec..d3009af1 100644 --- a/include/AModule.hpp +++ b/include/AModule.hpp @@ -25,6 +25,7 @@ class AModule : public IModule { SCROLL_DIR getScrollDir(GdkEventScroll *e); bool tooltipEnabled(); + std::vector pid_children_; const std::string name_; const Json::Value &config_; Gtk::EventBox event_box_; @@ -33,7 +34,6 @@ class AModule : public IModule { virtual bool handleScroll(GdkEventScroll *); private: - std::vector pid_; gdouble distance_scrolled_y_; gdouble distance_scrolled_x_; static const inline std::map, std::string> eventMap_{ diff --git a/src/AModule.cpp b/src/AModule.cpp index b19594a1..79f25654 100644 --- a/src/AModule.cpp +++ b/src/AModule.cpp @@ -35,7 +35,7 @@ AModule::AModule(const Json::Value& config, const std::string& name, const std:: } AModule::~AModule() { - for (const auto& pid : pid_) { + for (const auto& pid : pid_children_) { if (pid != -1) { killpg(pid, SIGTERM); } @@ -45,7 +45,7 @@ AModule::~AModule() { auto AModule::update() -> void { // Run user-provided update handler if configured if (config_["on-update"].isString()) { - pid_.push_back(util::command::forkExec(config_["on-update"].asString())); + pid_children_.push_back(util::command::forkExec(config_["on-update"].asString())); } } @@ -62,7 +62,7 @@ bool AModule::handleToggle(GdkEventButton* const& e) { } if (!format.empty()) { - pid_.push_back(util::command::forkExec(format)); + pid_children_.push_back(util::command::forkExec(format)); } dp.emit(); return true; @@ -123,9 +123,9 @@ AModule::SCROLL_DIR AModule::getScrollDir(GdkEventScroll* e) { bool AModule::handleScroll(GdkEventScroll* e) { auto dir = getScrollDir(e); if (dir == SCROLL_DIR::UP && config_["on-scroll-up"].isString()) { - pid_.push_back(util::command::forkExec(config_["on-scroll-up"].asString())); + pid_children_.push_back(util::command::forkExec(config_["on-scroll-up"].asString())); } else if (dir == SCROLL_DIR::DOWN && config_["on-scroll-down"].isString()) { - pid_.push_back(util::command::forkExec(config_["on-scroll-down"].asString())); + pid_children_.push_back(util::command::forkExec(config_["on-scroll-down"].asString())); } dp.emit(); return true; diff --git a/src/modules/custom.cpp b/src/modules/custom.cpp index 397298b2..cf66e44b 100644 --- a/src/modules/custom.cpp +++ b/src/modules/custom.cpp @@ -27,6 +27,9 @@ waybar::modules::Custom::~Custom() { void waybar::modules::Custom::delayWorker() { thread_ = [this] { + std::for_each(this->pid_children_.cbegin(), this->pid_children_.cend(), + [](int i){ wait(&i); }); + bool can_update = true; if (config_["exec-if"].isString()) { output_ = util::command::execNoRead(config_["exec-if"].asString()); From 15132aeec304bf85a27f0d8cd55079671bcb1013 Mon Sep 17 00:00:00 2001 From: "Ruan E. Formigoni" Date: Tue, 15 Nov 2022 01:19:51 -0300 Subject: [PATCH 2/3] Fix for leftover pids --- src/modules/custom.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/modules/custom.cpp b/src/modules/custom.cpp index cf66e44b..458228c5 100644 --- a/src/modules/custom.cpp +++ b/src/modules/custom.cpp @@ -27,8 +27,13 @@ waybar::modules::Custom::~Custom() { void waybar::modules::Custom::delayWorker() { thread_ = [this] { - std::for_each(this->pid_children_.cbegin(), this->pid_children_.cend(), - [](int i){ wait(&i); }); + for( int i : this->pid_children_ ) + { + int status; + waitpid(i, &status, 0); + } + + this->pid_children_.clear(); bool can_update = true; if (config_["exec-if"].isString()) { From d6b6158ae97651cb556ad388b365069843877ed0 Mon Sep 17 00:00:00 2001 From: Alexis Rouillard Date: Sun, 22 Jun 2025 09:42:14 +0200 Subject: [PATCH 3/3] Update custom.cpp --- src/modules/custom.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/modules/custom.cpp b/src/modules/custom.cpp index 3179e2bc..0220e348 100644 --- a/src/modules/custom.cpp +++ b/src/modules/custom.cpp @@ -35,8 +35,7 @@ waybar::modules::Custom::~Custom() { void waybar::modules::Custom::delayWorker() { thread_ = [this] { - for( int i : this->pid_children_ ) - { + for (int i: this->pid_children_) { int status; waitpid(i, &status, 0); }