Add shortDescription

pull/1209/head
dmitry 2021-08-17 05:28:41 +03:00
parent 9aec6bbed4
commit a57e431437
3 changed files with 22 additions and 8 deletions

View File

@ -25,6 +25,7 @@ class Language : public ALabel, public sigc::trackable {
std::string full_name; std::string full_name;
std::string short_name; std::string short_name;
std::string variant; std::string variant;
std::string short_description;
}; };
class XKBContext { class XKBContext {
@ -36,6 +37,7 @@ class Language : public ALabel, public sigc::trackable {
rxkb_context* context_ = nullptr; rxkb_context* context_ = nullptr;
rxkb_layout* xkb_layout_ = nullptr; rxkb_layout* xkb_layout_ = nullptr;
Layout* layout_ = nullptr; Layout* layout_ = nullptr;
std::map<std::string, rxkb_layout*> base_layouts_by_name_;
}; };
void onEvent(const struct Ipc::ipc_response&); void onEvent(const struct Ipc::ipc_response&);
@ -50,7 +52,6 @@ class Language : public ALabel, public sigc::trackable {
Layout layout_; Layout layout_;
std::string tooltip_format_ = ""; std::string tooltip_format_ = "";
std::map<std::string, Layout> layouts_map_; std::map<std::string, Layout> layouts_map_;
XKBContext xkb_context_;
bool is_variant_displayed; bool is_variant_displayed;
util::JsonParser parser_; util::JsonParser parser_;

View File

@ -29,11 +29,13 @@ Addressed by *sway/language*
# FORMAT REPLACEMENTS # FORMAT REPLACEMENTS
*{short}*: Short name of layout (e.g. "en"). Equals to {}. *{short}*: Short name of layout (e.g. "us"). Equals to {}.
*{shortDescription}*: Short description of layout (e.g. "en").
*{long}*: Long name of layout (e.g. "English (Dvorak)"). *{long}*: Long name of layout (e.g. "English (Dvorak)").
*{variant}*: Variant of layout (e.g. "Dvorak"). *{variant}*: Variant of layout (e.g. "dvorak").
# EXAMPLES # EXAMPLES

View File

@ -90,6 +90,7 @@ void Language::onEvent(const struct Ipc::ipc_response& res) {
auto Language::update() -> void { auto Language::update() -> void {
auto display_layout = trim(fmt::format(format_, auto display_layout = trim(fmt::format(format_,
fmt::arg("short", layout_.short_name), fmt::arg("short", layout_.short_name),
fmt::arg("shortDescription", layout_.short_description),
fmt::arg("long", layout_.full_name), fmt::arg("long", layout_.full_name),
fmt::arg("variant", layout_.variant))); fmt::arg("variant", layout_.variant)));
label_.set_markup(display_layout); label_.set_markup(display_layout);
@ -97,10 +98,10 @@ auto Language::update() -> void {
if (tooltip_format_ != "") { if (tooltip_format_ != "") {
auto tooltip_display_layout = trim(fmt::format(tooltip_format_, auto tooltip_display_layout = trim(fmt::format(tooltip_format_,
fmt::arg("short", layout_.short_name), fmt::arg("short", layout_.short_name),
fmt::arg("shortDescription", layout_.short_description),
fmt::arg("long", layout_.full_name), fmt::arg("long", layout_.full_name),
fmt::arg("variant", layout_.variant))); fmt::arg("variant", layout_.variant)));
label_.set_tooltip_markup(tooltip_display_layout); label_.set_tooltip_markup(tooltip_display_layout);
} else { } else {
label_.set_tooltip_markup(display_layout); label_.set_tooltip_markup(display_layout);
} }
@ -118,8 +119,9 @@ auto Language::set_current_layout(std::string current_layout) -> void {
auto Language::init_layouts_map(const std::vector<std::string>& used_layouts) -> void { auto Language::init_layouts_map(const std::vector<std::string>& used_layouts) -> void {
std::map<std::string, std::vector<Layout*>> found_by_short_names; std::map<std::string, std::vector<Layout*>> found_by_short_names;
auto layout = xkb_context_.next_layout(); XKBContext* xkb_context_ = new XKBContext();
for (; layout != nullptr; layout = xkb_context_.next_layout()) { auto layout = xkb_context_->next_layout();
for (; layout != nullptr; layout = xkb_context_->next_layout()) {
if (std::find(used_layouts.begin(), used_layouts.end(), layout->full_name) == if (std::find(used_layouts.begin(), used_layouts.end(), layout->full_name) ==
used_layouts.end()) { used_layouts.end()) {
continue; continue;
@ -136,6 +138,7 @@ auto Language::init_layouts_map(const std::vector<std::string>& used_layouts) ->
layouts_map_.emplace(layout->full_name, *layout); layouts_map_.emplace(layout->full_name, *layout);
} }
//delete xkb_context_;
if (is_variant_displayed || found_by_short_names.size() == 0) { if (is_variant_displayed || found_by_short_names.size() == 0) {
return; return;
@ -145,7 +148,6 @@ auto Language::init_layouts_map(const std::vector<std::string>& used_layouts) ->
for (const auto& used_layout_name : used_layouts) { for (const auto& used_layout_name : used_layouts) {
auto used_layout = &layouts_map_.find(used_layout_name)->second; auto used_layout = &layouts_map_.find(used_layout_name)->second;
auto layouts_with_same_name_list = found_by_short_names[used_layout->short_name]; auto layouts_with_same_name_list = found_by_short_names[used_layout->short_name];
spdlog::info("SIZE: " + std::to_string(layouts_with_same_name_list.size()));
if (layouts_with_same_name_list.size() < 2) { if (layouts_with_same_name_list.size() < 2) {
continue; continue;
} }
@ -180,8 +182,17 @@ auto Language::XKBContext::next_layout() -> Layout* {
auto name = std::string(rxkb_layout_get_name(xkb_layout_)); auto name = std::string(rxkb_layout_get_name(xkb_layout_));
auto variant_ = rxkb_layout_get_variant(xkb_layout_); auto variant_ = rxkb_layout_get_variant(xkb_layout_);
std::string variant = variant_ == nullptr ? "" : std::string(variant_); std::string variant = variant_ == nullptr ? "" : std::string(variant_);
auto short_description_ = rxkb_layout_get_brief(xkb_layout_);
std::string short_description;
if (short_description_ != nullptr) {
short_description = std::string(short_description_);
base_layouts_by_name_.emplace(name, xkb_layout_);
} else {
auto base_layout = base_layouts_by_name_[name];
short_description = base_layout == nullptr ? "" : std::string(rxkb_layout_get_brief(base_layout));
}
layout_ = new Layout{description, name, variant}; layout_ = new Layout{description, name, variant, short_description};
return layout_; return layout_;
} }