#+TITLE: swaylayout #+BEGIN_QUOTE Get the current Sway keyboard layout #+END_QUOTE * Table of contents :TOC_2: - [[#installation][Installation]] - [[#prerequisites][Prerequisites]] - [[#usage][Usage]] - [[#raison-dêtre][Raison d'être]] - [[#contributing][Contributing]] - [[#license][License]] * Installation For now: #+BEGIN_SRC sh cargo install --git https://github.com/filalex77/swaylayout #+END_SRC * Prerequisites Get the identifier of your keyboard, e.g. #+BEGIN_EXAMPLE $ 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 #+END_EXAMPLE * Usage Just get the current layout: #+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 * Raison d'être 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 * Contributing Unlikely, but appreciated. * License MIT, because who cares.