+TITLE: swaylayout

+BEGIN_QUOTE

Get the current Sway keyboard layout

+END_QUOTE

cargo install --git https://github.com/filalex77/swaylayout

+END_SRC

+BEGIN_EXAMPLE

$ swaymsg -t get_inputs

...

Input device: AT Translated Set 2 keyboard Type: Keyboard Identifier: 1:1:ATTranslatedSet2keyboard Product ID: 1 Vendor ID: 1 Active Keyboard Layout: English (US) Libinput Send Events: enabled

here it's 1:1:ATTranslatedSet2keyboard

+END_EXAMPLE

+BEGIN_EXAMPLE

$ swaylayout English (US)

+END_EXAMPLE

Listen to layout changes and output new layout on every change:

+BEGIN_EXAMPLE

$ swaylayout --listen

+END_EXAMPLE

Plugging that into waybar =.config/waybar/config=:

+BEGIN_SRC json

{ "modules-right": [ "custom/keyboard" ], "custom/keyboard": { "exec": "swaylayout --listen " } }

+END_SRC

| 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