| 25 | } |
| 26 | |
| 27 | auto waybar::modules::Backlight::update() -> void { |
| 28 | GET_BEST_DEVICE(best, backend, preferred_device_); |
| 29 | |
| 30 | const auto previous_best_device = backend.get_previous_best_device(); |
| 31 | if (best != nullptr) { |
| 32 | if (previous_best_device != nullptr && *previous_best_device == *best && |
| 33 | !previous_format_.empty() && previous_format_ == format_) { |
| 34 | return; |
| 35 | } |
| 36 | |
| 37 | if (best->get_powered()) { |
| 38 | event_box_.show(); |
| 39 | const uint8_t percent = |
| 40 | best->get_max() == 0 ? 100 : round(best->get_actual() * 100.0f / best->get_max()); |
| 41 | |
| 42 | // Get the state and apply state-specific format if available |
| 43 | auto state = getState(percent); |
| 44 | std::string current_format = format_; |
| 45 | if (!state.empty()) { |
| 46 | std::string state_format_name = "format-" + state; |
| 47 | if (config_[state_format_name].isString()) { |
| 48 | current_format = config_[state_format_name].asString(); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | std::string desc = fmt::format(fmt::runtime(current_format), fmt::arg("percent", percent), |
| 53 | fmt::arg("icon", getIcon(percent))); |
| 54 | label_.set_markup(desc); |
| 55 | if (tooltipEnabled()) { |
| 56 | std::string tooltip_format; |
| 57 | if (config_["tooltip-format"].isString()) { |
| 58 | tooltip_format = config_["tooltip-format"].asString(); |
| 59 | } |
| 60 | if (!tooltip_format.empty()) { |
| 61 | label_.set_tooltip_text(fmt::format(fmt::runtime(tooltip_format), |
| 62 | fmt::arg("percent", percent), |
| 63 | fmt::arg("icon", getIcon(percent)))); |
| 64 | } else { |
| 65 | label_.set_tooltip_text(desc); |
| 66 | } |
| 67 | } |
| 68 | } else { |
| 69 | event_box_.hide(); |
| 70 | } |
| 71 | } else { |
| 72 | if (previous_best_device == nullptr) { |
| 73 | return; |
| 74 | } |
| 75 | label_.set_markup(""); |
| 76 | } |
| 77 | backend.set_previous_best_device(best); |
| 78 | previous_format_ = format_; |
| 79 | ALabel::update(); |
| 80 | } |
| 81 | |
| 82 | bool waybar::modules::Backlight::handleScroll(GdkEventScroll* e) { |
| 83 | // Check if the user has set a custom command for scrolling |
nothing calls this directly
no test coverage detected