Keyboard Layout Indicator and Switcher for Waybar (No Polling, No Extra Packages and Dependencies) #3354
Replies: 3 comments 1 reply
-
|
Update: I've replaced the old polling-based method with a cleaner solution: No polling To switch from periodic polling to a pure signal-driven approach, simply change the interval value in your custom/layout module from 1 to "once": To keep the layout indicator instantly up to date on window focus changes, configure the "wlr/taskbar" module to emit a refresh signal: Since Waybar receives taskbar updates on every focus/activation event, this hook triggers a signal-based refresh of the "custom/layout" module — eliminating the need for polling entirely. At this point we have: The final piece is keyboard-driven layout switching with instant visual feedback. Configure a keybinding in ~/.config/labwc/rc.xml: Important: Avoid using Shift as part of the keybinding (e.g., Shift+Space). Labwc currently has known issues handling Shift-based bindings for layout switching . Instead, choose any other modifier combination — W-Space (Super+Space), A-Space (Alt+Space), or even CapsLock remapped via xkb work reliably. Pressing the bound shortcut now: |
Beta Was this translation helpful? Give feedback.
-
|
This is the very old polling hack which works only for 2 layouts unfortunately. Yesterday https://github.com/drougas/xkb-monitor came out and it's working fine, just |
Beta Was this translation helpful? Give feedback.
-
|
I created a script kb-eng that forces the English keyboard layout on launch. It can be automatically triggered for specific applications via window rules in ~/.config/labwc/rc.xm |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Set the grp_led:scroll XKB option in your environment file. For example:
This option lets us programmatically detect the current layout by reading 0 or 1 from /sys/class/leds/input*::scrolllock/brightness. Since sysfs files don't reliably trigger inotify events, we use polling—periodically reading the file—to track changes. We'll write a helper script named kb-layout that maps these values to short layout codes (e.g., en/ru) for display in Waybar.
Next, add a custom/layout module to your Waybar configuration under "modules-right":
"modules-right": ["custom/layout", ...]Configure the module as follows:
Make sure to define the #custom-layout selector in your Waybar CSS configuration.
The layout module now shows the active keyboard layout. Refreshing once per second via lightweight polling, it adds virtually zero overhead to the system.
We can enhance the module to update instantly on click—both via signal and polling—eliminating the 1‑second delay:
For cleaner configuration, extract the layout-switching command into a dedicated script. This script will toggle the keyboard layout and instantly refresh the Waybar indicator:
Save it as kb-toggle and make it executable. Then simplify the Waybar module configuration:
Beta Was this translation helpful? Give feedback.
All reactions