1. Overview

Understanding and managing keyboard configurations is important for efficient interaction with Linux systems. Further, system administrators may need to tailor their keyboard settings using commands such as setxkbmap. Therefore, knowing the available keyboard variants, layouts, or toggle options is necessary to know which one to choose.

In this tutorial, we’ll explore ways to list all available keyboard variants, layouts, and toggle options in a Linux system.

2. Keyboard Variants and Layouts

A keyboard variant refers to the specific language or regional settings that determine the software character mappings from keys on a keyboard. While a keyboard layout defines the physical arrangements of keys, a variant determines how those keys are interpreted and what characters or symbols they produce.

For instance, the US English variant maps the Q key to the letter Q, while the French variant maps the same key to A. However, variants can go beyond just character mappings. They can also include settings for features:

  • dead keys: keys that don’t directly produce a character but modify the next keystroke to create a combined character, such as accented letters or symbols
  • compose key behavior: determines how the compose key (typically a modifier key) is used in combination with other keystrokes to input complex characters or symbols
  • alternative keyboard layouts: some variants may provide alternative physical key arrangements tailored for specific languages or typing preferences
  • modifier key behavior: variants can define how modifier keys like ShiftCtrl, and Alt interact with other keys
  • numeric keypad configuration: allows for customization of behavior and character mappings of the numeric keypad can be customized for certain languages

On the other hand, keyboard layouts define the physical arrangement of keys on a keyboard. They also dictate where each key is located and how they are grouped together. This can include different variations:

  • QWERTY
  • AZERTY
  • Dvorak

Each layout is designed with specific ergonomics and typing efficiency in mind. For instance, the Dvorak layout places the most commonly used letters in the English language on the home row where they are easily accessible, thereby reducing finger movement and potentially increasing typing speed.

3. Using localectl Command

The localectl command is part of the systemd system and service manager which we use to query and change the system locale and keyboard layout settings. Also, it provides detailed information about the current keyboard configuration and available options.

First, let’s look at the current keyboard variant settings:

$ localectl status
   System Locale: LANG=en_NG
                  LANGUAGE=en_NG:en
       VC Keymap: us
      X11 Layout: us,de
       X11 Model: pc104

The output typically includes some specific information:

It indicates that the system’s language is set to English (United States), with a corresponding virtual console keymap and X11 layout.

3.1. List Keyboard Variants

We can list the available keyboard variants on our Linux system using localectl:

$ localectl list-x11-keymap-variants
101_qwerty_comma_dead
101_qwerty_comma_nodead
101_qwertz_comma_nodead
101_qwertz_dot_dead
...
102_qwertz_comma_dead
102_qwertz_comma_nodead
102_qwertz_dot_dead
102_qwertz_dot_nodead
CloGaelach
OADG109A
...

The output of this command is a list of all supported keyboard variants. Alternatively, we can specify a particular layout to filter the variants specific to that layout:

$ localectl list-x11-keymap-variants us
alt-intl
altgr-intl
chr
colemak
colemak_dh
colemak_dh_iso
dvorak
dvorak-alt-intl
dvorak-classic
dvorak-intl
dvorak-l
dvorak-r
dvp
...

Now, the output should only contain variants available for the US keyboard layout.

3.2. List Keyboard Layouts

Just like keyboard variants, we can use the localectl command to list the available keyboard layouts:

$ localectl list-x11-keymap-layouts
af
al
am
ara
at
au
az
ba
bd
...

The output of this command is therefore a comprehensive list of supported keyboard layouts typically including options for various languages, dialects, and regional variations.

3.3. Toggle Options

Toggle options enable users to switch between different input configurations or enable specific behaviors. We can also view the available toggle options using the localectl command:

$ localectl list-x11-keymap-options
Compose
altwin
altwin:alt_super_win
altwin:alt_win
altwin:ctrl_alt_win
altwin:ctrl_rwin
altwin:ctrl_win
altwin:hyper_win
altwin:left_meta_win
altwin:menu
altwin:menu_win
altwin:meta_alt
...

The output is a comprehensive list of all supported toggle options, some of which even include Meta keys.

