LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 02-14-2010, 12:12 PM   #1
alexbrui
LQ Newbie
 
Registered: Nov 2009
Location: Ukraine
Distribution: Slackware 13.37
Posts: 27

Rep: Reputation: 0
Non cyclic switching between keyboard layouts


Hi all.

I have three keyboard layouts: en, ru and ua. Now I switch between layouts by pressing Ctrl+Shift (en->ru->ua->en->ru...). Here is part of my xorg.conf
Code:
Option "XkbRules"	"xorg"
Option "XkbModel"	"pc101"
Option "XkbLayout"	"us,ru,ua(winkeys)"
Option "XkbOptions"     "grp:ctrl_shift_toggle,lv3:none,ctrl:caps,grp_led:scroll,caps:internal,compose:ralt"
I want to setup non cyclic switching with next sheme:
CapsLock - switch to en
CapsLock+Shift - switch to ru
CapsLock+Ctrl - switch to ua

I've read an xkb manuals and some articles about it but can't understand how I can setup xkb for non cyclic switching. Can anyone help me?
 
Old 02-15-2010, 08:13 AM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946
I'm not sure if it can be done with any regular keyboard mapping tool. The standard X switching mechanism seems to be a simple rotate.

It appears, however, that you can instead use one of the input method frameworks, uim or scim, to work with languages that have different keboard mappings, and these can be configured with separate shortcuts for each layout. I've never personally tried either of them for languages like that though.

See here for more on Linux language support.

http://www.jw-stumpel.nl/stestu.html
 
Old 02-15-2010, 08:26 AM   #3
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Wheezy (Fluxbox WM)
Posts: 1,363
Blog Entries: 52

Rep: Reputation: 353Reputation: 353Reputation: 353Reputation: 353
Here is one way to do it, which involves hacking the files in /usr/share/X11/xkb (alternatively you could set up your own keymap files). This is to select four keyboard layouts, but it will work for three.

First, add in a CapsLock selector type to the default xkb_types section in xkb/types/extra (this will be used to allow the CapsLock to select up to 4 different actions)
Code:
    type "FOUR_LEVEL_CAPS" {
        modifiers = Shift+Control;
	map[None] = Level1;
	map[Shift] = Level2;
	map[Control] = Level3;
	map[Shift+Control] = Level4;
	level_name[Level1] = "Base";
	level_name[Level2] = "Shift";
	level_name[Level3] = "Ctrl";  
	level_name[Level4] = "Shift Ctrl";  
    };
Then add in group set actions to the default xkb_compatibility section in xkb/compat/iso9995 (reinterpreting these somewhat so that they set a fixed group number)
Code:
    interpret ISO_First_Group_Lock {
	action= LockGroup(group=1);
    };
    interpret ISO_Prev_Group_Lock {
	action= LockGroup(group=2);
    };
    interpret ISO_Next_Group_Lock {
	action= LockGroup(group=3);
    };
    interpret ISO_Last_Group_Lock {
	action= LockGroup(group=4);
    };
Then add in the switch map to xkb/symbols/group
Code:
partial modifier_keys
xkb_symbols "shift_ctrl_caps_switch" {
    key <CAPS> { type = "FOUR_LEVEL_CAPS", [ ISO_First_Group_Lock, ISO_Prev_Group_Lock, ISO_Next_Group_Lock, ISO_Last_Group_Lock ] };
};
Now add in the group command to the option symbols in xkb/rules/base
Code:
  grp:shift_ctrl_caps_switch = +group(shift_ctrl_caps_switch)
Then you can set up your xorg.conf to make use of the new group change option, and restart X.

The four layouts are selected using 'capslock', 'shift-capslock', 'ctrl-capslock', and 'shift-ctrl-capslock' (as defined in the switch map).

Last edited by neonsignal; 02-15-2010 at 08:29 AM.
 
1 members found this post helpful.
Old 02-15-2010, 11:32 AM   #4
alexbrui
LQ Newbie
 
Registered: Nov 2009
Location: Ukraine
Distribution: Slackware 13.37
Posts: 27

Original Poster
Rep: Reputation: 0
Many thanks, neonsignal! This is what I need.
But I have a small problem with this. When I switch first layout by pressing CapsLock it switches correctly, then I press CapsLock+Shift to switch to the second layout and it switches correctly too. But when I press CapsLock again I get third layout instead of first. When I switch from third layot to first all works fine.
This is because I have only three layouts I'm right?
 
Old 02-15-2010, 04:07 PM   #5
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Wheezy (Fluxbox WM)
Posts: 1,363
Blog Entries: 52

Rep: Reputation: 353Reputation: 353Reputation: 353Reputation: 353
Quote:
But I have a small problem with this. When I switch first layout by pressing CapsLock it switches correctly, then I press CapsLock+Shift to switch to the second layout and it switches correctly too. But when I press CapsLock again I get third layout instead of first.
It isn't because of only three layouts (I tested that case). It is more likely to be a problem with the "FOUR_LEVEL_CAPS" not being right, or not getting loaded. The way to test this is to see if ctrl-CapsLock is working.

