Get the current Sway keyboard layout
For now:
cargo install --git https://github.com/filalex77/swaylayout
Get the identifier of your keyboard, e.g.
$ swaymsg -t get_inputs # ... Input device: AT Translated Set 2 keyboard Type: Keyboard Identifier: 1:1:AT_Translated_Set_2_keyboard Product ID: 1 Vendor ID: 1 Active Keyboard Layout: English (US) Libinput Send Events: enabled # here it's 1:1:AT_Translated_Set_2_keyboard
Just get the current layout:
$ swaylayout <ID> English (US)
Listen to layout changes and output new layout on every change:
$ swaylayout --listen <ID>
Plugging that into waybar .config/waybar/config
:
{
"modules-right": [
"custom/keyboard"
],
"custom/keyboard": {
"exec": "swaylayout --listen <ID>"
}
}
This unscientific benchmark:
Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
---|---|---|---|---|
swaylayout | 0.5 ± 0.2 | 0.4 | 1.7 | 1.00 |
pipe swaymsg into jq | 28.8 ± 2.1 | 26.6 | 35.9 | 52.85 ± 15.14 |
e.g. 36-68x times faster than the naive solution
Unlikely, but appreciated.
MIT, because who cares.