Also handle signal in custom-execs
parent
eb1775d5f8
commit
59181f22cd
|
@ -2,7 +2,6 @@
|
|||
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include <csignal>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <variant>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
#include <csignal>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
|
@ -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<std::chrono::seconds> restart_interval_;
|
||||
std::optional<int> signal_;
|
||||
std::function<void(std::string)> output_callback_;
|
||||
std::function<void(int)> exit_callback_;
|
||||
int pid_;
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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()) {
|
||||
|
|
Loading…
Reference in New Issue