Merge pull request #1178 from Anakael/pr/anakael/add-languge-tooltip-format

[sway/language] Add tooltip-format
This commit is contained in:
Alex 2021-07-25 15:05:58 +02:00 committed by GitHub
commit 91156dfc75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 1 deletions

View File

@ -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<std::string, Layout> layouts_map_;
XKBContext xkb_context_;
bool is_variant_displayed;

View File

@ -17,6 +17,11 @@ Addressed by *sway/language*
default: {} ++
The format, how layout should be displayed.
*tooltip-format*: ++
typeof: string ++
default: {} ++
The format, how layout should be displayed in tooltip.
*tooltip*: ++
typeof: bool ++
default: true ++

View File

@ -1,6 +1,7 @@
#include "modules/sway/language.hpp"
#include <fmt/core.h>
#include <json/json.h>
#include <spdlog/spdlog.h>
#include <xkbcommon/xkbregistry.h>
@ -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,8 +94,17 @@ auto Language::update() -> void {
fmt::arg("variant", layout_.variant)));
label_.set_markup(display_layout);
if (tooltipEnabled()) {
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();