refactor: call parent update

This commit is contained in:
Alex 2020-04-12 18:30:21 +02:00
parent 0f0765e517
commit b40cdcb5bd
17 changed files with 39 additions and 53 deletions

View File

@ -31,7 +31,7 @@ ALabel::ALabel(const Json::Value& config, const std::string& name, const std::st
} }
auto ALabel::update() -> void { auto ALabel::update() -> void {
// Nothing here AModule::update();
} }
std::string ALabel::getIcon(uint16_t percentage, const std::string& alt, uint16_t max) { std::string ALabel::getIcon(uint16_t percentage, const std::string& alt, uint16_t max) {

View File

@ -29,7 +29,10 @@ AModule::~AModule() {
} }
auto AModule::update() -> void { auto AModule::update() -> void {
// Run user-provided update handler if configured
if (config_["on-update"].isString()) {
pid_.push_back(util::command::forkExec(config_["on-update"].asString())); pid_.push_back(util::command::forkExec(config_["on-update"].asString()));
}
} }
bool AModule::handleToggle(GdkEventButton* const& e) { bool AModule::handleToggle(GdkEventButton* const& e) {

View File

@ -192,6 +192,8 @@ auto waybar::modules::Backlight::update() -> void {
} }
previous_best_ = best == nullptr ? std::nullopt : std::optional{*best}; previous_best_ = best == nullptr ? std::nullopt : std::optional{*best};
previous_format_ = format_; previous_format_ = format_;
// Call parent update
ALabel::update();
} }
template <class ForwardIt> template <class ForwardIt>

View File

@ -149,11 +149,6 @@ const std::string waybar::modules::Battery::formatTimeRemaining(float hoursRemai
} }
auto waybar::modules::Battery::update() -> void { 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(); auto [capacity, time_remaining, status] = getInfos();
if (status == "Unknown") { if (status == "Unknown") {
status = getAdapterStatus(capacity); status = getAdapterStatus(capacity);
@ -192,4 +187,6 @@ auto waybar::modules::Battery::update() -> void {
fmt::arg("icon", getIcon(capacity, state)), fmt::arg("icon", getIcon(capacity, state)),
fmt::arg("time", formatTimeRemaining(time_remaining)))); fmt::arg("time", formatTimeRemaining(time_remaining))));
} }
// Call parent update
ALabel::update();
} }

View File

@ -13,11 +13,6 @@ waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config)
} }
auto waybar::modules::Clock::update() -> void { auto waybar::modules::Clock::update() -> void {
// Run user-provided update handler if configured
if (config_["on-update"].isString()) {
AModule::update();
}
tzset(); // Update timezone information tzset(); // Update timezone information
auto now = std::chrono::system_clock::now(); auto now = std::chrono::system_clock::now();
auto localtime = fmt::localtime(std::chrono::system_clock::to_time_t(now)); auto localtime = fmt::localtime(std::chrono::system_clock::to_time_t(now));
@ -33,4 +28,6 @@ auto waybar::modules::Clock::update() -> void {
label_.set_tooltip_text(text); label_.set_tooltip_text(text);
} }
} }
// Call parent update
ALabel::update();
} }

View File

