Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I've been using plain XMonad for some time (not combined with KDE/GNome). Currently, I'm switching between keyboard layouts simply by a key combination globally:

[ ((modMask , xK_Scroll_Lock ),
    spawn "setxkbmap -layout us ; xmodmap ~/.Xmodmap")
, ((modMask .|. shiftMask, xK_Scroll_Lock),
    spawn "setxkbmap -layout cz ; xmodmap ~/.Xmodmap") ]

However that's a bit inconvenient. For many windows (i.e. browser, terminal) I need to keep the US layout most of the time. I need the localized layout only for text editors in 99% of cases. And I switch windows/workspaces a lot, so I have to switch the layouts manually almost every time I switch.

Ideally I'd like to achieve:

  • By pressing the key combination I set some kind of flag for the currently focused window.
  • XMonad calls the spawn commands automatically according to the flags when window focus changes.

How to do that (if it's possible)? Thanks for help.

(Bonus: Manage the flags externally by some kind of command from scripts.)

share|improve this question

2 Answers 2

You may want to have a look at scim and/or ibus. Both daemons can be started in an .Xsession. From my experience, ibus is the way to go, but might not have support for your input method.

An example configuration is documented for xfce.

Disclaimer: I would have added this as a comment, rather then an answer.

share|improve this answer

Install kbdd daemon which does the job.

Run this at startup:

kbdd
setxkbmap "us,ua" -option grp:scroll_toggle

That's all!

To display your layout in a widget you can find this Ruby code useful:

  interface = 'ru.gentoo.KbddService'
  member = 'layoutChanged'
  mon = open "| dbus-monitor --monitor \"sender='#{interface}',member='#{member}'\""
  loop do
    str = mon.gets
    if str =~ /layoutChanged/
      lang = mon.gets[/.\Z/] # lang is now either 0 or 1 depending on the current layout
    end
  end
share|improve this answer

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.