Keyboard layouts with kbdd

= Awesome 3 and kbdd =

kbdd stands for  k ey b oar d d aemon. It is a simple daemon, which is designed to be run in X11 session and remember keyboard layouts on a per-window basis. That's very useful if don't want to switch layouts back and forth, while typing in terminals (probably mostly in English layouts) and some kind of chat (Greek, for example). Another useful thing about it is D-Bus notification support (optional) — it can emit signals on layout change, thus making it possible to create a indicator widget.

First, head over to kbdd homepage and install latest version (chances to find it in repos are low). Gentoo users are advised to use rion overlay.

Make sure you've configured your Xorg server properly, kbdd uses its settings. Run kbdd executable and behold its unbelievable greatness in layout remembering!

Next thing is to create Awesome widget:

-- Keyboard layout widget kbdwidget = widget({type = "textbox", name = "kbdwidget"}) kbdwidget.border_width = 1 kbdwidget.border_color = beautiful.fg_normal kbdwidget.text = " Eng "

Awesome 3.5+ version: -- Keyboard layout widget kbdwidget = wibox.widget.textbox(" Eng ") kbdwidget.border_width = 1 kbdwidget.border_color = beautiful.fg_normal kbdwidget:set_text(" Eng ")

…place it where you want and make it listen to D-Bus events:

dbus.request_name("session", "ru.gentoo.kbdd") dbus.add_match("session", "interface='ru.gentoo.kbdd',member='layoutChanged'") dbus.add_signal("ru.gentoo.kbdd", function(...)   local data = {...}    local layout = data[2]    lts = {[0] = "Eng", [1] = "Рус"}    kbdwidget.text = " "..lts[layout].." "    end )

Awesome 3.5+ version: kbdstrings = {[0] = " Eng ", [1] = " Рус "}

dbus.request_name("session", "ru.gentoo.kbdd") dbus.add_match("session", "interface='ru.gentoo.kbdd',member='layoutChanged'") dbus.connect_signal("ru.gentoo.kbdd", function(...)   local data = {...}    local layout = data[2]    kbdwidget:set_markup(kbdstrings[layout])    end )

In this example the first layout (numbered "0") is English and therefore indicated as "Eng", and the second one is Russian ("1", "Рус"). Adjust it as you need: you could play with background and foreground colours, display images instead of boring letters and so on.

That's simplest example. See kbdd wiki and manpage for details regarding D-Bus methods and other features.

Advanced layout managing and prettier widget
Here's much more complex example of kbdd-powered widget with background images and layout selection menu written by Mellon. * Left mouse click switches two most recent layouts. * Middle click switches to next layout. * Right click opens menu. Widget state is changed by kbdd D-BUS signals, layouts are switched by calling kbdd D-BUS methods. Code is subject to changes, so look into example here and make sure you've checked most recent version at GoogleCode.



kbd.lua --

--

-- rc.lua --

-- Add widgets to the wibox - order matters mywibox[s].widgets = { --    ...        s == 1 and kbdwidget or nil, --    ...    }

-- My keybindings globalkeys = awful.util.table.join(globalkeys,   awful.key({ modkey, "Mod1"    }, "1",     function  os.execute(kbd_dbus_sw_cmd .. "0") end),    awful.key({ modkey, "Mod1"    }, "2",     function  os.execute(kbd_dbus_sw_cmd .. "1") end),    awful.key({ modkey, "Mod1"    }, "3",     function  os.execute(kbd_dbus_sw_cmd .. "2") end),    awful.key({ modkey, "Mod1"    }, "4",     function  os.execute(kbd_dbus_sw_cmd .. "3") end),    awful.key({  "Control"  }, "ISO_Level3_Shift",     function  os.execute(kbd_dbus_prev_cmd) end) )

Icons used are translatoid's (translator plasmoid using google translator).