Difference between revisions of "Configuring keyboard layouts in X"

From ArchWiki
Jump to: navigation, search
m (Xkb moved to Configuring keyboard layouts in X: The previous title was pretty stupid... (silly me))
m (Extended note for DE not working approach)
(12 intermediate revisions by 10 users not shown)
Line 1: Line 1:
= Intro =
+
[[Category:Internationalization]]
 +
{{Note|If you are simply wishing to change the bindings of one or two keys (for example, swap backspace and delete or rebind another key to perform the function of one that is broken) you can also use [[Xmodmap]]. Furthermore this approach will most likely not work with desktop environment such as Gnome which manage the keyboard layout by their own.}}
 +
== Intro ==
  
 
This page should describe howto configure the keyboard layouts for X properly, and also some common pitfalls when trying to do so.
 
This page should describe howto configure the keyboard layouts for X properly, and also some common pitfalls when trying to do so.
Line 5: Line 7:
 
Note that this page deals with X only, if you want to set a proper keyboard for the console, you should edit /etc/rc.conf (KEYMAP variable), or you can do it manually with 'loadkeys'.
 
Note that this page deals with X only, if you want to set a proper keyboard for the console, you should edit /etc/rc.conf (KEYMAP variable), or you can do it manually with 'loadkeys'.
  
