1
0
Fork 0
mirror of https://github.com/Zedfrigg/ironbar.git synced 2025-09-16 03:36:58 +02:00

feat: support glob patterns for keyboard layout icons (#949)

* Simplistic globbing for matching keyboard layout icons

Update the logic for determining the display text for the current keyboard layout.
Instead of a direct map lookup, iterate through the layout map to support wildcard matching.

Patterns ending with `*` will match any language string starting with the characters before the `*`. This allows grouping similar layouts (e.g., `English`, `English (Colemak-DH ISO)`) under a single pattern like `English*`.

* Use `IndexMap` instead of `HashMap` for keyboard layout icons map

This enables users to choose which globs to prioritize via ordering in the config

* Enable feature `serde` for `indexmap`

* Document wildcard matching for keyboard layouts

* Enable `indexmap2` feature flag for `schemars`

* Add missing period

* use string slices

* Fix formatting
This commit is contained in:
Alan 2025-07-21 00:19:58 +03:00 committed by GitHub
commit 5520562a18
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 21 additions and 8 deletions

View file

@ -1,8 +1,7 @@
use std::collections::HashMap;
use color_eyre::Result;
use color_eyre::eyre::Report;
use gtk::prelude::*;
use indexmap::IndexMap;
use serde::Deserialize;
use tokio::sync::mpsc;
use tracing::{debug, trace};
@ -129,7 +128,7 @@ struct Icons {
/// }
/// ```
#[serde(default)]
layout_map: HashMap<String, String>,
layout_map: IndexMap<String, String>,
}
impl Default for Icons {
@ -141,7 +140,7 @@ impl Default for Icons {
num_off: String::new(),
scroll_on: default_icon_scroll(),
scroll_off: String::new(),
layout_map: HashMap::new(),
layout_map: IndexMap::new(),
}
}
}
@ -338,7 +337,19 @@ impl Module<gtk::Box> for KeyboardModule {
}
}
KeyboardUpdate::Layout(KeyboardLayoutUpdate(language)) => {
let text = icons.layout_map.get(&language).unwrap_or(&language);
let text = icons
.layout_map
.iter()
.find_map(|(pattern, display_text)| {
let is_match = if pattern.ends_with("*") {
language.starts_with(&pattern[..pattern.len() - 1])
} else {
pattern == &language
};
is_match.then(|| display_text)
})
.unwrap_or(&language);
layout_button.set_label(text);
}
});