Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I use awesome as a window manager under gnome (debian system) and I made a widget to switch keyboard layout by this code:

-- Keyboard map indicator and changer
    kbdcfg = {}
    kbdcfg.cmd = "setxkbmap"
    kbdcfg.layout = { { "us", "" }, { "ru", "phonetic" } }
    kbdcfg.current = 1  -- us is our default layout
    kbdcfg.widget = widget({ type = "textbox", align = "right" })
    kbdcfg.widget.text = " " .. kbdcfg.layout[kbdcfg.current][1] .. " "
    kbdcfg.switch = function ()
       kbdcfg.current = kbdcfg.current % #(kbdcfg.layout) + 1
       local t = kbdcfg.layout[kbdcfg.current]
       kbdcfg.widget.text = " " .. t[1] .. " "
       os.execute( kbdcfg.cmd .. " " .. t[1] .. " " .. t[2] )
    end

    -- Mouse bindings
    kbdcfg.widget:buttons(awful.util.table.join(
        awful.button({ }, 1, function () kbdcfg.switch() end)
    ))
-- Alt + Right Shift switches the current keyboard layout
    awful.key({ "Mod1" }, "Shift_R", function () kbdcfg.switch() end),

It works, however there is a serious problem with keyboard behavior. When I switch to ru layout non of my keyboard bindings works. Awesome bindings don't work. For example vim shortcuts don't also work and etc. How I can solve this problem?

share|improve this question
add comment

2 Answers

About AwesomeWM, from its FAQ:

You should use keycodes, instead of keynames, like this:

  1. Run xev.
  2. Press "Print" key.
  3. Read the output

    KeyPress event, serial 34, synthetic NO, window 0x1200002,
    root 0x291, subw 0x0, time 1510129, (471,293), root:(472,316),
    state 0x0, keycode **107** (keysym 0xff61, Print), same_screen YES,
    ...
    
  4. Create ~/screenshots, install scrot and add the following to rc.lua:

    awful.key({ }, "#107", function () awful.util.spawn("scrot -e 'mv $f ~/screenshots/ 2>/dev/null'") end),
    

Now you may test, that you can create screenshots with any keyboard layout.

share|improve this answer
    
That's just a working example. The point is to use keycodes –  vasyabelkin Jul 2 '13 at 19:21
add comment

Your keyboard bindings are not working because your keyboard no longer has those keysyms.

If you want to have, for example, Alt+F do something, then you need "F" in some key. But if you load "ru" alone, then there is no "F" at all (nor any latin letter).

I think, specially when you need to handle multiple layouts, that it is much better to let X11 (through setxkbmap) do the job for you; the way the window managers do it is much more limited as you have discovered.

You may also try, as the awfull widget seems to call setxkbmap, to change "ru" with "ru,us", eg:

kbdcfg.layout = { { "us", "" }, { "ru,us", "phonetic" } }

that way, the "us" layout will be stacked on top of the "ru" one when loaded, and the keysysms of the "us" layout, while still not directly typeable, will be seen by the X11 layer that handles the key bindings.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.