@ -10,11 +10,6 @@ waybar::modules::Cpu::Cpu(const std::string& id, const Json::Value& config)
} }
auto waybar::modules::Cpu::update() -> void { 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 // TODO: as creating dynamic fmt::arg arrays is buggy we have to calc both
auto cpu_load = getCpuLoad(); auto cpu_load = getCpuLoad();
auto [cpu_usage, tooltip] = getCpuUsage(); auto [cpu_usage, tooltip] = getCpuUsage();
@ -23,6 +18,8 @@ auto waybar::modules::Cpu::update() -> void {
} }
label_.set_markup(fmt::format(format_, fmt::arg("load", cpu_load), fmt::arg("usage", cpu_usage))); label_.set_markup(fmt::format(format_, fmt::arg("load", cpu_load), fmt::arg("usage", cpu_usage)));
getState(cpu_usage); getState(cpu_usage);
// Call parent update
ALabel::update();
} }
uint16_t waybar::modules::Cpu::getCpuLoad() { uint16_t waybar::modules::Cpu::getCpuLoad() {

View File

@ -93,11 +93,6 @@ bool waybar::modules::Custom::handleToggle(GdkEventButton* const& e) {
} }
auto waybar::modules::Custom::update() -> void { 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 // Hide label if output is empty
if (config_["exec"].isString() && (output_.out.empty() || output_.exit_code != 0)) { if (config_["exec"].isString() && (output_.out.empty() || output_.exit_code != 0)) {
event_box_.hide(); event_box_.hide();
@ -133,6 +128,8 @@ auto waybar::modules::Custom::update() -> void {
event_box_.show(); event_box_.show();
} }
} }
// Call parent update
ALabel::update();
} }
void waybar::modules::Custom::parseOutputRaw() { void waybar::modules::Custom::parseOutputRaw() {

View File

@ -73,4 +73,6 @@ auto waybar::modules::Disk::update() -> void {
)); ));
} }
event_box_.show(); event_box_.show();
// Call parent update
ALabel::update();
} }

View File

@ -26,17 +26,14 @@ waybar::modules::IdleInhibitor::~IdleInhibitor() {
} }
auto waybar::modules::IdleInhibitor::update() -> void { auto waybar::modules::IdleInhibitor::update() -> void {
// Run user-provided update handler if configured
if (config_["on-update"].isString()) {
AModule::update();
}
label_.set_markup( label_.set_markup(
fmt::format(format_, fmt::arg("status", status_), fmt::arg("icon", getIcon(0, status_)))); fmt::format(format_, fmt::arg("status", status_), fmt::arg("icon", getIcon(0, status_))));
label_.get_style_context()->add_class(status_); label_.get_style_context()->add_class(status_);
if (tooltipEnabled()) { if (tooltipEnabled()) {
label_.set_tooltip_text(status_); label_.set_tooltip_text(status_);
} }
// Call parent update
ALabel::update();
} }
bool waybar::modules::IdleInhibitor::handleToggle(GdkEventButton* const& e) { bool waybar::modules::IdleInhibitor::handleToggle(GdkEventButton* const& e) {

View File

@ -9,11 +9,6 @@ waybar::modules::Memory::Memory(const std::string& id, const Json::Value& config
} }
auto waybar::modules::Memory::update() -> void { auto waybar::modules::Memory::update() -> void {
// Run user-provided update handler if configured
if (config_["on-update"].isString()) {
AModule::update();
}
parseMeminfo(); parseMeminfo();
if (memtotal_ > 0 && memfree_ >= 0) { if (memtotal_ > 0 && memfree_ >= 0) {
auto total_ram_gigabytes = memtotal_ / std::pow(1024, 2); auto total_ram_gigabytes = memtotal_ / std::pow(1024, 2);
@ -35,6 +30,8 @@ auto waybar::modules::Memory::update() -> void {
} else { } else {
event_box_.hide(); event_box_.hide();
} }
// Call parent update
ALabel::update();
} }
void waybar::modules::Memory::parseMeminfo() { void waybar::modules::Memory::parseMeminfo() {

View File

@ -35,11 +35,6 @@ waybar::modules::MPD::MPD(const std::string& id, const Json::Value& config)
} }
auto waybar::modules::MPD::update() -> void { 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_); std::lock_guard guard(connection_lock_);
tryConnect(); tryConnect();
@ -61,6 +56,9 @@ auto waybar::modules::MPD::update() -> void {
} }
setLabel(); setLabel();
// Call parent update
ALabel::update();
} }
std::thread waybar::modules::MPD::event_listener() { std::thread waybar::modules::MPD::event_listener() {

View File

@ -228,11 +228,6 @@ const std::string waybar::modules::Network::getNetworkState() const {
} }
auto waybar::modules::Network::update() -> void { 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::lock_guard<std::mutex> lock(mutex_);
std::string tooltip_format; std::string tooltip_format;
auto down_octets = read_netstat(BANDWIDTH_CATEGORY, BANDWIDTH_DOWN_TOTAL_KEY); auto down_octets = read_netstat(BANDWIDTH_CATEGORY, BANDWIDTH_DOWN_TOTAL_KEY);
@ -314,6 +309,9 @@ auto waybar::modules::Network::update() -> void {
label_.set_tooltip_text(text); label_.set_tooltip_text(text);
} }
} }
// Call parent update
ALabel::update();
} }
// Based on https://gist.github.com/Yawning/c70d804d4b8ae78cc698 // Based on https://gist.github.com/Yawning/c70d804d4b8ae78cc698

