Merge pull request #5156 from Alexays/refactor/generic-tooltip

refactor(ALabel): generic label+tooltip helper to remove per-module duplication
This commit is contained in:
Alexis Rouillard
2026-07-04 00:37:19 +02:00
committed by GitHub
29 changed files with 257 additions and 334 deletions
+48
View File
@@ -1,10 +1,14 @@
#pragma once #pragma once
#include <fmt/args.h>
#include <fmt/format.h>
#include <glibmm/markup.h> #include <glibmm/markup.h>
#include <gtkmm/label.h> #include <gtkmm/label.h>
#include <json/json.h> #include <json/json.h>
#include <optional> #include <optional>
#include <string>
#include <utility>
#include "AModule.hpp" #include "AModule.hpp"
@@ -30,6 +34,50 @@ class ALabel : public AModule {
bool setLabelMarkup(const Glib::ustring& markup); bool setLabelMarkup(const Glib::ustring& markup);
bool setTooltipMarkup(const Glib::ustring& markup); bool setTooltipMarkup(const Glib::ustring& markup);
// resolveTooltipFormat() / resolveFormat() are inherited from AModule.
// Combined label + tooltip helper. Builds a single fmt argument store from
// `args`, renders `labelFormat` into the label and the resolved tooltip format
// into the tooltip, both through the dedup-aware setters. Honors the `tooltip`
// toggle. This replaces the label/tooltip formatting boilerplate that modules
// used to duplicate. `state` selects `tooltip-format-<state>` when non-empty.
template <typename... Args>
void updateLabelAndTooltipForState(const std::string& state, const std::string& labelFormat,
const std::string& tooltipDefault, Args&&... args) {
fmt::dynamic_format_arg_store<fmt::format_context> store;
(store.push_back(std::forward<Args>(args)), ...);
setLabelMarkup(fmt::vformat(labelFormat, store));
if (tooltipEnabled()) {
setTooltipMarkup(fmt::vformat(resolveTooltipFormat(tooltipDefault, state), store));
}
}
template <typename... Args>
void updateLabelAndTooltip(const std::string& labelFormat, const std::string& tooltipDefault,
Args&&... args) {
updateLabelAndTooltipForState("", labelFormat, tooltipDefault, std::forward<Args>(args)...);
}
// Overloads accepting a pre-built argument store, for modules that must
// assemble a dynamic set of format arguments (e.g. per-core CPU stats) that
// cannot be expressed through a fixed variadic call.
// A non-const reference is used so this overload is preferred over the
// variadic template above (which would otherwise bind the store as a single
// forwarded argument).
void updateLabelAndTooltipForState(const std::string& state, const std::string& labelFormat,
const std::string& tooltipDefault,
fmt::dynamic_format_arg_store<fmt::format_context>& store) {
setLabelMarkup(fmt::vformat(labelFormat, store));
if (tooltipEnabled()) {
setTooltipMarkup(fmt::vformat(resolveTooltipFormat(tooltipDefault, state), store));
}
}
void updateLabelAndTooltip(const std::string& labelFormat, const std::string& tooltipDefault,
fmt::dynamic_format_arg_store<fmt::format_context>& store) {
updateLabelAndTooltipForState("", labelFormat, tooltipDefault, store);
}
bool handleToggle(GdkEventButton* const& e) override; bool handleToggle(GdkEventButton* const& e) override;
void copyToClipboard(const std::string&); void copyToClipboard(const std::string&);
virtual std::string getState(uint8_t value, bool lesser = false); virtual std::string getState(uint8_t value, bool lesser = false);
+39
View File
@@ -1,11 +1,16 @@
#pragma once #pragma once
#include <fmt/args.h>
#include <fmt/format.h>
#include <glibmm/dispatcher.h> #include <glibmm/dispatcher.h>
#include <glibmm/markup.h> #include <glibmm/markup.h>
#include <gtkmm.h> #include <gtkmm.h>
#include <gtkmm/eventbox.h> #include <gtkmm/eventbox.h>
#include <json/json.h> #include <json/json.h>
#include <string>
#include <utility>
#include "IModule.hpp" #include "IModule.hpp"
namespace waybar { namespace waybar {
@@ -40,6 +45,40 @@ class AModule : public IModule {
SCROLL_DIR getScrollDir(GdkEventScroll* e); SCROLL_DIR getScrollDir(GdkEventScroll* e);
bool tooltipEnabled() const; bool tooltipEnabled() const;
// --- Generic format/tooltip resolution (config-only, usable by any module,
// ALabel-derived or not). Prefers `<key>-<state>`, then `<key>`, then default.
std::string resolveFormat(const std::string& defaultFormat, const std::string& state = "") const {
if (!state.empty() && config_["format-" + state].isString()) {
return config_["format-" + state].asString();
}
if (config_["format"].isString()) {
return config_["format"].asString();
}
return defaultFormat;
}
std::string resolveTooltipFormat(const std::string& defaultFormat,
const std::string& state = "") const {
if (!state.empty() && config_["tooltip-format-" + state].isString()) {
return config_["tooltip-format-" + state].asString();
}
if (config_["tooltip-format"].isString()) {
return config_["tooltip-format"].asString();
}
return defaultFormat;
}
// Generic tooltip for any widget: honors the `tooltip` toggle and
// `tooltip-format`, formats with the given args and applies it. Lets modules
// that are not ALabel-derived (e.g. gamemode) reuse the shared logic.
template <typename... Args>
void updateTooltip(Gtk::Widget& widget, const std::string& defaultFormat, Args&&... args) {
if (!tooltipEnabled()) {
return;
}
widget.set_tooltip_markup(
fmt::format(fmt::runtime(resolveTooltipFormat(defaultFormat)), std::forward<Args>(args)...));
}
std::vector<int> pid_children_; std::vector<int> pid_children_;
const std::string name_; const std::string name_;
const Json::Value& config_; const Json::Value& config_;
+4 -18
View File
@@ -55,24 +55,10 @@ auto waybar::modules::Backlight::update() -> void {
} }
} }
std::string desc = updateLabelAndTooltip(current_format, current_format, fmt::arg("percent", percent),
fmt::format(fmt::runtime(current_format), fmt::arg("percent", percent), fmt::arg("percent_exp", percent_exp),
fmt::arg("percent_exp", percent_exp), fmt::arg("icon", getIcon(percent)), fmt::arg("icon", getIcon(percent)),
fmt::arg("icon_exp", getIcon(percent_exp))); fmt::arg("icon_exp", getIcon(percent_exp)));
label_.set_markup(desc);
if (tooltipEnabled()) {
std::string tooltip_format;
if (config_["tooltip-format"].isString()) {
tooltip_format = config_["tooltip-format"].asString();
}
if (!tooltip_format.empty()) {
label_.set_tooltip_markup(fmt::format(fmt::runtime(tooltip_format),
fmt::arg("percent", percent),
fmt::arg("icon", getIcon(percent))));
} else {
label_.set_tooltip_markup(desc);
}
}
} else { } else {
event_box_.hide(); event_box_.hide();
} }
+2 -2
View File
@@ -767,7 +767,7 @@ auto waybar::modules::Battery::update() -> void {
} else if (config_["tooltip-format"].isString()) { } else if (config_["tooltip-format"].isString()) {
tooltip_format = config_["tooltip-format"].asString(); tooltip_format = config_["tooltip-format"].asString();
} }
label_.set_tooltip_markup( setTooltipMarkup(
fmt::format(fmt::runtime(tooltip_format), fmt::arg("timeTo", tooltip_text_default), fmt::format(fmt::runtime(tooltip_format), fmt::arg("timeTo", tooltip_text_default),
fmt::arg("power", power), fmt::arg("capacity", capacity), fmt::arg("power", power), fmt::arg("capacity", capacity),
fmt::arg("time", time_remaining_formatted), fmt::arg("cycles", cycles), fmt::arg("time", time_remaining_formatted), fmt::arg("cycles", cycles),
@@ -790,7 +790,7 @@ auto waybar::modules::Battery::update() -> void {
} else { } else {
event_box_.show(); event_box_.show();
auto icons = std::vector<std::string>{status + "-" + state, status, state}; auto icons = std::vector<std::string>{status + "-" + state, status, state};
label_.set_markup(fmt::format( setLabelMarkup(fmt::format(
fmt::runtime(format), fmt::arg("capacity", capacity), fmt::arg("power", power), fmt::runtime(format), fmt::arg("capacity", capacity), fmt::arg("power", power),
fmt::arg("icon", getIcon(capacity, icons)), fmt::arg("time", time_remaining_formatted), fmt::arg("icon", getIcon(capacity, icons)), fmt::arg("time", time_remaining_formatted),
fmt::arg("cycles", cycles), fmt::arg("health", fmt::format("{:.3}", health)))); fmt::arg("cycles", cycles), fmt::arg("health", fmt::format("{:.3}", health))));
+2 -2
View File
@@ -284,7 +284,7 @@ auto waybar::modules::Bluetooth::update() -> void {
event_box_.hide(); event_box_.hide();
} else { } else {
event_box_.show(); event_box_.show();
label_.set_markup(fmt::format( setLabelMarkup(fmt::format(
fmt::runtime(format_), fmt::arg("status", state_), fmt::runtime(format_), fmt::arg("status", state_),
fmt::arg("num_connections", connected_devices_.size()), fmt::arg("num_connections", connected_devices_.size()),
fmt::arg("controller_address", cur_controller_ ? cur_controller_->address : "null"), fmt::arg("controller_address", cur_controller_ ? cur_controller_->address : "null"),
@@ -332,7 +332,7 @@ auto waybar::modules::Bluetooth::update() -> void {
device_enumerate_.erase(0, 1); device_enumerate_.erase(0, 1);
} }
} }
label_.set_tooltip_markup(fmt::format( setTooltipMarkup(fmt::format(
fmt::runtime(tooltip_format), fmt::arg("status", state_), fmt::runtime(tooltip_format), fmt::arg("status", state_),
fmt::arg("num_connections", connected_devices_.size()), fmt::arg("num_connections", connected_devices_.size()),
fmt::arg("controller_address", cur_controller_ ? cur_controller_->address : "null"), fmt::arg("controller_address", cur_controller_ ? cur_controller_->address : "null"),
+1 -1
View File
@@ -163,7 +163,7 @@ auto waybar::modules::Clock::update() -> void {
const auto* tz = tzList_[tzCurrIdx_] != nullptr ? tzList_[tzCurrIdx_] : local_zone(); const auto* tz = tzList_[tzCurrIdx_] != nullptr ? tzList_[tzCurrIdx_] : local_zone();
const zoned_time now{tz, floor<seconds>(system_clock::now())}; const zoned_time now{tz, floor<seconds>(system_clock::now())};
label_.set_markup(fmt_lib::vformat(m_locale_, format_, fmt_lib::make_format_args(now))); setLabelMarkup(fmt_lib::vformat(m_locale_, format_, fmt_lib::make_format_args(now)));
if (tooltipEnabled()) { if (tooltipEnabled()) {
const year_month_day today{floor<days>(now.get_local_time())}; const year_month_day today{floor<days>(now.get_local_time())};
+1 -15
View File
@@ -62,21 +62,7 @@ auto waybar::modules::Cpu::update() -> void {
store.push_back(fmt::arg(arg_names.back().c_str(), core_icon)); store.push_back(fmt::arg(arg_names.back().c_str(), core_icon));
} }
store.push_back(fmt::arg("icons", all_icons)); store.push_back(fmt::arg("icons", all_icons));
label_.set_markup(fmt::vformat(format, store)); updateLabelAndTooltipForState(state, format, tooltip, store);
if (tooltipEnabled()) {
std::string tooltip_format;
if (!state.empty() && config_["tooltip-format-" + state].isString()) {
tooltip_format = config_["tooltip-format-" + state].asString();
} else if (config_["tooltip-format"].isString()) {
tooltip_format = config_["tooltip-format"].asString();
}
if (!tooltip_format.empty()) {
label_.set_tooltip_markup(fmt::vformat(tooltip_format, store));
} else {
label_.set_tooltip_markup(tooltip);
}
}
} }
// Call parent update // Call parent update
+6 -18
View File
@@ -32,24 +32,12 @@ auto waybar::modules::CpuFrequency::update() -> void {
} else { } else {
event_box_.show(); event_box_.show();
auto icons = std::vector<std::string>{state}; auto icons = std::vector<std::string>{state};
fmt::dynamic_format_arg_store<fmt::format_context> store; updateLabelAndTooltip(
store.push_back(fmt::arg("icon", getIcon(avg_frequency, icons))); format,
store.push_back(fmt::arg("max_frequency", max_frequency)); "Minimum frequency: {min_frequency}\nAverage frequency: {avg_frequency}\nMaximum "
store.push_back(fmt::arg("min_frequency", min_frequency)); "frequency: {max_frequency}\n",
store.push_back(fmt::arg("avg_frequency", avg_frequency)); fmt::arg("icon", getIcon(avg_frequency, icons)), fmt::arg("max_frequency", max_frequency),
label_.set_markup(fmt::vformat(format, store)); fmt::arg("min_frequency", min_frequency), fmt::arg("avg_frequency", avg_frequency));
if (tooltipEnabled()) {
std::string tooltip;
if (config_["tooltip-format"].isString()) {
tooltip = config_["tooltip-format"].asString();
label_.set_tooltip_markup(fmt::vformat(tooltip, store));
} else {
tooltip = "Minimum frequency: {}\nAverage frequency: {}\nMaximum frequency: {}\n";
label_.set_tooltip_markup(
fmt::format(fmt::runtime(tooltip), min_frequency, avg_frequency, max_frequency));
}
}
} }
// Call parent update // Call parent update
+1 -10
View File
@@ -49,16 +49,7 @@ auto waybar::modules::CpuUsage::update() -> void {
store.push_back(fmt::arg(arg_names.back().c_str(), core_icon)); store.push_back(fmt::arg(arg_names.back().c_str(), core_icon));
} }
store.push_back(fmt::arg("icons", all_icons)); store.push_back(fmt::arg("icons", all_icons));
label_.set_markup(fmt::vformat(format, store)); updateLabelAndTooltip(format, tooltip, store);
if (tooltipEnabled()) {
if (config_["tooltip-format"].isString()) {
tooltip = config_["tooltip-format"].asString();
label_.set_tooltip_markup(fmt::vformat(tooltip, store));
} else {
label_.set_tooltip_markup(tooltip);
}
}
} }
// Call parent update // Call parent update
+2 -5
View File
@@ -197,7 +197,7 @@ auto waybar::modules::Custom::update() -> void {
(str.empty() && image_path_.empty() && image_name_.empty())) { (str.empty() && image_path_.empty() && image_name_.empty())) {
event_box_.hide(); event_box_.hide();
} else { } else {
label_.set_markup(str); setLabelMarkup(str);
if (tooltipEnabled()) { if (tooltipEnabled()) {
std::string tooltip_markup; std::string tooltip_markup;
if (tooltip_format_enabled_) { if (tooltip_format_enabled_) {
@@ -212,10 +212,7 @@ auto waybar::modules::Custom::update() -> void {
tooltip_markup = tooltip_; tooltip_markup = tooltip_;
} }
if (last_tooltip_markup_ != tooltip_markup) { setTooltipMarkup(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();
auto classes = style->list_classes(); auto classes = style->list_classes();
+2 -2
View File
@@ -132,10 +132,10 @@ auto waybar::modules::Disk::update() -> void {
event_box_.hide(); event_box_.hide();
} }
label_.set_markup(label); setLabelMarkup(label);
if (tooltipEnabled() && !tooltip_label.empty()) { if (tooltipEnabled() && !tooltip_label.empty()) {
label_.set_tooltip_markup(tooltip_label); setTooltipMarkup(tooltip_label);
} }
// Call parent update // Call parent update
ALabel::update(); ALabel::update();
+1 -4
View File
@@ -210,10 +210,7 @@ auto Gamemode::update() -> void {
lastStatus = status; lastStatus = status;
// Tooltip // Tooltip
if (tooltip) { updateTooltip(box_, tooltip_format, fmt::arg("count", gameCount));
std::string text = fmt::format(fmt::runtime(tooltip_format), fmt::arg("count", gameCount));
box_.set_tooltip_markup(text);
}
// Label format // Label format
std::string str = fmt::format(fmt::runtime(showAltText ? format_alt : format), std::string str = fmt::format(fmt::runtime(showAltText ? format_alt : format),
+13 -43
View File
@@ -141,7 +141,7 @@ auto waybar::modules::Gps::update() -> void {
// Show the module // Show the module
if (!event_box_.get_visible()) event_box_.set_visible(true); if (!event_box_.get_visible()) event_box_.set_visible(true);
std::string tooltip_format; std::string tooltip_state;
if (!alt_) { if (!alt_) {
auto state = getFixModeName(); auto state = getFixModeName();
@@ -155,57 +155,27 @@ auto waybar::modules::Gps::update() -> void {
} else { } else {
default_format_ = DEFAULT_FORMAT; default_format_ = DEFAULT_FORMAT;
} }
if (config_["tooltip-format-" + state].isString()) {
tooltip_format = config_["tooltip-format-" + state].asString();
}
if (!label_.get_style_context()->has_class(state)) { if (!label_.get_style_context()->has_class(state)) {
label_.get_style_context()->add_class(state); label_.get_style_context()->add_class(state);
} }
format_ = default_format_; format_ = default_format_;
state_ = state; state_ = state;
tooltip_state = state;
} }
auto format = format_; auto format = format_;
fmt::dynamic_format_arg_store<fmt::format_context> store; updateLabelAndTooltipForState(
store.push_back(fmt::arg("mode", getFixModeString())); tooltip_state, format, format, fmt::arg("mode", getFixModeString()),
store.push_back(fmt::arg("status", getFixStatusString())); fmt::arg("status", getFixStatusString()), fmt::arg("latitude", gps_data_.fix.latitude),
fmt::arg("latitude_error", gps_data_.fix.epy), fmt::arg("longitude", gps_data_.fix.longitude),
store.push_back(fmt::arg("latitude", gps_data_.fix.latitude)); fmt::arg("longitude_error", gps_data_.fix.epx),
store.push_back(fmt::arg("latitude_error", gps_data_.fix.epy)); fmt::arg("altitude_hae", gps_data_.fix.altHAE),
fmt::arg("altitude_msl", gps_data_.fix.altMSL), fmt::arg("altitude_error", gps_data_.fix.epv),
store.push_back(fmt::arg("longitude", gps_data_.fix.longitude)); fmt::arg("speed", gps_data_.fix.speed), fmt::arg("speed_error", gps_data_.fix.eps),
store.push_back(fmt::arg("longitude_error", gps_data_.fix.epx)); fmt::arg("climb", gps_data_.fix.climb), fmt::arg("climb_error", gps_data_.fix.epc),
fmt::arg("satellites_used", gps_data_.satellites_used),
store.push_back(fmt::arg("altitude_hae", gps_data_.fix.altHAE)); fmt::arg("satellites_visible", gps_data_.satellites_visible));
store.push_back(fmt::arg("altitude_msl", gps_data_.fix.altMSL));
store.push_back(fmt::arg("altitude_error", gps_data_.fix.epv));
store.push_back(fmt::arg("speed", gps_data_.fix.speed));
store.push_back(fmt::arg("speed_error", gps_data_.fix.eps));
store.push_back(fmt::arg("climb", gps_data_.fix.climb));
store.push_back(fmt::arg("climb_error", gps_data_.fix.epc));
store.push_back(fmt::arg("satellites_used", gps_data_.satellites_used));
store.push_back(fmt::arg("satellites_visible", gps_data_.satellites_visible));
auto text = fmt::vformat(format, store);
if (tooltipEnabled()) {
if (tooltip_format.empty() && config_["tooltip-format"].isString()) {
tooltip_format = config_["tooltip-format"].asString();
}
if (!tooltip_format.empty()) {
auto tooltip_text = fmt::vformat(tooltip_format, store);
if (label_.get_tooltip_text() != tooltip_text) {
label_.set_tooltip_markup(tooltip_text);
}
} else if (label_.get_tooltip_text() != text) {
label_.set_tooltip_markup(text);
}
}
label_.set_markup(text);
// Call parent update // Call parent update
ALabel::update(); ALabel::update();
} }
+9 -9
View File
@@ -77,9 +77,9 @@ auto Language::update() -> void {
if (!format_.empty()) { if (!format_.empty()) {
label_.show(); label_.show();
label_.set_markup(layoutName); setLabelMarkup(layoutName);
if (tooltip_enabled) { if (tooltip_enabled) {
label_.set_tooltip_markup(tooltipContent); setTooltipMarkup(tooltipContent);
} }
} else { } else {
label_.hide(); label_.hide();
@@ -93,12 +93,11 @@ auto Language::update() -> void {
} else { } else {
tooltipFormat = "{long}"; tooltipFormat = "{long}";
} }
auto tooltipText = trim(fmt::format( auto tooltipText =
fmt::runtime(tooltipFormat), trim(fmt::format(fmt::runtime(tooltipFormat), fmt::arg("long", layout_.full_name),
fmt::arg("long", layout_.full_name), fmt::arg("short", layout_.short_name),
fmt::arg("short", layout_.short_name), fmt::arg("shortDescription", layout_.short_description),
fmt::arg("shortDescription", layout_.short_description), fmt::arg("variant", layout_.variant)));
fmt::arg("variant", layout_.variant)));
label_.set_tooltip_text(tooltipText); label_.set_tooltip_text(tooltipText);
} else { } else {
label_.set_tooltip_text(""); label_.set_tooltip_text("");
@@ -185,7 +184,8 @@ void Language::initLanguage() {
auto Language::removeXkbLayoutCssClass() -> void { auto Language::removeXkbLayoutCssClass() -> void {
label_.get_style_context()->remove_class(layout_.short_name); label_.get_style_context()->remove_class(layout_.short_name);
spdlog::debug("hyprland language try to remove currently short_name css class {}", layout_.short_name); spdlog::debug("hyprland language try to remove currently short_name css class {}",
layout_.short_name);
} }
auto Language::addXkbLayoutCssClass() -> void { auto Language::addXkbLayoutCssClass() -> void {
label_.get_style_context()->add_class(layout_.short_name); label_.get_style_context()->add_class(layout_.short_name);
+9 -10
View File
@@ -67,7 +67,7 @@ auto Window::update() -> void {
fmt::arg("class", windowData_.class_name), fmt::arg("class", windowData_.class_name),
fmt::arg("initialClass", windowData_.initial_class_name)), fmt::arg("initialClass", windowData_.initial_class_name)),
config_["rewrite"]); config_["rewrite"]);
label_.set_markup(label_text); setLabelMarkup(label_text);
} else { } else {
label_.hide(); label_.hide();
} }
@@ -78,13 +78,12 @@ auto Window::update() -> void {
tooltip_format = config_["tooltip-format"].asString(); tooltip_format = config_["tooltip-format"].asString();
} }
if (!tooltip_format.empty()) { if (!tooltip_format.empty()) {
label_.set_tooltip_markup( setTooltipMarkup(fmt::format(fmt::runtime(tooltip_format), fmt::arg("title", windowName),
fmt::format(fmt::runtime(tooltip_format), fmt::arg("title", windowName), fmt::arg("initialTitle", windowData_.initial_title),
fmt::arg("initialTitle", windowData_.initial_title), fmt::arg("class", windowData_.class_name),
fmt::arg("class", windowData_.class_name), fmt::arg("initialClass", windowData_.initial_class_name)));
fmt::arg("initialClass", windowData_.initial_class_name)));
} else if (!label_text.empty()) { } else if (!label_text.empty()) {
label_.set_tooltip_markup(label_text); setTooltipMarkup(label_text);
} }
} }
@@ -222,9 +221,9 @@ void Window::queryActiveWorkspace() {
std::vector<Json::Value> visibleWindows; std::vector<Json::Value> visibleWindows;
std::ranges::copy_if(workspaceWindows, std::back_inserter(visibleWindows), std::ranges::copy_if(workspaceWindows, std::back_inserter(visibleWindows),
[&](const Json::Value& window) { return !window["hidden"].asBool(); }); [&](const Json::Value& window) { return !window["hidden"].asBool(); });
solo_ = 1 == std::count_if( solo_ =
visibleWindows.begin(), visibleWindows.end(), 1 == std::count_if(visibleWindows.begin(), visibleWindows.end(),
[&](const Json::Value& window) { return !window["floating"].asBool(); }); [&](const Json::Value& window) { return !window["floating"].asBool(); });
allFloating_ = std::ranges::all_of( allFloating_ = std::ranges::all_of(
visibleWindows, [&](const Json::Value& window) { return window["floating"].asBool(); }); visibleWindows, [&](const Json::Value& window) { return window["floating"].asBool(); });
fullscreen_ = windowData_.fullscreen; fullscreen_ = windowData_.fullscreen;
+2 -9
View File
@@ -79,16 +79,9 @@ auto waybar::modules::IdleInhibitor::update() -> void {
} }
std::string status_text = status ? "activated" : "deactivated"; std::string status_text = status ? "activated" : "deactivated";
label_.set_markup(fmt::format(fmt::runtime(format_), fmt::arg("status", status_text), updateLabelAndTooltipForState(status_text, format_, "{status}", fmt::arg("status", status_text),
fmt::arg("icon", getIcon(0, status_text)))); fmt::arg("icon", getIcon(0, status_text)));
label_.get_style_context()->add_class(status_text); label_.get_style_context()->add_class(status_text);
if (tooltipEnabled()) {
auto config = config_[status ? "tooltip-format-activated" : "tooltip-format-deactivated"];
auto tooltip_format = config.isString() ? config.asString() : "{status}";
label_.set_tooltip_markup(fmt::format(fmt::runtime(tooltip_format),
fmt::arg("status", status_text),
fmt::arg("icon", getIcon(0, status_text))));
}
// Call parent update // Call parent update
ALabel::update(); ALabel::update();
} }
+4 -13
View File
@@ -72,19 +72,10 @@ auto JACK::update() -> void {
} else } else
format = "{load}%"; format = "{load}%";
label_.set_markup(fmt::format(fmt::runtime(format), fmt::arg("load", std::round(load_)), updateLabelAndTooltip(
fmt::arg("bufsize", bufsize_), fmt::arg("samplerate", samplerate_), format, "{bufsize}/{samplerate} {latency}ms", fmt::arg("load", std::round(load_)),
fmt::arg("latency", fmt::format("{:.2f}", latency)), fmt::arg("bufsize", bufsize_), fmt::arg("samplerate", samplerate_),
fmt::arg("xruns", xruns_))); fmt::arg("latency", fmt::format("{:.2f}", latency)), fmt::arg("xruns", xruns_));
if (tooltipEnabled()) {
std::string tooltip_format = "{bufsize}/{samplerate} {latency}ms";
if (config_["tooltip-format"].isString()) tooltip_format = config_["tooltip-format"].asString();
label_.set_tooltip_markup(fmt::format(
fmt::runtime(tooltip_format), fmt::arg("load", std::round(load_)),
fmt::arg("bufsize", bufsize_), fmt::arg("samplerate", samplerate_),
fmt::arg("latency", fmt::format("{:.2f}", latency)), fmt::arg("xruns", xruns_)));
}
// Call parent update // Call parent update
ALabel::update(); ALabel::update();
+14 -33
View File
@@ -1,16 +1,14 @@
#include "modules/memory.hpp" #include "modules/memory.hpp"
namespace { namespace {
const std::unordered_map<std::string, float> kUnits = { const std::unordered_map<std::string, float> kUnits = {{"kB", 1.000},
{"kB", 1.000}, {"kiB", 1.024},
{"kiB", 1.024}, {"MB", 1.000 * 1000.0},
{"MB", 1.000 * 1000.0}, {"MiB", 1.024 * 1024.0},
{"MiB", 1.024 * 1024.0}, {"GB", 1.000 * 1000.0 * 1000.0},
{"GB", 1.000 * 1000.0 * 1000.0}, {"GiB", 1.024 * 1024.0 * 1024.0},
{"GiB", 1.024 * 1024.0 * 1024.0}, {"TB", 1.000 * 1000.0 * 1000.0 * 1000.0},
{"TB", 1.000 * 1000.0 * 1000.0 * 1000.0}, {"TiB", 1.024 * 1024.0 * 1024.0 * 1024.0}};
{"TiB", 1.024 * 1024.0 * 1024.0 * 1024.0}
};
} }
waybar::modules::Memory::Memory(const std::string& id, const Json::Value& config) waybar::modules::Memory::Memory(const std::string& id, const Json::Value& config)
@@ -54,7 +52,7 @@ auto waybar::modules::Memory::update() -> void {
if (memtotal > 0 && memfree >= 0) { if (memtotal > 0 && memfree >= 0) {
int used_ram_percentage = 100 * (memtotal - memfree) / memtotal; int used_ram_percentage = 100 * (memtotal - memfree) / memtotal;
int used_swap_percentage = 0; int used_swap_percentage = 0;
if ((bool) swaptotal) { if ((bool)swaptotal) {
used_swap_percentage = 100 * (swaptotal - swapfree) / swaptotal; used_swap_percentage = 100 * (swaptotal - swapfree) / swaptotal;
} }
@@ -77,31 +75,14 @@ auto waybar::modules::Memory::update() -> void {
} else { } else {
event_box_.show(); event_box_.show();
auto icons = std::vector<std::string>{state}; auto icons = std::vector<std::string>{state};
label_.set_markup(fmt::format( updateLabelAndTooltip(
fmt::runtime(format), used_ram_percentage, format, fmt::format("{:.{}f}{} used", used_ram, 1, unit_), used_ram_percentage,
fmt::arg("icon", getIcon(used_ram_percentage, icons)), fmt::arg("icon", getIcon(used_ram_percentage, icons)), fmt::arg("total", total_ram),
fmt::arg("total", total_ram), fmt::arg("swapTotal", total_swap), fmt::arg("swapTotal", total_swap), fmt::arg("percentage", used_ram_percentage),
fmt::arg("percentage", used_ram_percentage),
fmt::arg("swapState", swaptotal == 0 ? "Off" : "On"), fmt::arg("swapState", swaptotal == 0 ? "Off" : "On"),
fmt::arg("swapPercentage", used_swap_percentage), fmt::arg("used", used_ram), fmt::arg("swapPercentage", used_swap_percentage), fmt::arg("used", used_ram),
fmt::arg("swapUsed", used_swap), fmt::arg("avail", available_ram), fmt::arg("swapUsed", used_swap), fmt::arg("avail", available_ram),
fmt::arg("swapAvail", available_swap))); fmt::arg("swapAvail", available_swap));
}
if (tooltipEnabled()) {
if (config_["tooltip-format"].isString()) {
auto tooltip_format = config_["tooltip-format"].asString();
label_.set_tooltip_markup(fmt::format(
fmt::runtime(tooltip_format), used_ram_percentage,
fmt::arg("total", total_ram), fmt::arg("swapTotal", total_swap),
fmt::arg("percentage", used_ram_percentage),
fmt::arg("swapState", swaptotal == 0 ? "Off" : "On"),
fmt::arg("swapPercentage", used_swap_percentage), fmt::arg("used", used_ram),
fmt::arg("swapUsed", used_swap), fmt::arg("avail", available_ram),
fmt::arg("swapAvail", available_swap)));
} else {
label_.set_tooltip_markup(fmt::format("{:.{}f}{} used", used_ram, 1, unit_));
}
} }
} else { } else {
event_box_.hide(); event_box_.hide();
+2 -2
View File
@@ -735,7 +735,7 @@ auto Mpris::update() -> void {
if (label_format.empty()) { if (label_format.empty()) {
label_.hide(); label_.hide();
} else { } else {
label_.set_markup(label_format); setLabelMarkup(label_format);
label_.show(); label_.show();
} }
} catch (fmt::format_error const& e) { } catch (fmt::format_error const& e) {
@@ -758,7 +758,7 @@ auto Mpris::update() -> void {
fmt::arg("player_icon", getIconFromJson(config_["player-icons"], info.name)), fmt::arg("player_icon", getIconFromJson(config_["player-icons"], info.name)),
fmt::arg("status_icon", getIconFromJson(config_["status-icons"], info.status_string))); fmt::arg("status_icon", getIconFromJson(config_["status-icons"], info.status_string)));
label_.set_tooltip_markup(tooltip_text); setTooltipMarkup(tooltip_text);
} catch (fmt::format_error const& e) { } catch (fmt::format_error const& e) {
spdlog::warn("mpris: format error (tooltip): {}", e.what()); spdlog::warn("mpris: format error (tooltip): {}", e.what());
} }
+41 -54
View File
@@ -356,32 +356,45 @@ auto waybar::modules::Network::update() -> void {
final_ipaddr_ += ipaddr6_; final_ipaddr_ += ipaddr6_;
} }
auto text = fmt::format( fmt::dynamic_format_arg_store<fmt::format_context> store;
fmt::runtime(format_), fmt::arg("essid", essid_), fmt::arg("bssid", bssid_), store.push_back(fmt::arg("essid", essid_));
fmt::arg("signaldBm", signal_strength_dbm_), fmt::arg("signalStrength", signal_strength_), store.push_back(fmt::arg("bssid", bssid_));
fmt::arg("signalStrengthApp", signal_strength_app_), fmt::arg("ifname", ifname_), store.push_back(fmt::arg("signaldBm", signal_strength_dbm_));
fmt::arg("netmask", netmask_), fmt::arg("netmask6", netmask6_), store.push_back(fmt::arg("signalStrength", signal_strength_));
fmt::arg("ipaddr", final_ipaddr_), fmt::arg("gwaddr", gwaddr_), fmt::arg("cidr", cidr_), store.push_back(fmt::arg("signalStrengthApp", signal_strength_app_));
fmt::arg("cidr6", cidr6_), fmt::arg("frequency", fmt::format("{:.1f}", frequency_)), store.push_back(fmt::arg("ifname", ifname_));
fmt::arg("icon", getIcon(signal_strength_, state_)), store.push_back(fmt::arg("netmask", netmask_));
fmt::arg("bandwidthDownBits", pow_format(bandwidth_down * 8ull / elapsed_seconds, "b/s")), store.push_back(fmt::arg("netmask6", netmask6_));
fmt::arg("bandwidthUpBits", pow_format(bandwidth_up * 8ull / elapsed_seconds, "b/s")), store.push_back(fmt::arg("ipaddr", final_ipaddr_));
store.push_back(fmt::arg("gwaddr", gwaddr_));
store.push_back(fmt::arg("cidr", cidr_));
store.push_back(fmt::arg("cidr6", cidr6_));
store.push_back(fmt::arg("frequency", fmt::format("{:.1f}", frequency_)));
store.push_back(fmt::arg("icon", getIcon(signal_strength_, state_)));
store.push_back(
fmt::arg("bandwidthDownBits", pow_format(bandwidth_down * 8ull / elapsed_seconds, "b/s")));
store.push_back(
fmt::arg("bandwidthUpBits", pow_format(bandwidth_up * 8ull / elapsed_seconds, "b/s")));
store.push_back(
fmt::arg("bandwidthTotalBits", fmt::arg("bandwidthTotalBits",
pow_format((bandwidth_up + bandwidth_down) * 8ull / elapsed_seconds, "b/s")), pow_format((bandwidth_up + bandwidth_down) * 8ull / elapsed_seconds, "b/s")));
fmt::arg("bandwidthDownOctets", pow_format(bandwidth_down / elapsed_seconds, "o/s")), store.push_back(
fmt::arg("bandwidthUpOctets", pow_format(bandwidth_up / elapsed_seconds, "o/s")), fmt::arg("bandwidthDownOctets", pow_format(bandwidth_down / elapsed_seconds, "o/s")));
fmt::arg("bandwidthTotalOctets", store.push_back(fmt::arg("bandwidthUpOctets", pow_format(bandwidth_up / elapsed_seconds, "o/s")));
pow_format((bandwidth_up + bandwidth_down) / elapsed_seconds, "o/s")), store.push_back(fmt::arg("bandwidthTotalOctets",
fmt::arg("bandwidthDownBytes", pow_format(bandwidth_down / elapsed_seconds, "B/s")), pow_format((bandwidth_up + bandwidth_down) / elapsed_seconds, "o/s")));
fmt::arg("bandwidthUpBytes", pow_format(bandwidth_up / elapsed_seconds, "B/s")), store.push_back(
fmt::arg("bandwidthDownBytesCompact", fmt::arg("bandwidthDownBytes", pow_format(bandwidth_down / elapsed_seconds, "B/s")));
pow_format(bandwidth_down / elapsed_seconds, "B", false, 2)), store.push_back(fmt::arg("bandwidthUpBytes", pow_format(bandwidth_up / elapsed_seconds, "B/s")));
fmt::arg("bandwidthUpBytesCompact", store.push_back(fmt::arg("bandwidthDownBytesCompact",
pow_format(bandwidth_up / elapsed_seconds, "B", false, 2)), pow_format(bandwidth_down / elapsed_seconds, "B", false, 2)));
fmt::arg("bandwidthTotalBytes", store.push_back(fmt::arg("bandwidthUpBytesCompact",
pow_format((bandwidth_up + bandwidth_down) / elapsed_seconds, "B/s"))); pow_format(bandwidth_up / elapsed_seconds, "B", false, 2)));
if (text.compare(label_.get_label()) != 0) { store.push_back(fmt::arg("bandwidthTotalBytes",
label_.set_markup(text); pow_format((bandwidth_up + bandwidth_down) / elapsed_seconds, "B/s")));
auto text = fmt::vformat(format_, store);
if (setLabelMarkup(text)) {
if (text.empty()) { if (text.empty()) {
event_box_.hide(); event_box_.hide();
} else { } else {
@@ -393,35 +406,9 @@ auto waybar::modules::Network::update() -> void {
tooltip_format = config_["tooltip-format"].asString(); tooltip_format = config_["tooltip-format"].asString();
} }
if (!tooltip_format.empty()) { if (!tooltip_format.empty()) {
auto tooltip_text = fmt::format( setTooltipMarkup(fmt::vformat(tooltip_format, store));
fmt::runtime(tooltip_format), fmt::arg("essid", essid_), fmt::arg("bssid", bssid_), } else {
fmt::arg("signaldBm", signal_strength_dbm_), fmt::arg("signalStrength", signal_strength_), setTooltipMarkup(text);
fmt::arg("signalStrengthApp", signal_strength_app_), fmt::arg("ifname", ifname_),
fmt::arg("netmask", netmask_), fmt::arg("netmask6", netmask6_),
fmt::arg("ipaddr", final_ipaddr_), fmt::arg("gwaddr", gwaddr_), fmt::arg("cidr", cidr_),
fmt::arg("cidr6", cidr6_), fmt::arg("frequency", fmt::format("{:.1f}", frequency_)),
fmt::arg("icon", getIcon(signal_strength_, state_)),
fmt::arg("bandwidthDownBits", pow_format(bandwidth_down * 8ull / elapsed_seconds, "b/s")),
fmt::arg("bandwidthUpBits", pow_format(bandwidth_up * 8ull / elapsed_seconds, "b/s")),
fmt::arg("bandwidthTotalBits",
pow_format((bandwidth_up + bandwidth_down) * 8ull / elapsed_seconds, "b/s")),
fmt::arg("bandwidthDownOctets", pow_format(bandwidth_down / elapsed_seconds, "o/s")),
fmt::arg("bandwidthUpOctets", pow_format(bandwidth_up / elapsed_seconds, "o/s")),
fmt::arg("bandwidthTotalOctets",
pow_format((bandwidth_up + bandwidth_down) / elapsed_seconds, "o/s")),
fmt::arg("bandwidthDownBytes", pow_format(bandwidth_down / elapsed_seconds, "B/s")),
fmt::arg("bandwidthUpBytes", pow_format(bandwidth_up / elapsed_seconds, "B/s")),
fmt::arg("bandwidthDownBytesCompact",
pow_format(bandwidth_down / elapsed_seconds, "B", false, 2)),
fmt::arg("bandwidthUpBytesCompact",
pow_format(bandwidth_up / elapsed_seconds, "B", false, 2)),
fmt::arg("bandwidthTotalBytes",
pow_format((bandwidth_up + bandwidth_down) / elapsed_seconds, "B/s")));
if (label_.get_tooltip_text() != tooltip_text) {
label_.set_tooltip_markup(tooltip_text);
}
} else if (label_.get_tooltip_text() != text) {
label_.set_tooltip_markup(text);
} }
} }
+8 -12
View File
@@ -187,18 +187,14 @@ void PowerProfilesDaemon::switchToProfile(std::string const& str) {
auto PowerProfilesDaemon::update() -> void { auto PowerProfilesDaemon::update() -> void {
if (connected_ && activeProfile_ != availableProfiles_.end()) { if (connected_ && activeProfile_ != availableProfiles_.end()) {
auto profile = (*activeProfile_); auto profile = (*activeProfile_);
// Set label // Set label and tooltip
fmt::dynamic_format_arg_store<fmt::format_context> store; updateLabelAndTooltip(format_, tooltipFormat_, fmt::arg("profile", profile.name),
store.push_back(fmt::arg("profile", profile.name)); // Legacy placeholder, kept for backward compatibility with existing
// Legacy placeholder, kept for backward compatibility with existing configs. // configs.
store.push_back(fmt::arg("driver", profile.driver)); fmt::arg("driver", profile.driver),
store.push_back(fmt::arg("cpu_driver", profile.cpuDriver)); fmt::arg("cpu_driver", profile.cpuDriver),
store.push_back(fmt::arg("platform_driver", profile.platformDriver)); fmt::arg("platform_driver", profile.platformDriver),
store.push_back(fmt::arg("icon", getIcon(0, profile.name))); fmt::arg("icon", getIcon(0, profile.name)));
label_.set_markup(fmt::vformat(format_, store));
if (tooltipEnabled()) {
label_.set_tooltip_markup(fmt::vformat(tooltipFormat_, store));
}
// Set CSS class // Set CSS class
if (!currentStyle_.empty()) { if (!currentStyle_.empty()) {
+14 -15
View File
@@ -73,7 +73,6 @@ const std::vector<std::string> waybar::modules::Pulseaudio::getPulseIcon() const
auto waybar::modules::Pulseaudio::update() -> void { auto waybar::modules::Pulseaudio::update() -> void {
auto format = format_; auto format = format_;
std::string tooltip_format;
auto sink_volume = backend->getSinkVolume(); auto sink_volume = backend->getSinkVolume();
if (!alt_) { if (!alt_) {
std::string format_name = "format"; std::string format_name = "format";
@@ -121,29 +120,29 @@ auto waybar::modules::Pulseaudio::update() -> void {
auto source_desc = backend->getSourceDesc(); auto source_desc = backend->getSourceDesc();
format_source = fmt::format(fmt::runtime(format_source), fmt::arg("volume", source_volume)); format_source = fmt::format(fmt::runtime(format_source), fmt::arg("volume", source_volume));
auto text = fmt::format(
fmt::runtime(format), fmt::arg("desc", sink_desc), fmt::arg("volume", sink_volume), fmt::dynamic_format_arg_store<fmt::format_context> store;
fmt::arg("format_source", format_source), fmt::arg("source_volume", source_volume), store.push_back(fmt::arg("desc", sink_desc));
fmt::arg("source_desc", source_desc), fmt::arg("icon", getIcon(sink_volume, getPulseIcon()))); store.push_back(fmt::arg("volume", sink_volume));
store.push_back(fmt::arg("format_source", format_source));
store.push_back(fmt::arg("source_volume", source_volume));
store.push_back(fmt::arg("source_desc", source_desc));
store.push_back(fmt::arg("icon", getIcon(sink_volume, getPulseIcon())));
auto text = fmt::vformat(format, store);
if (text.empty()) { if (text.empty()) {
label_.hide(); label_.hide();
} else { } else {
label_.set_markup(text); setLabelMarkup(text);
label_.show(); label_.show();
} }
if (tooltipEnabled()) { if (tooltipEnabled()) {
if (tooltip_format.empty() && config_["tooltip-format"].isString()) { auto tooltip_format = resolveTooltipFormat("");
tooltip_format = config_["tooltip-format"].asString();
}
if (!tooltip_format.empty()) { if (!tooltip_format.empty()) {
label_.set_tooltip_markup(fmt::format( setTooltipMarkup(fmt::vformat(tooltip_format, store));
fmt::runtime(tooltip_format), fmt::arg("desc", sink_desc),
fmt::arg("volume", sink_volume), fmt::arg("format_source", format_source),
fmt::arg("source_volume", source_volume), fmt::arg("source_desc", source_desc),
fmt::arg("icon", getIcon(sink_volume, getPulseIcon()))));
} else { } else {
label_.set_tooltip_markup(sink_desc); setTooltipMarkup(sink_desc);
} }
} }
+1 -12
View File
@@ -18,18 +18,7 @@ auto waybar::modules::Clock::update() -> void {
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));
auto text = fmt::format(fmt::runtime(format_), localtime); updateLabelAndTooltip(format_, format_, localtime);
label_.set_markup(text);
if (tooltipEnabled()) {
if (config_["tooltip-format"].isString()) {
auto tooltip_format = config_["tooltip-format"].asString();
auto tooltip_text = fmt::format(fmt::runtime(tooltip_format), localtime);
label_.set_tooltip_markup(tooltip_text);
} else {
label_.set_tooltip_markup(text);
}
}
// Call parent update // Call parent update
ALabel::update(); ALabel::update();
} }
+3 -3
View File
@@ -124,7 +124,7 @@ auto Language::update() -> void {
fmt::runtime(format_), fmt::arg("short", layout_.short_name), fmt::runtime(format_), fmt::arg("short", layout_.short_name),
fmt::arg("shortDescription", layout_.short_description), fmt::arg("long", layout_.full_name), fmt::arg("shortDescription", layout_.short_description), fmt::arg("long", layout_.full_name),
fmt::arg("variant", layout_.variant), fmt::arg("flag", layout_.country_flag()))); fmt::arg("variant", layout_.variant), fmt::arg("flag", layout_.country_flag())));
label_.set_markup(display_layout); setLabelMarkup(display_layout);
if (tooltipEnabled()) { if (tooltipEnabled()) {
if (tooltip_format_ != "") { if (tooltip_format_ != "") {
auto tooltip_display_layout = trim( auto tooltip_display_layout = trim(
@@ -132,9 +132,9 @@ auto Language::update() -> void {
fmt::arg("shortDescription", layout_.short_description), fmt::arg("shortDescription", layout_.short_description),
fmt::arg("long", layout_.full_name), fmt::arg("variant", layout_.variant), fmt::arg("long", layout_.full_name), fmt::arg("variant", layout_.variant),
fmt::arg("flag", layout_.country_flag()))); fmt::arg("flag", layout_.country_flag())));
label_.set_tooltip_markup(tooltip_display_layout); setTooltipMarkup(tooltip_display_layout);
} else { } else {
label_.set_tooltip_markup(display_layout); setTooltipMarkup(display_layout);
} }
} }
+2 -2
View File
@@ -31,12 +31,12 @@ Scratchpad::Scratchpad(const std::string& id, const Json::Value& config)
auto Scratchpad::update() -> void { auto Scratchpad::update() -> void {
if (count_ || show_empty_) { if (count_ || show_empty_) {
event_box_.show(); event_box_.show();
label_.set_markup( setLabelMarkup(
fmt::format(fmt::runtime(format_), fmt::format(fmt::runtime(format_),
fmt::arg("icon", getIcon(count_, "", config_["format-icons"].size())), fmt::arg("icon", getIcon(count_, "", config_["format-icons"].size())),
fmt::arg("count", count_))); fmt::arg("count", count_)));
if (tooltip_enabled_) { if (tooltip_enabled_) {
label_.set_tooltip_markup(tooltip_text_); setTooltipMarkup(tooltip_text_);
} }
} else { } else {
event_box_.hide(); event_box_.hide();
+3 -3
View File
@@ -281,7 +281,7 @@ auto SystemdFailedUnits::update() -> void {
last_status_ = overall_state_; last_status_ = overall_state_;
label_.set_markup(fmt::format( setLabelMarkup(fmt::format(
fmt::runtime(nr_failed_ == 0 ? format_ok_ : format_), fmt::arg("nr_failed", nr_failed_), fmt::runtime(nr_failed_ == 0 ? format_ok_ : format_), fmt::arg("nr_failed", nr_failed_),
fmt::arg("nr_failed_system", nr_failed_system_), fmt::arg("nr_failed_user", nr_failed_user_), fmt::arg("nr_failed_system", nr_failed_system_), fmt::arg("nr_failed_user", nr_failed_user_),
fmt::arg("system_state", system_state_), fmt::arg("user_state", user_state_), fmt::arg("system_state", system_state_), fmt::arg("user_state", user_state_),
@@ -290,14 +290,14 @@ auto SystemdFailedUnits::update() -> void {
std::string failed_list = BuildTooltipFailedList(); std::string failed_list = BuildTooltipFailedList();
auto tooltip_template = overall_state_ == "ok" ? tooltip_format_ok_ : tooltip_format_; auto tooltip_template = overall_state_ == "ok" ? tooltip_format_ok_ : tooltip_format_;
if (!tooltip_template.empty()) { if (!tooltip_template.empty()) {
label_.set_tooltip_markup(fmt::format( setTooltipMarkup(fmt::format(
fmt::runtime(tooltip_template), fmt::arg("nr_failed", nr_failed_), fmt::runtime(tooltip_template), fmt::arg("nr_failed", nr_failed_),
fmt::arg("nr_failed_system", nr_failed_system_), fmt::arg("nr_failed_system", nr_failed_system_),
fmt::arg("nr_failed_user", nr_failed_user_), fmt::arg("system_state", system_state_), fmt::arg("nr_failed_user", nr_failed_user_), fmt::arg("system_state", system_state_),
fmt::arg("user_state", user_state_), fmt::arg("overall_state", overall_state_), fmt::arg("user_state", user_state_), fmt::arg("overall_state", overall_state_),
fmt::arg("failed_units_list", failed_list))); fmt::arg("failed_units_list", failed_list)));
} else { } else {
label_.set_tooltip_markup(""); setTooltipMarkup("");
} }
} }
ALabel::update(); ALabel::update();
+4 -13
View File
@@ -155,19 +155,10 @@ auto waybar::modules::Temperature::update() -> void {
event_box_.show(); event_box_.show();
auto max_temp = config_["critical-threshold"].isInt() ? config_["critical-threshold"].asInt() : 0; auto max_temp = config_["critical-threshold"].isInt() ? config_["critical-threshold"].asInt() : 0;
label_.set_markup(fmt::format(fmt::runtime(format), fmt::arg("temperatureC", temperature_c), updateLabelAndTooltip(format, "{temperatureC}°C", fmt::arg("temperatureC", temperature_c),
fmt::arg("temperatureF", temperature_f), fmt::arg("temperatureF", temperature_f),
fmt::arg("temperatureK", temperature_k), fmt::arg("temperatureK", temperature_k),
fmt::arg("icon", getIcon(temperature_c, "", max_temp)))); fmt::arg("icon", getIcon(temperature_c, "", max_temp)));
if (tooltipEnabled()) {
std::string tooltip_format = "{temperatureC}°C";
if (config_["tooltip-format"].isString()) {
tooltip_format = config_["tooltip-format"].asString();
}
label_.set_tooltip_markup(fmt::format(
fmt::runtime(tooltip_format), fmt::arg("temperatureC", temperature_c),
fmt::arg("temperatureF", temperature_f), fmt::arg("temperatureK", temperature_k)));
}
// Call parent update // Call parent update
ALabel::update(); ALabel::update();
} }
+1 -1
View File
@@ -223,7 +223,7 @@ auto UPower::update() -> void {
return; return;
} }
label_.set_markup(getText(upDevice_, format_)); setLabelMarkup(getText(upDevice_, format_));
// Set icon // Set icon
if (upDevice_.icon_name == NULL || !gtkTheme_->has_icon(upDevice_.icon_name)) if (upDevice_.icon_name == NULL || !gtkTheme_->has_icon(upDevice_.icon_name))
upDevice_.icon_name = (char*)NO_BATTERY.c_str(); upDevice_.icon_name = (char*)NO_BATTERY.c_str();
+18 -23
View File
@@ -477,7 +477,6 @@ std::vector<std::string> waybar::modules::Wireplumber::getWPIcon() {
auto waybar::modules::Wireplumber::update() -> void { auto waybar::modules::Wireplumber::update() -> void {
auto format = format_; auto format = format_;
std::string tooltipFormat;
std::string format_name = "format"; std::string format_name = "format";
// Handle sink bluetooth state // Handle sink bluetooth state
@@ -543,32 +542,28 @@ auto waybar::modules::Wireplumber::update() -> void {
std::string formatted_source = std::string formatted_source =
fmt::format(fmt::runtime(format_source), fmt::arg("volume", source_vol)); fmt::format(fmt::runtime(format_source), fmt::arg("volume", source_vol));
std::string markup = fmt::format( fmt::dynamic_format_arg_store<fmt::format_context> store;
fmt::runtime(format), fmt::arg("node_name", node_name_), fmt::arg("volume", vol), store.push_back(fmt::arg("node_name", node_name_));
fmt::arg("icon", getIcon(vol, getWPIcon())), fmt::arg("format_source", formatted_source), store.push_back(fmt::arg("volume", vol));
fmt::arg("source_volume", source_vol), fmt::arg("source_desc", source_name_), store.push_back(fmt::arg("icon", getIcon(vol, getWPIcon())));
fmt::arg("volume_linear", volume_), fmt::arg("volume_cubic", vol_cube), store.push_back(fmt::arg("format_source", formatted_source));
fmt::arg("volume_db", vol_db), fmt::arg("source_volume_linear", source_volume_), store.push_back(fmt::arg("source_volume", source_vol));
fmt::arg("source_volume_cubic", source_vol_cube), store.push_back(fmt::arg("source_desc", source_name_));
fmt::arg("source_volume_db", source_vol_db)); store.push_back(fmt::arg("volume_linear", volume_));
label_.set_markup(markup); store.push_back(fmt::arg("volume_cubic", vol_cube));
store.push_back(fmt::arg("volume_db", vol_db));
store.push_back(fmt::arg("source_volume_linear", source_volume_));
store.push_back(fmt::arg("source_volume_cubic", source_vol_cube));
store.push_back(fmt::arg("source_volume_db", source_vol_db));
setLabelMarkup(fmt::vformat(format, store));
if (tooltipEnabled()) { if (tooltipEnabled()) {
if (tooltipFormat.empty() && config_["tooltip-format"].isString()) { auto tooltipFormat = resolveTooltipFormat("");
tooltipFormat = config_["tooltip-format"].asString();
}
if (!tooltipFormat.empty()) { if (!tooltipFormat.empty()) {
label_.set_tooltip_markup(fmt::format( setTooltipMarkup(fmt::vformat(tooltipFormat, store));
fmt::runtime(tooltipFormat), fmt::arg("node_name", node_name_), fmt::arg("volume", vol),
fmt::arg("icon", getIcon(vol, getWPIcon())), fmt::arg("format_source", formatted_source),
fmt::arg("source_volume", source_vol), fmt::arg("source_desc", source_name_),
fmt::arg("volume_linear", volume_), fmt::arg("volume_cubic", vol_cube),
fmt::arg("volume_db", vol_db), fmt::arg("source_volume_linear", source_volume_),
fmt::arg("source_volume_cubic", source_vol_cube),
fmt::arg("source_volume_db", source_vol_db)));
} else { } else {
label_.set_tooltip_markup(node_name_); setTooltipMarkup(node_name_);
} }
} }