mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
add signalhandler for module update
This commit is contained in:
@ -6,8 +6,9 @@
|
||||
waybar::ALabel::ALabel(const Json::Value& config, const std::string format, uint16_t interval)
|
||||
: config_(config),
|
||||
format_(config_["format"].isString() ? config_["format"].asString() : format),
|
||||
interval_(std::chrono::seconds(config_["interval"].isUInt()
|
||||
? config_["interval"].asUInt() : interval)), default_format_(format_)
|
||||
interval_(config_["interval"] == "once" ? std::chrono::seconds(100000000) :
|
||||
std::chrono::seconds(config_["interval"].isUInt() ?
|
||||
config_["interval"].asUInt() : interval)), default_format_(format_)
|
||||
{
|
||||
event_box_.add(label_);
|
||||
if (config_["max-length"].isUInt()) {
|
||||
|
16
src/bar.cpp
16
src/bar.cpp
@ -185,6 +185,22 @@ void waybar::Bar::handleDescription(void* /*data*/,
|
||||
// Nothing here
|
||||
}
|
||||
|
||||
void waybar::Bar::handleSignal(int signal)
|
||||
{
|
||||
for (auto& module : modules_left_) {
|
||||
auto* custom = dynamic_cast<waybar::modules::Custom*>(module.get());
|
||||
if(custom) custom->refresh(signal);
|
||||
}
|
||||
for (auto& module : modules_center_) {
|
||||
auto* custom = dynamic_cast<waybar::modules::Custom*>(module.get());
|
||||
if(custom) custom->refresh(signal);
|
||||
}
|
||||
for (auto& module : modules_right_) {
|
||||
auto* custom = dynamic_cast<waybar::modules::Custom*>(module.get());
|
||||
if(custom) custom->refresh(signal);
|
||||
}
|
||||
}
|
||||
|
||||
void waybar::Bar::layerSurfaceHandleConfigure(void* data,
|
||||
struct zwlr_layer_surface_v1* surface, uint32_t serial, uint32_t width,
|
||||
uint32_t height)
|
||||
|
@ -19,6 +19,14 @@ int main(int argc, char* argv[])
|
||||
}
|
||||
});
|
||||
|
||||
for (int sig = SIGRTMIN + 1; sig <= SIGRTMAX; ++sig) {
|
||||
std::signal(sig, [] (int sig/*signal*/) {
|
||||
for (auto& bar : waybar::client->bars) {
|
||||
bar->handleSignal(sig);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return c.main(argc, argv);
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << e.what() << std::endl;
|
||||
|
@ -78,6 +78,13 @@ void waybar::modules::Custom::continuousWorker()
|
||||
};
|
||||
}
|
||||
|
||||
void waybar::modules::Custom::refresh(int sig /*signal*/)
|
||||
{
|
||||
if(sig == SIGRTMIN + config_["signal"].asInt()) {
|
||||
thread_.wake_up();
|
||||
}
|
||||
}
|
||||
|
||||
auto waybar::modules::Custom::update() -> void
|
||||
{
|
||||
// Hide label if output is empty
|
||||
|
Reference in New Issue
Block a user