1
0
Fork 0
mirror of https://github.com/polybar/polybar.git synced 2024-11-11 13:50:56 -05:00

fix: Initialize token labels in constructor

This commit is contained in:
Michael Carlberg 2016-06-22 19:07:57 +02:00
parent 04bd48d104
commit 8caa95de7f
2 changed files with 18 additions and 19 deletions

View file

@ -44,15 +44,21 @@ BatteryModule::BatteryModule(std::string name_) : InotifyModule(name_)
if (this->formatter->has(TAG_RAMP_CAPACITY))
this->ramp_capacity = drawtypes::get_config_ramp(
name(), get_tag_name(TAG_RAMP_CAPACITY));
if (this->formatter->has(TAG_LABEL_CHARGING, FORMAT_CHARGING))
if (this->formatter->has(TAG_LABEL_CHARGING, FORMAT_CHARGING)) {
this->label_charging = drawtypes::get_optional_config_label(
name(), get_tag_name(TAG_LABEL_CHARGING), "%percentage%");
if (this->formatter->has(TAG_LABEL_DISCHARGING, FORMAT_DISCHARGING))
this->label_charging_tokenized = this->label_charging->clone();
}
if (this->formatter->has(TAG_LABEL_DISCHARGING, FORMAT_DISCHARGING)) {
this->label_discharging = drawtypes::get_optional_config_label(
name(), get_tag_name(TAG_LABEL_DISCHARGING), "%percentage%");
if (this->formatter->has(TAG_LABEL_FULL, FORMAT_FULL))
this->label_discharging_tokenized = this->label_discharging->clone();
}
if (this->formatter->has(TAG_LABEL_FULL, FORMAT_FULL)) {
this->label_full = drawtypes::get_optional_config_label(
name(), get_tag_name(TAG_LABEL_FULL), "%percentage%");
this->label_full_tokenized = this->label_full->clone();
}
this->path_capacity = string::replace(PATH_BATTERY_CAPACITY, "%battery%", this->battery);
this->path_adapter = string::replace(PATH_ADAPTER_STATUS, "%adapter%", this->adapter);
@ -142,13 +148,6 @@ bool BatteryModule::on_event(InotifyEvent *event)
if (this->state == state && this->percentage == percentage)
return false;
if (!this->label_charging_tokenized)
this->label_charging_tokenized = this->label_charging->clone();
if (!this->label_discharging_tokenized)
this->label_discharging_tokenized = this->label_discharging->clone();
if (!this->label_full_tokenized)
this->label_full_tokenized = this->label_full->clone();
this->label_charging_tokenized->text = this->label_charging->text;
this->label_charging_tokenized->replace_token("%percentage%", IntToStr(percentage) + "%");

View file

@ -35,8 +35,10 @@ NetworkModule::NetworkModule(std::string name_) : TimerModule(name_, 1s)
// Create elements for format-connected
if (this->formatter->has(TAG_RAMP_SIGNAL, FORMAT_CONNECTED))
this->ramp_signal = drawtypes::get_config_ramp(name(), get_tag_name(TAG_RAMP_SIGNAL));
if (this->formatter->has(TAG_LABEL_CONNECTED, FORMAT_CONNECTED))
if (this->formatter->has(TAG_LABEL_CONNECTED, FORMAT_CONNECTED)) {
this->label_connected = drawtypes::get_optional_config_label(name(), get_tag_name(TAG_LABEL_CONNECTED), DEFAULT_LABEL_CONNECTED);
this->label_connected_tokenized = this->label_connected->clone();
}
// Create elements for format-disconnected
if (this->formatter->has(TAG_LABEL_DISCONNECTED, FORMAT_DISCONNECTED)) {
@ -48,8 +50,10 @@ NetworkModule::NetworkModule(std::string name_) : TimerModule(name_, 1s)
if (this->ping_nth_update > 0) {
this->formatter->add(FORMAT_PACKETLOSS, DEFAULT_FORMAT_PACKETLOSS, { TAG_ANIMATION_PACKETLOSS, TAG_LABEL_PACKETLOSS, TAG_LABEL_CONNECTED });
if (this->formatter->has(TAG_LABEL_PACKETLOSS, FORMAT_PACKETLOSS))
if (this->formatter->has(TAG_LABEL_PACKETLOSS, FORMAT_PACKETLOSS)) {
this->label_packetloss = drawtypes::get_optional_config_label(name(), get_tag_name(TAG_LABEL_PACKETLOSS), DEFAULT_LABEL_PACKETLOSS);
this->label_packetloss_tokenized = this->label_packetloss->clone();
}
if (this->formatter->has(TAG_ANIMATION_PACKETLOSS, FORMAT_PACKETLOSS))
this->animation_packetloss = drawtypes::get_config_animation(name(), get_tag_name(TAG_ANIMATION_PACKETLOSS));
}
@ -151,16 +155,12 @@ bool NetworkModule::update()
};
if (this->label_connected) {
if (!this->label_connected_tokenized)
this->label_connected_tokenized = this->label_connected->clone();
this->label_connected_tokenized->text = this->label_connected->text;
replace_tokens(this->label_connected_tokenized);
}
if (this->label_packetloss) {
if (!this->label_packetloss_tokenized)
this->label_packetloss_tokenized = this->label_packetloss->clone();
this->label_packetloss_tokenized->text = this->label_packetloss->text;
replace_tokens(this->label_packetloss_tokenized);