I'm assuming that you didn't make any changes to the above. It would be worth looking at the Xorg log to see if there were any errors (these may also appear on the ctrl-alt-F1 terminal window).

Last edited by neonsignal; 02-15-2010 at 09:25 PM.
 
Old 02-15-2010, 09:05 PM   #6
lumak
Member
 
Registered: Aug 2008
Location: Phoenix
Distribution: Arch
Posts: 799
Blog Entries: 32

Rep: Reputation: 109Reputation: 109
... If you work only in GUI, then why can't you just bind "setxkbmap en" "setxkbmap ru" and "setxkbmap ua" to any key combo you want?
 
Old 02-16-2010, 11:39 AM   #7
alexbrui
LQ Newbie
 
Registered: Nov 2009
Location: Ukraine
Distribution: Slackware 13.37
Posts: 27

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by neonsignal View Post
It isn't because of only three layouts (I tested that case). It is more likely to be a problem with the "FOUR_LEVEL_CAPS" not being right, or not getting loaded. The way to test this is to see if ctrl-CapsLock is working.
Ctrl+CapsLock is working, I can switch to third layout.
Switching from first to second layout works. Switching from first to third and from third to first works too.
When I switch from second layout to first I get third layout and need to press CapsLock again to perform switching.

Quote:
Originally Posted by neonsignal View Post
I'm assuming that you didn't make any changes to the above. It would be worth looking at the Xorg log to see if there were any errors (these may also appear on the ctrl-alt-F1 terminal window).
I made changes in xkb files as you tell. When I discover this problem I check my changes twice and seems all edits are correct. Here is files with my edits.
Also I've look in Xorg.log and as I can see there are no errors related to the keyboard

Xorg log: http://www.4shared.com/file/22332535.../Xorg0log.html
xkb files with edits: http://www.4shared.com/file/22332503...ed/xkbtar.html
 
Old 02-16-2010, 07:54 PM   #8
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Wheezy (Fluxbox WM)
Posts: 1,363
Blog Entries: 52

Rep: Reputation: 353Reputation: 353Reputation: 353Reputation: 353
Quote:
Ctrl+CapsLock is working, I can switch to third layout. Switching from first to second layout works. Switching from first to third and from third to first works too.
When I switch from second layout to first I get third layout and need to press CapsLock again to perform switching.
I've been able to replicate the problem. On my system, running setxkbmap after X windows starts (even without any parameters) fixes the problem (ie, CapsLock switches back to the first layout immediately).

This explains why I didn't see it earlier, because I was running setxkbmap to try out different combinations.

I don't know why setxkbmap would make a difference. My guess is that the setup order must be slightly different when X windows first starts, and something else is adding a definition to the capslock.

==EDIT==

Looking at the keymap (using xkbcomp) after X windows starts, CAPS is set to:
Code:
    key <CAPS> {
        type[group1]= "FOUR_LEVEL_CAPS",
        symbols[Group1]= [ ISO_First_Group_Lock, ISO_Prev_Group_Lock, ISO_Next_Group_Lock, ISO_Last_Group_Lock ],
        symbols[Group2]= [ ISO_Next_Group_Lock, ISO_Last_Group_Lock ]
    };
Which makes it look like the first group is wrapping into the second (perhaps because it was originally allocated only 2 entries by the pc keymap?). Running setxkbmap changes this to the way it should be:
[CODE]
Code:
    key <CAPS> {
        type[group1]= "FOUR_LEVEL_CAPS",
        symbols[Group1]= [ ISO_First_Group_Lock, ISO_Prev_Group_Lock, ISO_Next_Group_Lock, ISO_Last_Group_Lock ]
    };

Last edited by neonsignal; 02-16-2010 at 09:28 PM.
 
1 members found this post helpful.
Old 02-17-2010, 12:54 AM   #9
alexbrui
LQ Newbie
 
Registered: Nov 2009
Location: Ukraine
Distribution: Slackware 13.37
Posts: 27

Original Poster
Rep: Reputation: 0
Many thanks neonsignal!
Now all works and my understanding was much better
 
  


Reply

Tags
keyboard, layout, linux, xkb


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Switching between keyboard layouts ganick Red Hat 2 12-18-2008 01:41 PM
switching between keyboard layouts trawler Linux - Software 1 10-22-2005 06:51 AM
Switching keyboard layouts jrdioko Linux - General 0 10-24-2004 02:07 PM
Switching between keyboard layouts ??? GloVe Linux - General 1 10-13-2003 10:26 AM
switching keyboard layouts linuxfond Linux - Newbie 1 05-28-2003 10:04 PM


All times are GMT -5. The time now is 07:02 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration