mirror of
				https://github.com/rad4day/Waybar.git
				synced 2025-11-04 01:32:42 +01:00 
			
		
		
		
	Merge pull request #1229 from kraftwerk28/sway-language-country-flag
`sway/language` country flag
This commit is contained in:
		@@ -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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user