Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions include/ALabel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <gtkmm/label.h>
#include <json/json.h>

#include <optional>

#include "AModule.hpp"

namespace waybar {
Expand All @@ -25,12 +27,19 @@ class ALabel : public AModule {
bool alt_ = false;
std::string default_format_;

bool setLabelMarkup(const Glib::ustring& markup);
bool setTooltipMarkup(const Glib::ustring& markup);

bool handleToggle(GdkEventButton* const& e) override;
virtual std::string getState(uint8_t value, bool lesser = false);

std::map<std::string, GtkMenuItem*> submenus_;
std::map<std::string, std::string> menuActionsMap_;
static void handleGtkMenuEvent(GtkMenuItem* menuitem, gpointer data);

private:
std::optional<Glib::ustring> last_label_markup_;
std::optional<Glib::ustring> last_tooltip_markup_;
};

} // namespace waybar
20 changes: 20 additions & 0 deletions src/ALabel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,26 @@ ALabel::ALabel(const Json::Value& config, const std::string& name, const std::st

auto ALabel::update() -> void { AModule::update(); }

bool ALabel::setLabelMarkup(const Glib::ustring& markup) {
if (last_label_markup_ == markup) {
return false;
}

label_.set_markup(markup);
last_label_markup_ = markup;
return true;
}

bool ALabel::setTooltipMarkup(const Glib::ustring& markup) {
if (last_tooltip_markup_ == markup) {
return false;
}

label_.set_tooltip_markup(markup);
last_tooltip_markup_ = markup;
return true;
}

std::string ALabel::getIcon(uint16_t percentage, const std::string& alt, uint16_t max) {
auto format_icons = config_["format-icons"];
if (format_icons.isObject()) {
Expand Down
8 changes: 4 additions & 4 deletions src/modules/mpd/mpd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void waybar::modules::MPD::setLabel() {
? config_["format-disconnected"].asString()
: "disconnected";
if (format.empty()) {
label_.set_markup(format);
setLabelMarkup(format);
label_.show();
} else {
label_.hide();
Expand All @@ -110,7 +110,7 @@ void waybar::modules::MPD::setLabel() {
? config_["tooltip-format-disconnected"].asString()
: "MPD (disconnected)";
// Nothing to format
label_.set_tooltip_markup(tooltip_format);
setTooltipMarkup(tooltip_format);
}
return;
}
Expand Down Expand Up @@ -190,7 +190,7 @@ void waybar::modules::MPD::setLabel() {
label_.hide();
} else {
label_.show();
label_.set_markup(text);
setLabelMarkup(text);
}
} catch (fmt::format_error const& e) {
spdlog::warn("mpd: format error: {}", e.what());
Expand All @@ -210,7 +210,7 @@ void waybar::modules::MPD::setLabel() {
fmt::arg("stateIcon", stateIcon), fmt::arg("consumeIcon", consumeIcon),
fmt::arg("randomIcon", randomIcon), fmt::arg("repeatIcon", repeatIcon),
fmt::arg("singleIcon", singleIcon), fmt::arg("filename", filename), fmt::arg("uri", uri));
label_.set_tooltip_markup(tooltip_text);
setTooltipMarkup(tooltip_text);
} catch (fmt::format_error const& e) {
spdlog::warn("mpd: format error (tooltip): {}", e.what());
}
Expand Down
4 changes: 2 additions & 2 deletions src/modules/sway/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ auto Window::update() -> void {
old_app_id_ = app_id_;
}

label_.set_markup(waybar::util::rewriteString(
setLabelMarkup(waybar::util::rewriteString(
fmt::format(fmt::runtime(format_), fmt::arg("title", window_), fmt::arg("app_id", app_id_),
fmt::arg("shell", shell_), fmt::arg("marks", marks_)),
config_["rewrite"]));
if (tooltipEnabled()) {
label_.set_tooltip_markup(window_);
setTooltipMarkup(window_);
}

updateAppIcon();
Expand Down