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.

So, this is something I've been dreaming of for years now. I've sporadically foraged for a solution on Google but never really found anything. I was told once by someone on IRC that it's possible but never really seen how this could be done.

Here's what I want.

I use en and ru keyboard layouts as two primary languages of input that I work with on a daily basis. I use Shift+Caps_Lock to toggle these layouts. Sometimes I need to type in ua and pl, and I want to have them in a separate group of layouts that would be toggled by pressing say L_Win+Caps_Lock.

So, whenever I press L_Win+Caps_Lock I start cycling between ua and pl, and when I need to get back to my standard group of en and ru I would press Shift+Caps_Lock.

This description is in no way linked to any real understanding of how the existing keyboard layout switching framework works. It's just me imagining the ideal scenario.

Well, dear super users, can this be done on Linux? If yes, how?

share|improve this question
add comment

2 Answers

I made a little improvement for this script. Now it doesn't break WM keyboard switcher. It works a little different as TS wants but I think it is more convinient this way at least for me

You should change keyboard model and options if you want

#!/bin/sh
current=`setxkbmap -query | grep layout|cut  -d ',' -f 2`
if [ "$current" == 'pl' ]
then 
    notify-send -t 1500 -i keyboard "Keyboard layouts: EN / RU"
    setxkbmap -model logitech_base -layout en,ru -variant , -option grp:caps_toggle,compose:rwin
else 
    notify-send -t 1500 -i keyboard "Keyboard layouts: UA / PL"
    setxkbmap -model logitech_base -layout ua,pl -variant , -option grp:caps_toggle,compose:rwin
fi
share|improve this answer
    
It looks like you're never going to get out of EN/RU group, because once you're in UA/PL, you go into EN/RU and you're stuck there forever. PS: maybe not ;D –  ILIV May 15 '13 at 15:46
    
Well, I have CapsLock as a groop switcher. It switches between EN/RU. When I need UA/PL I run that script (mapped to CTRL+Caps) and use Caps to switch between UA/PL. Another Ctrl+Caps restore layouts to EN/RU. Actually I use it only for 3 langs: EN/RU and EN/UA groups. –  izbushka May 16 '13 at 11:19
add comment

The easiest way would probably be to use your window manager's keyboard layout switcher for your main layouts (en and ru) and then use the following script mapped to L_Win+Caps_Lock:

#!/bin/bash 

current=`setxkbmap -query | grep layout | fold -s2 | tail -n 1`
if [ "$current" == 'ua' ]
then
    setxkbmap -layout pl
else
    setxkbmap -layout ua
fi

If you save the script as toggle_layout.sh, make it executable and map it to your desired keybord shortcut using your window manager's tools, it should do what you need. The script just checks if you are currently using the ua layout and, if not, switches to pl.


UPDATE:

I got it to work in the following way:

  1. Map the script above to Ctrl+8 (that's keypad 8).
  2. Make another script to toggle between the main layouts:

    #!/bin/bash 
    
    current=`setxkbmap -query | grep layout | fold -s2 | tail -n 1`
    if [ "$current" == 'en' ]
    then
        setxkbmap -layout ru
    else
        setxkbmap -layout en
    fi
    
  3. Map the script from step 2 to Ctrl+2 (that's keypad 2).

Make sure you use keys that do not change when the layout changes (that's why I used the keypad in this example). I don't know if you can do this without breaking the WM native way of changing layouts but at least this should work.

share|improve this answer
    
Thanks for a quick reply. I'll give that a try. Nonetheless, I'm really curious if this can be done by simply configuring existing standard software (like xorg-xkbutils/GNOME). –  ILIV Nov 14 '12 at 15:26
    
@ILIV, AFAIK, it is not possible to set two different keyboard shortcuts for keyboard switching. All I am using here is the standard setxkbmap. I doubt you can get it any simpler than that. –  terdon Nov 14 '12 at 15:38
    
Yep, it's a pretty good solution -- that I have to test yet lol -- and I'm almost ashamed that I didn't think of that myself! I was just too focused on doing it by configuring xkbutils/DE. I'm actually so excited that you responded, because if this works well this is a dream come true :P –  ILIV Nov 14 '12 at 15:54
    
Here's the problem with your approach. Once I run setxkbmap in terminal, I lose any keyboard layouts but one that I passed as an argument to -layout option. –  ILIV Nov 14 '12 at 16:17
    
@ILIV, you're quite right, it seems to break the WM's native method of changing layouts. See my updated answer for a workaround. It works fine on my LMDE machine when switching between el,es,en and ua. –  terdon Nov 14 '12 at 17:22
show 2 more comments

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.