A lightweight utility that monitors keyboard state on Wayland compositors. It reports keyboard layout changes and lock key states (Caps Lock, Num Lock, Scroll Lock) in real-time.
Tested on labwc.
libwayland-client- Wayland client librarylibxkbcommon- XKB keyboard handling librarylibxkbregistry- XKB registry for layout lookup (part of libxkbcommon)
wayland-protocols- Wayland protocol XML fileswayland-scanner- Wayland protocol code generatorcurl- For downloading wlr-layer-shell protocol
When these optional dependencies are available, xkb-monitor uses wlr-layer-shell to query the current keyboard layout on startup. Without them, the initial layout may default to index 0 until a key is pressed.
# Required
sudo apt install libwayland-dev libxkbcommon-dev
# Optional (for accurate initial layout)
sudo apt install wayland-protocols curl# Required
sudo pacman -S wayland libxkbcommon
# Optional (for accurate initial layout)
sudo pacman -S wayland-protocols curlmakeThis will automatically detect if wayland-protocols and wayland-scanner are
available. If found, the build will:
- Generate xdg-shell protocol files from wayland-protocols
- Download and generate wlr-layer-shell protocol files
- Enable accurate initial layout reporting
To explicitly disable layer-shell support even when dependencies are available:
make SKIP_WLR_LAYER_SHELL=1For a debug build with address sanitizer:
make debugTo clean generated protocol files:
make distcleanBuild, then Copy the binary to a directory in your $PATH:
make
sudo cp xkb-monitor /usr/local/bin/xkb-monitor # CSV output
xkb-monitor -j # JSON output
xkb-monitor -n # Name only (layout changes only)
xkb-monitor -jn # JSON name only (Waybar compatible)CSV (default):
index,description,name,variant,caps,num,scroll
0,English (US),us,,0,0,0
1,Greek,gr,,0,0,0
JSON (xkb-monitor -j):
{"index":0,"description":"English (US)","name":"us","variant":"","caps":false,"num":false,"scroll":false}
{"index":1,"description":"Greek","name":"gr","variant":"","caps":false,"num":false,"scroll":false}Name only (xkb-monitor -n):
us
gr
Name only - JSON (xkb-monitor -jn):
{"text":"us"}
{"text":"gr"}
Add to your Waybar config:
// Alternative: modules-center, or modules-left
"modules-right": [
...
"custom/keyboard-layout",
...
],
"custom/keyboard": {
"exec": "xkb-monitor -n",
"format": "⌨ {}"
}To process the output (ie., running sed etc), make sure the tool does not
buffer stdout. For example, use sed -u:
"custom/keyboard-layout": {
"exec": "xkb-monitor -n | sed -u 's/us/e/; s/gr/λ/'",
"format": "⌨ {}"
}MIT