Reputation: 1478
I used to switch keyboard layout pressing ❖ win+spacebar on Windows 8, and ⌘+spacebar on OS X.
However, on Linux I have ❖ win key dedicated to XMonad as modificator key. So, to switch between layouts I have to use alt+⇧ shift.
This was not a problem until I've installed Emacs. Now I'm able to use all meta+shift key combinations, because I have alt as meta (⎋ escape could help, but it's very unhandy).
I think the easiest workaround for this case is to configure ❖ win+space to layout switch combination. Though XMonad by default use this combination to switching layouts, I rarely cycle layouts in both direction, so I will happy to have ❖ win+space for switching keyboard layout, and ❖ win+shift+space to switch XMonad layout. If I could make such configuration I will be able to use alt key as meta in Emacs.
However, I don't know how to make XMonad to use ❖ win+space as keyboard switch combination, being more preciese I don't know is it even possible.
Upvotes: 2
Views: 4626
Reputation: 4029
I was able to accomplish this with a shell (zsh) script saved on my path as cycle-keyboard-layout:
#!/usr/bin/env zsh
total_layouts="${#@}"
current_layout=$(setxkbmap -query | awk '/layout:/{ print $2 }')
current_index="${@[(i)$current_layout]}"
next_index="$((current_index % total_layouts + 1))"
next_layout="${@[$next_index]}"
setxkbmap "$next_layout"
Then, in my xmonad.hs I include:
import XMonad.Util.CustomKeys (customKeys)
altMask = mod1Mask
main =
xmonad $ defaultConfig
{ keys = customKeys delkeys inskeys
, modMask = mod4Mask
}
inskeys :: XConfig l -> [((KeyMask, KeySym), X ())]
inskeys conf@XConfig {modMask = modMask} =
[ -- modMask + alt + space
, ((modMask .|. altMask, xK_space),
spawn "cycle-keyboard-layout dvorak us")
]
delkeys :: XConfig l -> [(KeyMask, KeySym)]
delkeys XConfig {} = []
And now ⌘+alt+spacebar (I use ⌘+spacebar for other things) switches my layout between dvorak and us qwerty. To use other layouts, just replace dvorak us
with a space separated list of layouts which can be set with setxkbmap layout
.
My full bare bones xmonad.hs is at https://github.com/schlueter/xmonad-config/blob/master/xmonad.hs.
Upvotes: 2
Reputation: 745
All you've got to do is unbind Win-Space
(using removeKeys
), and create bindings for xmonad-layout switching and keyboard-layout switching (using additionalKeys
or additionalKeysP
).
Details and examples in the documentation.
The keyboard-layout switching command can be launched by using spawn
from the Core library.
Upvotes: 1