However, we can focus on options related to layout switching or group toggling by filtering the output via the grep command:

$ localectl list-x11-keymap-options | grep grp:
grp:alt_caps_toggle
grp:alt_shift_toggle
grp:alt_space_toggle
grp:alts_toggle
grp:caps_switch
grp:caps_toggle
grp:ctrl_alt_toggle
...

The output is the list of toggle options for switching between keyboard layouts or input groups.

4. The base.lst File

The base.lst file is typically located in the /usr/share/X11/xkb/rules/ directory on most Linux distributions that use the X Window System (X11). Further, this file contains a list of available keyboard layouts, models, variants, and options that we can use to configure the keyboard behavior in the X11 environment. It also serves as a central repository of keyboard-related information and various tools and applications that need to interact with the keyboard configuration.

4.1. Structure and Contents

Moreover, the base.lst file is structured in a specific format, with different sections:

  • keyboard models
  • keyboard layouts
  • keyboard variants
  • keyboard options

Each section contains entries that describe the available choices and provide additional information or metadata about them.

For instance, let’s look at a sample base.lst file and its contents:

$ cat /usr/share/X11/xkb/rules/base.lst
! model
  pc86            Generic 86-key PC
  pc101           Generic 101-key PC
  pc102           Generic 102-key PC
  ...

! layout
  us              English (US)
  af              Afghani
  ara             Arabic
  ...

! variant
  chr             us: Cherokee
  haw             us: Hawaiian
  euro            us: English (US, euro on 5)
  ...

! option
  grp                  Switching to another layout
  grp:switch           Right Alt (while pressed)
  grp:lswitch          Left Alt (while pressed)
  ...

Further, filtering the sections of this file is a more descriptive approach to listing the keyboard properties.

4.2. Listing Keyboard Variants

If we prefer a more descriptive approach in listing the available keyboard variants, we can filter the section between the markers !variant and the next empty line:

$ sed '/^! variant$/,/^ *$/!d;//d' /usr/share/X11/xkb/rules/base.lst
  chr             us: Cherokee
  haw             us: Hawaiian
  euro            us: English (US, euro on 5)
  intl            us: English (US, intl., with dead keys)
  ...

This command displays a list of keyboard variants along with their corresponding descriptions.

4.3. Listing Keyboard Layouts

Similar to the approach for listing variants, we can also search the base.lst file to obtain a more descriptive listing of keyboard layouts:

$ sed '/^! layout$/,/^ *$/!d;//d' /usr/share/X11/xkb/rules/base.lst
  us              English (US)
  af              Afghani
  ara             Arabic
  al              Albanian
  am              Armenian
  at              German (Austria)
  au              English (Australian)
  az              Azerbaijani
  by              Belarusian
  ...

The output comprises the available keyboard layouts with additional context that helps us identify the corresponding layout.

4.4. Listing Toggle Options

We can also search the base.lst file for a more descriptive listing of toggle options:

$ sed '/^! option$/,/^ *$/!d;//d' /usr/share/X11/xkb/rules/base.lst
  grp                  Switching to another layout
  grp:switch           Right Alt (while pressed)
  grp:lswitch          Left Alt (while pressed)
  grp:lwin_switch      Left Win (while pressed)
  grp:rwin_switch      Right Win (while pressed)
  grp:win_switch       Any Win (while pressed)
  grp:menu_switch      Menu (while pressed), Shift+Menu for Menu
  grp:caps_switch      Caps Lock (while pressed), Alt+Caps Lock for the original Caps Lock action
  grp:rctrl_switch     Right Ctrl (while pressed)
  grp:toggle           Right Alt
  ...

The code snippet displays the available toggle options and provides additional context that helps us understand the purpose and functionality of each option.

5. Conclusion

Knowing the available keyboard layouts, variants, and toggle options is important to configure and manage keyboard input settings particularly when using commands like setxkbmap. It enables us to know the available options to use for this command.

In this article, we explored the concepts of keyboard variants and layouts, distinguishing their roles in character mappings and physical key arrangements. We also discussed how to use the localectl command to list available keyboard variants, layouts, and toggle options. Finally, we looked at how to filter the base.lst file for this purpose.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments