Skip to content

Commit

Permalink
added tooltip-format-<short_description> on hyprland/language tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
vpcano committed Oct 19, 2024
1 parent 696f7e1 commit 550d108
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
1 change: 0 additions & 1 deletion include/modules/hyprland/language.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class Language : public waybar::ALabel, public EventHandler {
std::mutex mutex_;
const Bar& bar_;
util::JsonParser parser_;
const bool tooltip_format_enabled_;

Layout layout_;
};
Expand Down
37 changes: 23 additions & 14 deletions src/modules/hyprland/language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ namespace waybar::modules::hyprland {

Language::Language(const std::string& id, const Bar& bar, const Json::Value& config)
: ALabel(config, "language", id, "{}", 0, true),
bar_(bar),
tooltip_format_enabled_{config_["tooltip-format"].isString()} {
bar_(bar) {
modulesReady = true;

if (!gIPC) {
Expand Down Expand Up @@ -56,30 +55,40 @@ auto Language::update() -> void {
fmt::arg("shortDescription", layout_.short_description),
fmt::arg("variant", layout_.variant)));
}

spdlog::debug("hyprland language formatted layout name {}", layoutName);

std::string tooltipContent = std::string{};
if (tooltipEnabled()) {
if (tooltip_format_enabled_) {
bool tooltip_enabled = tooltipEnabled();
if (tooltip_enabled) {
if (config_.isMember("tooltip-format")) {
auto tooltip_format = config_["tooltip-format"].asString();
tooltipContent = fmt::format(fmt::runtime(tooltip_format),
fmt::arg("long", layout_.full_name),
fmt::arg("short", layout_.short_name),
fmt::arg("shortDescription", layout_.short_description),
fmt::arg("variant", layout_.variant));

} else {
if (config_.isMember("tooltip-format-" + layout_.short_description + "-" + layout_.variant)) {
const auto propName = "tooltip-format-" + layout_.short_description + "-" + layout_.variant;
tooltipContent = fmt::format(fmt::runtime(tooltip_format), config_[propName].asString());
} else if (config_.isMember("tooltip-format-" + layout_.short_description)) {
const auto propName = "tooltip-format-" + layout_.short_description;
tooltipContent = fmt::format(fmt::runtime(tooltip_format), config_[propName].asString());
} else {
tooltipContent = trim(fmt::format(fmt::runtime(tooltip_format), fmt::arg("long", layout_.full_name),
fmt::arg("short", layout_.short_name),
fmt::arg("shortDescription", layout_.short_description),
fmt::arg("variant", layout_.variant)));
}
}
else {
// if no tooltip format is provided, use the same text as the module
tooltipContent = layoutName;
}
spdlog::debug("hyprland language formatted tooltip content {}", tooltipContent);
}

spdlog::debug("hyprland language formatted tooltip content {}", tooltipContent);

if (!format_.empty()) {
label_.show();
label_.set_markup(layoutName);
label_.set_tooltip_markup(tooltipContent);
if (tooltip_enabled) {
label_.set_tooltip_markup(tooltipContent);
}
} else {
label_.hide();
}
Expand Down

0 comments on commit 550d108

Please sign in to comment.