#pragma once #include #include #include #include #include #include #include #include #include "AModule.hpp" namespace waybar { class ALabel : public AModule { public: ALabel(const Json::Value&, const std::string&, const std::string&, const std::string& format, uint16_t interval = 0, bool ellipsize = false, bool enable_click = false, bool enable_scroll = false); virtual ~ALabel() = default; auto update() -> void override; virtual std::string getIcon(uint16_t, const std::string& alt = "", uint16_t max = 0); virtual std::string getIcon(uint16_t, const std::vector& alts, uint16_t max = 0); protected: Gtk::Label label_; std::string format_; const std::chrono::milliseconds interval_; bool alt_ = false; std::string default_format_; bool setLabelMarkup(const Glib::ustring& markup); bool setTooltipMarkup(const Glib::ustring& markup); // Resolve the tooltip format string: prefers `tooltip-format-` (when a // non-empty state is given), then `tooltip-format`, then `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; } // 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-` when non-empty. template void updateLabelAndTooltipForState(const std::string& state, const std::string& labelFormat, const std::string& tooltipDefault, Args&&... args) { fmt::dynamic_format_arg_store store; (store.push_back(std::forward(args)), ...); setLabelMarkup(fmt::vformat(labelFormat, store)); if (tooltipEnabled()) { setTooltipMarkup(fmt::vformat(resolveTooltipFormat(tooltipDefault, state), store)); } } template void updateLabelAndTooltip(const std::string& labelFormat, const std::string& tooltipDefault, Args&&... args) { updateLabelAndTooltipForState("", labelFormat, tooltipDefault, std::forward(args)...); } bool handleToggle(GdkEventButton* const& e) override; void copyToClipboard(const std::string&); virtual std::string getState(uint8_t value, bool lesser = false); std::map submenus_; std::map menuActionsMap_; static void handleGtkMenuEvent(GtkMenuItem* menuitem, gpointer data); private: std::optional last_label_markup_; std::optional last_tooltip_markup_; }; } // namespace waybar