Add tooltip-formay
This commit is contained in:
parent
1b4ddbca3a
commit
68e4457f3a
|
@ -48,6 +48,7 @@ class Language : public ALabel, public sigc::trackable {
|
||||||
const static std::string XKB_ACTIVE_LAYOUT_NAME_KEY;
|
const static std::string XKB_ACTIVE_LAYOUT_NAME_KEY;
|
||||||
|
|
||||||
Layout layout_;
|
Layout layout_;
|
||||||
|
std::string tooltip_format_ = "";
|
||||||
std::map<std::string, Layout> layouts_map_;
|
std::map<std::string, Layout> layouts_map_;
|
||||||
XKBContext xkb_context_;
|
XKBContext xkb_context_;
|
||||||
bool is_variant_displayed;
|
bool is_variant_displayed;
|
||||||
|
|
|
@ -17,6 +17,11 @@ Addressed by *sway/language*
|
||||||
default: {} ++
|
default: {} ++
|
||||||
The format, how layout should be displayed.
|
The format, how layout should be displayed.
|
||||||
|
|
||||||
|
*format-tooltip*: ++
|
||||||
|
typeof: string ++
|
||||||
|
default: {} ++
|
||||||
|
The format, how layout should be displayed in tooltip.
|
||||||
|
|
||||||
*tooltip*: ++
|
*tooltip*: ++
|
||||||
typeof: bool ++
|
typeof: bool ++
|
||||||
default: true ++
|
default: true ++
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "modules/sway/language.hpp"
|
#include "modules/sway/language.hpp"
|
||||||
|
|
||||||
#include <fmt/core.h>
|
#include <fmt/core.h>
|
||||||
|
#include <json/json.h>
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
#include <xkbcommon/xkbregistry.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)
|
Language::Language(const std::string& id, const Json::Value& config)
|
||||||
: ALabel(config, "language", id, "{}", 0, true) {
|
: ALabel(config, "language", id, "{}", 0, true) {
|
||||||
is_variant_displayed = format_.find("{variant}") != std::string::npos;
|
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_.subscribe(R"(["input"])");
|
||||||
ipc_.signal_event.connect(sigc::mem_fun(*this, &Language::onEvent));
|
ipc_.signal_event.connect(sigc::mem_fun(*this, &Language::onEvent));
|
||||||
ipc_.signal_cmd.connect(sigc::mem_fun(*this, &Language::onCmd));
|
ipc_.signal_cmd.connect(sigc::mem_fun(*this, &Language::onCmd));
|
||||||
|
@ -90,8 +94,17 @@ auto Language::update() -> void {
|
||||||
fmt::arg("variant", layout_.variant)));
|
fmt::arg("variant", layout_.variant)));
|
||||||
label_.set_markup(display_layout);
|
label_.set_markup(display_layout);
|
||||||
if (tooltipEnabled()) {
|
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);
|
label_.set_tooltip_markup(display_layout);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
event_box_.show();
|
event_box_.show();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue