2 and more keyboard layout groups in Linux changed by different hot keys

wettstein509 at solnet.ch wettstein509 at solnet.ch
Thu Nov 15 11:47:44 PST 2012


> So, whenever I press L_Win+Caps_Lock I start cycling through ua and pl
> (possibly more layouts), and when I need to get back to my standard group
> of en and ru I would press Shift+Caps_Lock to start typing in en (assuming
> it's always the default layout in this group)

To summarise my understanding of your request: You want to use one key
combination to switch between two sets of layouts, and another key
combination to switch between the two layouts within a set.  This is
possible with the standard keyboard facilities.  However, four layouts
total is the maximum (one can have more by not using just groups but
also overlays or layouts with many levels, but that is a lot of work).

> So, ideally a solution would have to be friendly for this desktop
> environment and not break anything in it :D

You have to customise beyond Gnome's abilities, but when you have
created the customised layout and found a activate it, it should work
with Gnome applications.

Start by configuring (in Gnome) your keymap with the four layouts, in
such an order that layouts from different sets alternate.  So one set is
put in even positions, and one in odd positions.  When we cycle trough
the list of four layouts is steps of one, we alternate between sets.
When we cycle in steps of two, we alternate between layouts within a
set.  It also would be possible to switch between layouts going to
always the first layout in the other set, with slightly more effort.

When you four-layout keymap is done and active, dump it into a file to:

  xkbcomp :0 mylayout.xkb

This assumes your display is :0.

You have now to edit mylayout.xkb.  In this file, you find a section
called xkb_types.  Towards the end of this section, add:

    type "THREE_LEVEL_SUPER" {
        modifiers= Shift+Super;
        map[Shift]= Level2;
        map[Super]= Level3;
        level_name[Level1]= "Base";
        level_name[Level2]= "Shift";
        level_name[Level3]= "Super";
    };

I assume here that your left windows key is configured as Super key.

Then search for <CAPS>.  If you have configured Shift+Caps for
switching, you will find something similar to this:

    key <CAPS> {        [  Caps_Lock,           ISO_Next_Group  ]       };

Replace this by:

    key <CAPS> {
        type= "THREE_LEVEL_SUPER",
        repeat= No,
        symbols[Group1]= [              Caps_Lock, ISO_Next_Group, ISO_Next_Group ],
	actions[Group1]= [ LockMods(modifiers=Lock), LockGroup(group=+2), LockGroup(group=+1) ]
    };

If switching between sets should bring you always to the first layout of
the other set, instead replace it by:

    key <CAPS> {
        type= "THREE_LEVEL_SUPER",
        repeat= No,
        symbols[Group1]= [              Caps_Lock, ISO_Next_Group, ISO_Next_Group ],
	actions[Group1]= [ LockMods(modifiers=Lock), LockGroup(group=+2), LockGroup(group=2) ],
        symbols[Group2]= [              Caps_Lock, ISO_Next_Group, ISO_Next_Group ],
	actions[Group2]= [ LockMods(modifiers=Lock), LockGroup(group=+2), LockGroup(group=1) ],
        symbols[Group3]= [              Caps_Lock, ISO_Next_Group, ISO_Next_Group ],
	actions[Group3]= [ LockMods(modifiers=Lock), LockGroup(group=+2), LockGroup(group=2) ],
        symbols[Group4]= [              Caps_Lock, ISO_Next_Group, ISO_Next_Group ],
	actions[Group4]= [ LockMods(modifiers=Lock), LockGroup(group=+2), LockGroup(group=1) ]
    };

To activate your customised layout, load it up to the server:

  xkbcomp mylayout.xkb :0

Now your desired setup should work.  How to best activate it
automatically at the beginning of the Gnome session, I do not know.
Maybe you can but the above line in a little script, and run this script
as a start-up program.  This would only work if Gnome runs it after it
sets the keyboard layout.  Maybe someone else knows more about this.







More information about the xorg mailing list