From 59181f22cdca13aa4bc5a44e26b2da7cb14cb86b Mon Sep 17 00:00:00 2001 From: Risto Toijala Date: Sun, 3 Oct 2021 15:27:52 +0300 Subject: [PATCH] Also handle signal in custom-execs --- include/modules/custom.hpp | 1 - include/util/worker_thread.hpp | 13 ++++++++++++- src/bar.cpp | 3 +++ src/modules/custom.cpp | 6 +----- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/include/modules/custom.hpp b/include/modules/custom.hpp index 03c53c2f..8104d896 100644 --- a/include/modules/custom.hpp +++ b/include/modules/custom.hpp @@ -2,7 +2,6 @@ #include -#include #include #include #include diff --git a/include/util/worker_thread.hpp b/include/util/worker_thread.hpp index 7d005346..502f5970 100644 --- a/include/util/worker_thread.hpp +++ b/include/util/worker_thread.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include @@ -36,6 +37,9 @@ class WorkerThread { if (config["restart-interval"].isUInt()) { restart_interval_ = std::chrono::seconds(config["restart-interval"].asUInt()); } + if (config["signal"].isInt()) { + signal_ = SIGRTMIN + config["signal"].asInt(); + } if (interval_.count() > 0) { thread_ = [this] { delay_worker(); }; @@ -51,7 +55,13 @@ class WorkerThread { } } - auto wake_up() { return thread_.wake_up(); } + void refresh(int signal) { + if (signal_.has_value() && *signal_ == signal) { + wake_up(); + } + } + + void wake_up() { thread_.wake_up(); } private: void delay_worker() { @@ -123,6 +133,7 @@ class WorkerThread { std::string exec_if_; std::chrono::seconds interval_; std::optional restart_interval_; + std::optional signal_; std::function output_callback_; std::function exit_callback_; int pid_; diff --git a/src/bar.cpp b/src/bar.cpp index 9cf85b41..ec59eb29 100644 --- a/src/bar.cpp +++ b/src/bar.cpp @@ -632,6 +632,9 @@ void waybar::Bar::handleSignal(int signal) { custom->refresh(signal); } } + for (auto& thread : custom_threads_) { + thread->refresh(signal); + } } void waybar::Bar::getModules(const Factory& factory, const std::string& pos) { diff --git a/src/modules/custom.cpp b/src/modules/custom.cpp index 58695477..a84489c0 100644 --- a/src/modules/custom.cpp +++ b/src/modules/custom.cpp @@ -36,11 +36,7 @@ void waybar::modules::Custom::injectOutput(Json::Value output) { dp.emit(); } -void waybar::modules::Custom::refresh(int sig) { - if (sig == SIGRTMIN + config_["signal"].asInt()) { - thread_.wake_up(); - } -} +void waybar::modules::Custom::refresh(int sig) { thread_.refresh(sig); } void waybar::modules::Custom::handleEvent() { if (!config_["exec-on-event"].isBool() || config_["exec-on-event"].asBool()) {