Only redraw battery indicator on power change if power change option is set to true

This commit is contained in:
jkre 2023-12-14 22:56:31 +01:00
parent 578b01e06b
commit 2934138a66

View file

@ -717,14 +717,14 @@ namespace Cpu {
const auto& [percent, watts, seconds, status] = current_bat; const auto& [percent, watts, seconds, status] = current_bat;
if (redraw or percent != old_percent or watts != old_watts or seconds != old_seconds or status != old_status) { if (redraw or percent != old_percent or (watts != old_watts and Config::getB("show_battery_watts")) or seconds != old_seconds or status != old_status) {
old_percent = percent; old_percent = percent;
old_watts = watts; old_watts = watts;
old_seconds = seconds; old_seconds = seconds;
old_status = status; old_status = status;
const string str_time = (seconds > 0 ? sec_to_dhms(seconds, true, true) : ""); const string str_time = (seconds > 0 ? sec_to_dhms(seconds, true, true) : "");
const string str_percent = to_string(percent) + '%'; const string str_percent = to_string(percent) + '%';
const string str_watts = (watts != -1 ? fmt::format("{:.2f}", watts) + 'W' : ""); const string str_watts = (watts != -1 and Config::getB("show_battery_watts") ? fmt::format("{:.2f}", watts) + 'W' : "");
const auto& bat_symbol = bat_symbols.at((bat_symbols.contains(status) ? status : "unknown")); const auto& bat_symbol = bat_symbols.at((bat_symbols.contains(status) ? status : "unknown"));
const int current_len = (Term::width >= 100 ? 11 : 0) + str_time.size() + str_percent.size() + str_watts.size() + to_string(Config::getI("update_ms")).size(); const int current_len = (Term::width >= 100 ? 11 : 0) + str_time.size() + str_percent.size() + str_watts.size() + to_string(Config::getI("update_ms")).size();
const int current_pos = Term::width - current_len - 17; const int current_pos = Term::width - current_len - 17;
@ -736,7 +736,7 @@ namespace Cpu {
out += Mv::to(y, bat_pos) + title_left + Theme::c("title") + Fx::b + "BAT" + bat_symbol + ' ' + str_percent out += Mv::to(y, bat_pos) + title_left + Theme::c("title") + Fx::b + "BAT" + bat_symbol + ' ' + str_percent
+ (Term::width >= 100 ? Fx::ub + ' ' + bat_meter(percent) + Fx::b : "") + (Term::width >= 100 ? Fx::ub + ' ' + bat_meter(percent) + Fx::b : "")
+ (not str_time.empty() ? ' ' + Theme::c("title") + str_time : "") + (not str_watts.empty() ? ' ' + Theme::c("title") + Fx::b + str_watts : " ") + Fx::ub + title_right; + (not str_time.empty() ? ' ' + Theme::c("title") + str_time : "") + (not str_watts.empty() ? " " + Theme::c("title") + Fx::b + str_watts : "") + Fx::ub + title_right;
} }
} }
else if (bat_pos > 0) { else if (bat_pos > 0) {