X11 switching keyboard layouts
tl;dr
For myself:
sudo apt-get install fbxkb setxkbmap -option grp:switch,grp:shifts_toggle 'us,us(dvorak)'
Add to ~/.fluxbox/startup:
fbxkb &
The story
I learned that Xorg (if not all X11 implementations) provide input method switching built-in! You can change keyboard layouts with:
setxkbmap -layout us -variant basic
To switch to dvorak:
setxkbmap -layout us -variant dvorak
While researching in preparation for writing a tray icon utility to show/switch input methods, I learned that you can simply specify multiple input methods, and complex options such as switching between the two:
setxkbmap -option grp:switch,grp:shifts_toggle,grp_led:scroll 'us(basic),us(dvorak)'
See xkeyboard-config(7) for a list of options.
And in my research, I also learned that I don't need to write my own mktrayicon-powered one: Multiple already exist!
- xxkb (sourceforge) (less-dead github fork). You know an open-source project is old and probably abandoned if it's on sourceforge. It was cool before it went sour. (And it was cool before github was cool and has fallen now too.)
- gxkb (origin?) (github)
- ibus (github
- fbxkb (sourceforge) (in Debian sid)
Fbxkb was the closest to what I wanted visually, functionally, and source code-wise. Multiple sources of fbxkb source code exist, such as a few github places, the sourceforge (abandoned) upstream in svn which I don't use, and the Debian source tarball.
I did fork it to add some small steps I wanted:
- Display menu on left click, and increment input method on middle click
- Enable rotating input methods on scrollwheel scrolling action
- Add variant support, e.g., dvorak
- Add tooltip
Comments