CLI keyboard layout switcher for X11
I wrote this one (using the code of xxkb) to allow switching keyboard layouts with individual hotkeys. For example:
# assume we have two layouts configured
$ setxkbmap -layout "en, ua"
# switch to Ukrainian first
$ xkbswitch 1
# switch to English back
$ xkbswitch 0
You could bind these to hotkeys within you window manager and every time you press the hotkey you know which layout is the current one. This also allows to use non-standard hotkeys to switch layouts.
<!-- Ctrl+Shift+1 switches to English -->
<keybind key="C-S-1">
<action name="Execute">
<command>xkbswitch 0</command>
</action>
</keybind>
<!-- Ctrl+Shift+2 switches to Ukrainian -->
<keybind key="C-S-2">
<action name="Execute">
<command>xkbswitch 1</command>
</action>
</keybind>
-- {{{ Key bindings
globalkeys = awful.util.table.join(
....
awful.key({ "Control", "Shift" }, "1", function() os.execute("xkbswitch 0") end),
awful.key({ "Control", "Shift" }, "2", function() os.execute("xkbswitch 1") end),
....
)
Or you could ensure same layout every time you run a certain program. Example for OpenBox again:
<!-- I want to have input lang set to English when locking my screen -->
<keybind key="W-L">
<action name="Execute">
<command>sh -c 'xkbswitch 0; slimlock'</command>
</action>
</keybind>
The only dependency is libX11.
$ cc -lX11 xkbswitch.c