sync tooltip updates without resetting hover state
This commit is contained in:
@@ -35,6 +35,7 @@ class Custom : public ALabel {
|
|||||||
std::string id_;
|
std::string id_;
|
||||||
std::string alt_;
|
std::string alt_;
|
||||||
std::string tooltip_;
|
std::string tooltip_;
|
||||||
|
std::string last_tooltip_markup_;
|
||||||
const bool tooltip_format_enabled_;
|
const bool tooltip_format_enabled_;
|
||||||
std::vector<std::string> class_;
|
std::vector<std::string> class_;
|
||||||
int percentage_;
|
int percentage_;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "modules/custom.hpp"
|
#include "modules/custom.hpp"
|
||||||
|
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
#include "util/scope_guard.hpp"
|
#include "util/scope_guard.hpp"
|
||||||
|
|
||||||
@@ -180,21 +181,22 @@ auto waybar::modules::Custom::update() -> void {
|
|||||||
} else {
|
} else {
|
||||||
label_.set_markup(str);
|
label_.set_markup(str);
|
||||||
if (tooltipEnabled()) {
|
if (tooltipEnabled()) {
|
||||||
|
std::string tooltip_markup;
|
||||||
if (tooltip_format_enabled_) {
|
if (tooltip_format_enabled_) {
|
||||||
auto tooltip = config_["tooltip-format"].asString();
|
auto tooltip = config_["tooltip-format"].asString();
|
||||||
tooltip = fmt::format(fmt::runtime(tooltip), fmt::arg("text", text_),
|
tooltip_markup = fmt::format(fmt::runtime(tooltip), fmt::arg("text", text_),
|
||||||
fmt::arg("tooltip", tooltip_), fmt::arg("alt", alt_),
|
fmt::arg("tooltip", tooltip_), fmt::arg("alt", alt_),
|
||||||
fmt::arg("icon", getIcon(percentage_, alt_)),
|
fmt::arg("icon", getIcon(percentage_, alt_)),
|
||||||
fmt::arg("percentage", percentage_));
|
fmt::arg("percentage", percentage_));
|
||||||
label_.set_tooltip_markup(tooltip);
|
|
||||||
} else if (text_ == tooltip_) {
|
} else if (text_ == tooltip_) {
|
||||||
if (label_.get_tooltip_markup() != str) {
|
tooltip_markup = str;
|
||||||
label_.set_tooltip_markup(str);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (label_.get_tooltip_markup() != tooltip_) {
|
tooltip_markup = tooltip_;
|
||||||
label_.set_tooltip_markup(tooltip_);
|
}
|
||||||
}
|
|
||||||
|
if (last_tooltip_markup_ != tooltip_markup) {
|
||||||
|
label_.set_tooltip_markup(tooltip_markup);
|
||||||
|
last_tooltip_markup_ = std::move(tooltip_markup);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
auto style = label_.get_style_context();
|
auto style = label_.get_style_context();
|
||||||
|
|||||||
Reference in New Issue
Block a user