1

I realize that by adding

setxkbmap xxx

we can change the keyboard layout in X server. It cannot survive logout/reboot, so we can add this line into $HOME/.profile to make it available when we log in, as this question describes.

But, when we do this, before logining in, the keyboard layout is still not available. If we want to use it at this stage, what is the way to go? I am using GDM on Centos7.

What I have tried:

  1. Define a new keyboard layout, named symmetri, and put it under /usr/share/X11/xkb/symbols/. To test, you can download it here. NOTE: I have only defined the layout for X11 server, not yet for virtual console. Maybe that is why I cannot list it with locatectl list-keymaps, neither loadkeys, nor touching /etc/vconsole.conf.

  2. setxkbmap symmetri to use it. Changes applied. Put it in /etc/profile.d/symmetri.sh to use it in user profile.

  3. Log out and when I try to login, it stops to work and I get QWERTY.

  4. I log in with QWERTY, and then I use Symmetri now, because the script is sourced out upon successful login.

  5. Open terminal, I switch back to us by setxkbmap us,

And then,

localectl set-x11-keymap symmetri

This time, the layout is not switched. localectl set-keymap symmetri neither.

  • Wait, why did you put it in /etc/profile.d? What is in /etc/profile.d/symmetri.sh? Did you try echo "setxkbmap symmetri >> /var/lib/gdm/.profile? Did you try adding setxkbmap symmetri to /etc/profile? – terdon May 31 '18 at 15:48
  • Setting locale on boot makes gdm use that setting on startup. See man locale, man locale.conf and man locale-gen for more info. – Mio Rin May 31 '18 at 15:49
  • OK I meant put setxkbmap symmetri into /etc/profile.d/symmetri.sh. No, I haven't try /etc/profile/, neither echo this line into another file – WesternGun May 31 '18 at 16:00
  • I thought you said you tried putting it in /var/lib/gdm/.profile. If you didn't, can you please try that and let us know if it works? – terdon May 31 '18 at 16:38
  • Thanks terdon, you are almost the nicest guy I have seen here. No, /var/lib/gdm/.profile does not work, either, neither with logout/login or reboot. Upon login, I have old keyboard layout. – WesternGun Jun 04 '18 at 07:28

2 Answers2

3

you can use

localectl set-x11-keymap ***

This will be permanent for the console and desktop, more detailed configuration can be found on the man page https://www.unix.com/man-page/centos/1/LOCALECTL/

  • Well, I don't know, but localectl does not work for me; in my case it is a customized keymap file for X11, with no extension; it is not a xxx.map file for virtual console. What works was setxkbmap. – WesternGun May 30 '18 at 09:25
  • At last your solution is the way, but not before adding the new layout into .../X11/xkb/rules/evdev.xml and .../X11/xkb/rules/evdev.lst file. See my answer. It is just weird that it works in your situation but not in mine. – WesternGun Jun 04 '18 at 15:43
  • For me it seems to write in /etc/vconsole.conf but not in /etc/locale.conf, and the man says `Note that the changes performed using this tool might require the initramfs to be rebuilt to take effect during early system boot. The initramfs is not rebuilt automatically by localectl.

    Note that systemd-firstboot(1) may be used to initialize the system locale for mounted (but not booted) system images.`, so I haven't rebooted but it will not be a surprise if it vanishes

    – wxi Feb 15 '20 at 09:46
0

@terdon your solution is not working, but thanks for helping me out, I have learned more; at first I am also suspecting if it has something to do with Gnome, but it turned out that it is only X11. And @TimBrandrick, your solution should work in most of the cases, but in my case, not before adding my keyboard layout into the .../X11/xkb/rules/evdev.xml (and just in case, .../X11/xkb/rules/evdev.lst, because according to some sources, the lst file is the compiled version of xml, but I doubt whether all processes depending on these files will only read xml files; so I add in both. Actually, xml has more info than lst, but lst is easier to understand.)

So, here's how I did it:

1. Open .../X11/xkb/rules/evdev.xml.

(I omit the initial part, because it differs between distributions. In CentOS 7, it is under /usr/share/; in Ubuntu <= 8.08, it is under /etc/.1 Strange. )

2. At the end of children nodes of <layoutList>, add this part:

(change as you need, it is just a template)

<layout>
  <configItem>
    <name>symmetri</name>
    <shortDescription>symmetri</shortDescription>
    <description>Symmetri (CN, EN and ES)</description>
    <languageList>
      <iso639Id>us</iso639Id>
    </languageList>
  </configItem>
  <variantList>
    <variant>
      <configItem>
        <name>non-prog</name>
        <shortDescription>non-prog</shortDescription>
        <description>Symmetri for non-programmer (CN, EN and ES)</description>
        <languageList>
          <iso639Id>us</iso639Id>
        </languageList>
      </configItem>
    </variant>
  </variantList>
</layout>

If your keyboard layout has no variant, <variantList> part can be self-closing, like: <variantList />.

Note: iso639Id should has a value compatible with ISO 639-1 or 639-2 standard.1 The full table is also given in the reference 1. And, it must be conform with your locale settings. I set English(U.S) as my system language, so I fill us here.

3. Save it, and open .../X11/xkb/rules/evdev.lst.

4. At the end of ! layout, add your layout's name. Like:

symmetri        Symmetri layout (CN, EN and ES)

5. If your keyboard layout has variant, at the end of ! variant, add it, too.

non-prog        symmetri: non-programmer

The variant's name should coincide with the info above in the xml file. (As I test, localectl list-x11-keymap-variants will only read this file instead of reading the xml, should be an error/bug.)

6. You can do the same to base.xml and base.lst, but I did it first and it does not work.

7. Set your keyboard layout with:

setxkbmap symmetri

or, to set the variant, use:

setxkbmap symmetri -variant non-prog 

localectl can list-x11-keymap-layouts and list-x11-keymap-variants, but you cannot set variant with it; only setxkbmap can.

With this setting, now after reboot and before first login, you have your new keyboard layout(although the variant will not persist!! Only the basic layout will!) But, once successfully login, the desktop manager will take over, and if you don't configure the new keyboard layout in the $HOME/.bashrc/$HOME/.profile(for single user)//etc/profile.d/xxx.sh//etc/profile(for all users) file, you will not get your new keyboard layout once logout and login back!!!! So these changes will only persist before first successful login... you have to use .bashrc or profile scripts to tell X server: "not only before login, but also after login I want it for all users!" Cautious: with this change, even if you log out and change user, the layout will be the changed one, not qwerty(us).

Really frustrating.... there must be a easier way, but I cannot find it.

References:(a must read)

  1. http://people.uleth.ca/~daniel.odonnell/Blog/custom-keyboard-in-linuxx11
  • Another thing is: in Ubuntu, you can edit /etc/default/keyboard file to achieve the same. And then, you update the kernel definition with update-initramfs -u – WesternGun May 16 '21 at 12:36
  • Another thing is: in Ubuntu, you can edit /etc/default/keyboard file to achieve the same. And then, you update the kernel definition with update-initramfs -u – WesternGun May 16 '21 at 12:36