View File

@ -196,11 +196,6 @@ const std::string waybar::modules::Pulseaudio::getPortIcon() const {
} }
auto waybar::modules::Pulseaudio::update() -> void { auto waybar::modules::Pulseaudio::update() -> void {
// Run user-provided update handler if configured
if (config_["on-update"].isString()) {
AModule::update();
}
auto format = format_; auto format = format_;
std::string format_name = "format"; std::string format_name = "format";
if (monitor_.find("a2dp_sink") != std::string::npos) { if (monitor_.find("a2dp_sink") != std::string::npos) {
@ -234,4 +229,7 @@ auto waybar::modules::Pulseaudio::update() -> void {
if (tooltipEnabled()) { if (tooltipEnabled()) {
label_.set_tooltip_text(desc_); label_.set_tooltip_text(desc_);
} }
// Call parent update
ALabel::update();
} }

View File

@ -51,6 +51,8 @@ auto Mode::update() -> void {
} }
event_box_.show(); event_box_.show();
} }
// Call parent update
ALabel::update();
} }
} // namespace waybar::modules::sway } // namespace waybar::modules::sway

View File

@ -64,6 +64,8 @@ auto Window::update() -> void {
if (tooltipEnabled()) { if (tooltipEnabled()) {
label_.set_tooltip_text(window_); label_.set_tooltip_text(window_);
} }
// Call parent update
ALabel::update();
} }
std::tuple<std::size_t, int, std::string, std::string> Window::getFocusedNode( std::tuple<std::size_t, int, std::string, std::string> Window::getFocusedNode(

View File

@ -176,6 +176,8 @@ auto Workspaces::update() -> void {
} }
onButtonReady(*it, button); onButtonReady(*it, button);
} }
// Call parent update
AModule::update();
} }
Gtk::Button &Workspaces::addButton(const Json::Value &node) { Gtk::Button &Workspaces::addButton(const Json::Value &node) {

View File

@ -19,11 +19,6 @@ waybar::modules::Temperature::Temperature(const std::string& id, const Json::Val
} }
auto waybar::modules::Temperature::update() -> void { 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 [temperature_c, temperature_f] = getTemperature();
auto critical = isCritical(temperature_c); auto critical = isCritical(temperature_c);
auto format = format_; auto format = format_;
@ -38,6 +33,8 @@ auto waybar::modules::Temperature::update() -> void {
fmt::arg("temperatureC", temperature_c), fmt::arg("temperatureC", temperature_c),
fmt::arg("temperatureF", temperature_f), fmt::arg("temperatureF", temperature_f),
fmt::arg("icon", getIcon(temperature_c, "", max_temp)))); fmt::arg("icon", getIcon(temperature_c, "", max_temp))));
// Call parent update
ALabel::update();
} }
std::tuple<uint16_t, uint16_t> waybar::modules::Temperature::getTemperature() { std::tuple<uint16_t, uint16_t> waybar::modules::Temperature::getTemperature() {