From 68e4457f3a226c985bb48bf470f1a992e91cf688 Mon Sep 17 00:00:00 2001 From: dmitry Date: Sat, 24 Jul 2021 17:24:37 +0300 Subject: [PATCH] Add tooltip-formay --- include/modules/sway/language.hpp | 1 + man/waybar-sway-language.5.scd | 5 +++++ src/modules/sway/language.cpp | 15 ++++++++++++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/include/modules/sway/language.hpp b/include/modules/sway/language.hpp index fb4438bb..b310b7f3 100644 --- a/include/modules/sway/language.hpp +++ b/include/modules/sway/language.hpp @@ -48,6 +48,7 @@ class Language : public ALabel, public sigc::trackable { const static std::string XKB_ACTIVE_LAYOUT_NAME_KEY; Layout layout_; + std::string tooltip_format_ = ""; std::map layouts_map_; XKBContext xkb_context_; bool is_variant_displayed; diff --git a/man/waybar-sway-language.5.scd b/man/waybar-sway-language.5.scd index f7f88304..60a18fc3 100644 --- a/man/waybar-sway-language.5.scd +++ b/man/waybar-sway-language.5.scd @@ -17,6 +17,11 @@ Addressed by *sway/language* default: {} ++ The format, how layout should be displayed. +*format-tooltip*: ++ + typeof: string ++ + default: {} ++ + The format, how layout should be displayed in tooltip. + *tooltip*: ++ typeof: bool ++ default: true ++ diff --git a/src/modules/sway/language.cpp b/src/modules/sway/language.cpp index 86a8e1eb..5f3ce065 100644 --- a/src/modules/sway/language.cpp +++ b/src/modules/sway/language.cpp @@ -1,6 +1,7 @@ #include "modules/sway/language.hpp" #include +#include #include #include @@ -19,6 +20,9 @@ const std::string Language::XKB_ACTIVE_LAYOUT_NAME_KEY = "xkb_active_layout_name Language::Language(const std::string& id, const Json::Value& config) : ALabel(config, "language", id, "{}", 0, true) { is_variant_displayed = format_.find("{variant}") != std::string::npos; + if (config.isMember("tooltip-format")) { + tooltip_format_ = config["tooltip-format"].asString(); + } ipc_.subscribe(R"(["input"])"); ipc_.signal_event.connect(sigc::mem_fun(*this, &Language::onEvent)); ipc_.signal_cmd.connect(sigc::mem_fun(*this, &Language::onCmd)); @@ -90,7 +94,16 @@ auto Language::update() -> void { fmt::arg("variant", layout_.variant))); label_.set_markup(display_layout); if (tooltipEnabled()) { - label_.set_tooltip_markup(display_layout); + if (tooltip_format_ != "") { + auto tooltip_display_layout = trim(fmt::format(tooltip_format_, + fmt::arg("short", layout_.short_name), + fmt::arg("long", layout_.full_name), + fmt::arg("variant", layout_.variant))); + label_.set_tooltip_markup(tooltip_display_layout); + + } else { + label_.set_tooltip_markup(display_layout); + } } event_box_.show();