Also handle signal in custom-execs
parent
eb1775d5f8
commit
59181f22cd
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
|
|
||||||
#include <csignal>
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <csignal>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
@ -36,6 +37,9 @@ class WorkerThread {
|
||||||
if (config["restart-interval"].isUInt()) {
|
if (config["restart-interval"].isUInt()) {
|
||||||
restart_interval_ = std::chrono::seconds(config["restart-interval"].asUInt());
|
restart_interval_ = std::chrono::seconds(config["restart-interval"].asUInt());
|
||||||
}
|
}
|
||||||
|
if (config["signal"].isInt()) {
|
||||||
|
signal_ = SIGRTMIN + config["signal"].asInt();
|
||||||
|
}
|
||||||
|
|
||||||
if (interval_.count() > 0) {
|
if (interval_.count() > 0) {
|
||||||
thread_ = [this] { delay_worker(); };
|
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:
|
private:
|
||||||
void delay_worker() {
|
void delay_worker() {
|
||||||
|
@ -123,6 +133,7 @@ class WorkerThread {
|
||||||
std::string exec_if_;
|
std::string exec_if_;
|
||||||
std::chrono::seconds interval_;
|
std::chrono::seconds interval_;
|
||||||
std::optional<std::chrono::seconds> restart_interval_;
|
std::optional<std::chrono::seconds> restart_interval_;
|
||||||
|
std::optional<int> signal_;
|
||||||
std::function<void(std::string)> output_callback_;
|
std::function<void(std::string)> output_callback_;
|
||||||
std::function<void(int)> exit_callback_;
|
std::function<void(int)> exit_callback_;
|
||||||
int pid_;
|
int pid_;
|
||||||
|
|
|
@ -632,6 +632,9 @@ void waybar::Bar::handleSignal(int signal) {
|
||||||
custom->refresh(signal);
|
custom->refresh(signal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for (auto& thread : custom_threads_) {
|
||||||
|
thread->refresh(signal);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void waybar::Bar::getModules(const Factory& factory, const std::string& pos) {
|
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();
|
dp.emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void waybar::modules::Custom::refresh(int sig) {
|
void waybar::modules::Custom::refresh(int sig) { thread_.refresh(sig); }
|
||||||
if (sig == SIGRTMIN + config_["signal"].asInt()) {
|
|
||||||
thread_.wake_up();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void waybar::modules::Custom::handleEvent() {
|
void waybar::modules::Custom::handleEvent() {
|
||||||
if (!config_["exec-on-event"].isBool() || config_["exec-on-event"].asBool()) {
|
if (!config_["exec-on-event"].isBool() || config_["exec-on-event"].asBool()) {
|
||||||
|
|
Loading…
Reference in New Issue