= Setting the layouts: the keyboard section in xorg.conf =
+
Instead of configuring xorg.conf you might as well use the [[Xorg#Keyboard_settings|hotplugging capabilities of Xorg]].
 +
 
 +
== Setting the layouts: the keyboard section in xorg.conf ==
  
 
Let's do it by example: mine looks like this:
 
Let's do it by example: mine looks like this:
  
  Section "InputDevice"
+
  Section "InputClass"
 
         Identifier      "IntegratedKeyboard"
 
         Identifier      "IntegratedKeyboard"
         Option         "CoreKeyboard"
+
         MatchIsKeyboard "on"
         Option          "XkbModel" "thinkpad60" # "pc105"
+
         MatchDevicePath "/dev/input/event*"
         Option          "XkbLayout"             "us,sk,de"
+
        Driver          "evdev"
 +
         Option          "XkbModel"     "thinkpad60"
 +
         Option          "XkbLayout"     "us,sk,de"
 
         Option          "XkbVariant"    "altgr-intl,qwerty,"
 
         Option          "XkbVariant"    "altgr-intl,qwerty,"
 
         Option          "XkbOptions"    "grp:menu_toggle,grp_led:caps"
 
         Option          "XkbOptions"    "grp:menu_toggle,grp_led:caps"
        Option          "XkbRules"              "xorg"
 
        Driver          "kbd"
 
 
  EndSection
 
  EndSection
 +
 +
Note that nowadays you should create a separate config file, like /etc/X11/xorg.conf.d/90-keyboard-layouts.conf, and put this text there.
  
 
The outcome is the following: I have three keyboard layouts available (us, sk and de) with my preferred variants; I can switch cyclically between them by pressing the 'menu' key, and when one of the last two is selected, my caps led is on (obviously, the caps led doesn't show if I have capslock on anymore). Also, the extra multimedia keys on my thinkpad will produce appropriate events.
 
The outcome is the following: I have three keyboard layouts available (us, sk and de) with my preferred variants; I can switch cyclically between them by pressing the 'menu' key, and when one of the last two is selected, my caps led is on (obviously, the caps led doesn't show if I have capslock on anymore). Also, the extra multimedia keys on my thinkpad will produce appropriate events.
  
 
Now some explanations for the variables:
 
Now some explanations for the variables:
* XkbModel: selects the keyboard model. This has an influence only for some extra keys your keyboard might have. The safe fallback is "pc105". But for instance laptops usually have some extra keys, and usually to get them working (without messing up with xmodmap, see below) you can set a proper model. The list of models can be found in /usr/share/X11/xkb/rules/xorg
+
* XkbModel: selects the keyboard model. This has an influence only for some extra keys your keyboard might have. The safe fallback are "pc104" or "pc105". But for instance laptops usually have some extra keys, and sometimes to get them working (without messing up with xmodmap, see below) you can set a proper model. The list of models can be found in /usr/share/X11/xkb/rules/xorg
 
* XkbLayout: sets the list of available layouts. The possibilities can be found in /usr/share/X11/xkb/symbols/* (each layout has a file there)
 
* XkbLayout: sets the list of available layouts. The possibilities can be found in /usr/share/X11/xkb/symbols/* (each layout has a file there)
* XkbVariant: specify variants for each of the layouts given in XkbLayout. For instance, the default sk variant is 'qwertz', so I had to specify 'qwerty' to get the one I wanted. The possibilities for variants can be found in /usr/share/X11/xkb/symbols/<layout> and they tend to have some commentary about what do they actually do. '''Warning:''' if you do specify some XkbVariant, you need to have as many commas in it as in XkbLayout, otherwise it may not work. For instance, if I just wanted sk-qwerty, and us and de with their default variants, I need to write 'XkbVariant ",qwerty,"' (notice the commas).
+
* XkbVariant: specify variants for each of the layouts given in XkbLayout. For instance, the default sk variant is 'qwertz', so I had to specify 'qwerty' to get the one I wanted. The possibilities for variants can be found in /usr/share/X11/xkb/symbols/<layout> and they tend to have some commentary about what do they actually do. '''Warning:''' if you do specify some XkbVariant, you need to have as many commas in it as in XkbLayout, otherwise it may not work. For instance, if I just wanted sk-qwerty, and us and de with their default variants, I need to write 'XkbVariant ",qwerty,"' (notice the commas). Similarly, if you have multiple XkbVariant entries for one XkbLayout, you will have to enter the layout multiple times (e.g. "us,us" and "dvorak,basic").
 
* XkbOptions: some extras. Here you can specify how do you want to switch the layouts, what led will be used for notification, a special way to enter the euro-sign, etc... For the possibilities, look at /usr/share/X11/xkb/rules/xorg and then for their descriptions in the appropriate file in /usr/share/X11/xkb/symbols/*
 
* XkbOptions: some extras. Here you can specify how do you want to switch the layouts, what led will be used for notification, a special way to enter the euro-sign, etc... For the possibilities, look at /usr/share/X11/xkb/rules/xorg and then for their descriptions in the appropriate file in /usr/share/X11/xkb/symbols/*
  
= What to do when it doesn't work as expected? =
+
== What to do when it doesn't work as expected? ==
  
 
First try to narrow down the problem by removing most of the settings, and adding them one-by-one to see when the problem occurs. Make sure that the syntax is correct (ie the commas in 'XkbVariant').
 
First try to narrow down the problem by removing most of the settings, and adding them one-by-one to see when the problem occurs. Make sure that the syntax is correct (ie the commas in 'XkbVariant').
Line 36: Line 42:
 
If you're still puzzled, try politely asking on the forums, with a good description of the problem, and also the list of things that you tried.
 
If you're still puzzled, try politely asking on the forums, with a good description of the problem, and also the list of things that you tried.
  
= Futher reading: assigning actions to extra keys =
+
== Futher reading: assigning actions to extra keys ==
  
 
It's all here [[Extra_Keyboard_Keys]] and here [[Extra_Keyboard_Keys_in_Xorg]].
 
It's all here [[Extra_Keyboard_Keys]] and here [[Extra_Keyboard_Keys_in_Xorg]].

Revision as of 15:10, 1 March 2013

Note: If you are simply wishing to change the bindings of one or two keys (for example, swap backspace and delete or rebind another key to perform the function of one that is broken) you can also use Xmodmap. Furthermore this approach will most likely not work with desktop environment such as Gnome which manage the keyboard layout by their own.

Intro

This page should describe howto configure the keyboard layouts for X properly, and also some common pitfalls when trying to do so.

Note that this page deals with X only, if you want to set a proper keyboard for the console, you should edit /etc/rc.conf (KEYMAP variable), or you can do it manually with 'loadkeys'.

Instead of configuring xorg.conf you might as well use the hotplugging capabilities of Xorg.

Setting the layouts: the keyboard section in xorg.conf

Let's do it by example: mine looks like this:

Section "InputClass"
        Identifier      "IntegratedKeyboard"
        MatchIsKeyboard "on"
        MatchDevicePath "/dev/input/event*"
        Driver          "evdev"
        Option          "XkbModel"      "thinkpad60"
        Option          "XkbLayout"     "us,sk,de"
        Option          "XkbVariant"    "altgr-intl,qwerty,"
        Option          "XkbOptions"    "grp:menu_toggle,grp_led:caps"
EndSection

Note that nowadays you should create a separate config file, like /etc/X11/xorg.conf.d/90-keyboard-layouts.conf, and put this text there.

The outcome is the following: I have three keyboard layouts available (us, sk and de) with my preferred variants; I can switch cyclically between them by pressing the 'menu' key, and when one of the last two is selected, my caps led is on (obviously, the caps led doesn't show if I have capslock on anymore). Also, the extra multimedia keys on my thinkpad will produce appropriate events.

Now some explanations for the variables:

  • XkbModel: selects the keyboard model. This has an influence only for some extra keys your keyboard might have. The safe fallback are "pc104" or "pc105". But for instance laptops usually have some extra keys, and sometimes to get them working (without messing up with xmodmap, see below) you can set a proper model. The list of models can be found in /usr/share/X11/xkb/rules/xorg
  • XkbLayout: sets the list of available layouts. The possibilities can be found in /usr/share/X11/xkb/symbols/* (each layout has a file there)
  • XkbVariant: specify variants for each of the layouts given in XkbLayout. For instance, the default sk variant is 'qwertz', so I had to specify 'qwerty' to get the one I wanted. The possibilities for variants can be found in /usr/share/X11/xkb/symbols/<layout> and they tend to have some commentary about what do they actually do. Warning: if you do specify some XkbVariant, you need to have as many commas in it as in XkbLayout, otherwise it may not work. For instance, if I just wanted sk-qwerty, and us and de with their default variants, I need to write 'XkbVariant ",qwerty,"' (notice the commas). Similarly, if you have multiple XkbVariant entries for one XkbLayout, you will have to enter the layout multiple times (e.g. "us,us" and "dvorak,basic").
  • XkbOptions: some extras. Here you can specify how do you want to switch the layouts, what led will be used for notification, a special way to enter the euro-sign, etc... For the possibilities, look at /usr/share/X11/xkb/rules/xorg and then for their descriptions in the appropriate file in /usr/share/X11/xkb/symbols/*

What to do when it doesn't work as expected?

First try to narrow down the problem by removing most of the settings, and adding them one-by-one to see when the problem occurs. Make sure that the syntax is correct (ie the commas in 'XkbVariant').

Read the section on xmodmap and xev below for more ways to check what's going on.

If you're still puzzled, try politely asking on the forums, with a good description of the problem, and also the list of things that you tried.

Futher reading: assigning actions to extra keys

It's all here Extra_Keyboard_Keys and here Extra_Keyboard_Keys_in_Xorg.