feat(modules): call user on-update if configured
This commit is contained in:
parent
de0a3cb020
commit
0f0765e517
|
@ -29,7 +29,7 @@ AModule::~AModule() {
|
|||
}
|
||||
|
||||
auto AModule::update() -> void {
|
||||
// Nothing here
|
||||
pid_.push_back(util::command::forkExec(config_["on-update"].asString()));
|
||||
}
|
||||
|
||||
bool AModule::handleToggle(GdkEventButton* const& e) {
|
||||
|
|
|
@ -175,6 +175,11 @@ auto waybar::modules::Backlight::update() -> void {
|
|||
return;
|
||||
}
|
||||
|
||||
// Run user-provided update handler if configured
|
||||
if (config_["on-update"].isString()) {
|
||||
AModule::update();
|
||||
}
|
||||
|
||||
const auto percent = best->get_max() == 0 ? 100 : best->get_actual() * 100 / best->get_max();
|
||||
label_.set_markup(fmt::format(
|
||||
format_, fmt::arg("percent", std::to_string(percent)), fmt::arg("icon", getIcon(percent))));
|
||||
|
|
|
@ -149,6 +149,11 @@ const std::string waybar::modules::Battery::formatTimeRemaining(float hoursRemai
|
|||
}
|
||||
|
||||
auto waybar::modules::Battery::update() -> void {
|
||||
// Run user-provided update handler if configured
|
||||
if (config_["on-update"].isString()) {
|
||||
AModule::update();
|
||||
}
|
||||
|
||||
auto [capacity, time_remaining, status] = getInfos();
|
||||
if (status == "Unknown") {
|
||||
status = getAdapterStatus(capacity);
|
||||
|
|
|
@ -13,6 +13,11 @@ waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config)
|
|||
}
|
||||
|
||||
auto waybar::modules::Clock::update() -> void {
|
||||
// Run user-provided update handler if configured
|
||||
if (config_["on-update"].isString()) {
|
||||
AModule::update();
|
||||
}
|
||||
|
||||
tzset(); // Update timezone information
|
||||
auto now = std::chrono::system_clock::now();
|
||||
auto localtime = fmt::localtime(std::chrono::system_clock::to_time_t(now));
|
||||
|
|
|
@ -10,6 +10,11 @@ waybar::modules::Cpu::Cpu(const std::string& id, const Json::Value& config)
|
|||
}
|
||||
|
||||
auto waybar::modules::Cpu::update() -> void {
|
||||
// Run user-provided update handler if configured
|
||||
if (config_["on-update"].isString()) {
|
||||
AModule::update();
|
||||
}
|
||||
|
||||
// TODO: as creating dynamic fmt::arg arrays is buggy we have to calc both
|
||||
auto cpu_load = getCpuLoad();
|
||||
auto [cpu_usage, tooltip] = getCpuUsage();
|
||||
|
|
|
@ -93,6 +93,11 @@ bool waybar::modules::Custom::handleToggle(GdkEventButton* const& e) {
|
|||
}
|
||||
|
||||
auto waybar::modules::Custom::update() -> void {
|
||||
// Run user-provided update handler if configured
|
||||
if (config_["on-update"].isString()) {
|
||||
AModule::update();
|
||||
}
|
||||
|
||||
// Hide label if output is empty
|
||||
if (config_["exec"].isString() && (output_.out.empty() || output_.exit_code != 0)) {
|
||||
event_box_.hide();
|
||||
|
|
|
@ -26,6 +26,11 @@ waybar::modules::IdleInhibitor::~IdleInhibitor() {
|
|||
}
|
||||
|
||||
auto waybar::modules::IdleInhibitor::update() -> void {
|
||||
// Run user-provided update handler if configured
|
||||
if (config_["on-update"].isString()) {
|
||||
AModule::update();
|
||||
}
|
||||
|
||||
label_.set_markup(
|
||||
fmt::format(format_, fmt::arg("status", status_), fmt::arg("icon", getIcon(0, status_))));
|
||||
label_.get_style_context()->add_class(status_);
|
||||
|
|
|
@ -9,6 +9,11 @@ waybar::modules::Memory::Memory(const std::string& id, const Json::Value& config
|
|||
}
|
||||
|
||||
auto waybar::modules::Memory::update() -> void {
|
||||
// Run user-provided update handler if configured
|
||||
if (config_["on-update"].isString()) {
|
||||
AModule::update();
|
||||
}
|
||||
|
||||
parseMeminfo();
|
||||
if (memtotal_ > 0 && memfree_ >= 0) {
|
||||
auto total_ram_gigabytes = memtotal_ / std::pow(1024, 2);
|
||||
|
|
|
@ -35,6 +35,11 @@ waybar::modules::MPD::MPD(const std::string& id, const Json::Value& config)
|
|||
}
|
||||
|
||||
auto waybar::modules::MPD::update() -> void {
|
||||
// Run user-provided update handler if configured
|
||||
if (config_["on-update"].isString()) {
|
||||
AModule::update();
|
||||
}
|
||||
|
||||
std::lock_guard guard(connection_lock_);
|
||||
tryConnect();
|
||||
|
||||
|
|
|
@ -228,6 +228,11 @@ const std::string waybar::modules::Network::getNetworkState() const {
|
|||
}
|
||||
|
||||
auto waybar::modules::Network::update() -> void {
|
||||
// Run user-provided update handler if configured
|
||||
if (config_["on-update"].isString()) {
|
||||
AModule::update();
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
std::string tooltip_format;
|
||||
auto down_octets = read_netstat(BANDWIDTH_CATEGORY, BANDWIDTH_DOWN_TOTAL_KEY);
|
||||
|
|
|
@ -196,6 +196,11 @@ const std::string waybar::modules::Pulseaudio::getPortIcon() const {
|
|||
}
|
||||
|
||||
auto waybar::modules::Pulseaudio::update() -> void {
|
||||
// Run user-provided update handler if configured
|
||||
if (config_["on-update"].isString()) {
|
||||
AModule::update();
|
||||
}
|
||||
|
||||
auto format = format_;
|
||||
std::string format_name = "format";
|
||||
if (monitor_.find("a2dp_sink") != std::string::npos) {
|
||||
|
|
|
@ -19,6 +19,11 @@ waybar::modules::Temperature::Temperature(const std::string& id, const Json::Val
|
|||
}
|
||||
|
||||
auto waybar::modules::Temperature::update() -> void {
|
||||
// Run user-provided update handler if configured
|
||||
if (config_["on-update"].isString()) {
|
||||
AModule::update();
|
||||
}
|
||||
|
||||
auto [temperature_c, temperature_f] = getTemperature();
|
||||
auto critical = isCritical(temperature_c);
|
||||
auto format = format_;
|
||||
|
|
Loading…
Reference in New Issue