Merge pull request #1229 from kraftwerk28/sway-language-country-flag

`sway/language` country flag
pull/1332/head^2
Alex 2021-12-01 11:49:39 +01:00 committed by GitHub
commit 7069429c03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 3 deletions

View File

@ -32,6 +32,7 @@ class Language : public ALabel, public sigc::trackable {
std::string short_name; std::string short_name;
std::string variant; std::string variant;
std::string short_description; std::string short_description;
std::string country_flag() const;
}; };
class XKBContext { class XKBContext {

View File

@ -37,6 +37,8 @@ Addressed by *sway/language*
*{variant}*: Variant of layout (e.g. "dvorak"). *{variant}*: Variant of layout (e.g. "dvorak").
*{flag}*: Country flag of layout.
# EXAMPLES # EXAMPLES
``` ```

View File

@ -99,7 +99,8 @@ auto Language::update() -> void {
fmt::arg("short", layout_.short_name), fmt::arg("short", layout_.short_name),
fmt::arg("shortDescription", layout_.short_description), 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),
fmt::arg("flag", layout_.country_flag())));
label_.set_markup(display_layout); label_.set_markup(display_layout);
if (tooltipEnabled()) { if (tooltipEnabled()) {
if (tooltip_format_ != "") { if (tooltip_format_ != "") {
@ -107,7 +108,8 @@ auto Language::update() -> void {
fmt::arg("short", layout_.short_name), fmt::arg("short", layout_.short_name),
fmt::arg("shortDescription", layout_.short_description), 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),
fmt::arg("flag", layout_.country_flag())));
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);
@ -212,4 +214,15 @@ Language::XKBContext::~XKBContext() {
rxkb_context_unref(context_); rxkb_context_unref(context_);
delete layout_; delete layout_;
} }
std::string Language::Layout::country_flag() const {
if (short_name.size() != 2) return "";
unsigned char result[] = "\xf0\x9f\x87\x00\xf0\x9f\x87\x00";
result[3] = short_name[0] + 0x45;
result[7] = short_name[1] + 0x45;
// Check if both emojis are in A-Z symbol bounds
if (result[3] < 0xa6 || result[3] > 0xbf) return "";
if (result[7] < 0xa6 || result[7] > 0xbf) return "";
return std::string{reinterpret_cast<char*>(result)};
}
} // namespace waybar::modules::sway } // namespace waybar::modules::sway