mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
Merge pull request #1229 from kraftwerk28/sway-language-country-flag
`sway/language` country flag
This commit is contained in:
commit
7069429c03
@ -32,6 +32,7 @@ class Language : public ALabel, public sigc::trackable {
|
||||
std::string short_name;
|
||||
std::string variant;
|
||||
std::string short_description;
|
||||
std::string country_flag() const;
|
||||
};
|
||||
|
||||
class XKBContext {
|
||||
|
@ -37,6 +37,8 @@ Addressed by *sway/language*
|
||||
|
||||
*{variant}*: Variant of layout (e.g. "dvorak").
|
||||
|
||||
*{flag}*: Country flag of layout.
|
||||
|
||||
# EXAMPLES
|
||||
|
||||
```
|
||||
|
@ -99,7 +99,8 @@ auto Language::update() -> void {
|
||||
fmt::arg("short", layout_.short_name),
|
||||
fmt::arg("shortDescription", layout_.short_description),
|
||||
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);
|
||||
if (tooltipEnabled()) {
|
||||
if (tooltip_format_ != "") {
|
||||
@ -107,7 +108,8 @@ auto Language::update() -> void {
|
||||
fmt::arg("short", layout_.short_name),
|
||||
fmt::arg("shortDescription", layout_.short_description),
|
||||
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);
|
||||
} else {
|
||||
label_.set_tooltip_markup(display_layout);
|
||||
@ -212,4 +214,15 @@ Language::XKBContext::~XKBContext() {
|
||||
rxkb_context_unref(context_);
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user