LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (http://www.linuxquestions.org/questions/slackware-14/)
-   -   How to match X keyboard layout with the the kernel keyboard map? (http://www.linuxquestions.org/questions/slackware-14/how-to-match-x-keyboard-layout-with-the-the-kernel-keyboard-map-4175455061/)

Didier Spaier 03-21-2013 06:37 PM

How to match X keyboard layout with the the kernel keyboard map?
 
As a reminder:
(1) the kernel keymap for the console can be chosen (either during installation or later) among those available in directories:
/usr/share/kbd/keymaps/i386/{azerty,colemak,dvorak,fgGlod,olpc,qwerty,qwertz}
(2) the keyboard layout used under X can be set among those listed under "! layout" in file:
/usr/share/X11/xkb/rules/evdev.lst

I would like that during Slackware configuration post-installation, whenever possible a user who has chosen a given kernel keymap be offered to set a matching X keyboard layout (if it exists and the kbd and xorg-server packages have been installed, of course). In other words in that case copy /usr/share/X11/xorg.conf.d/90-keyboard-layout.conf to /etc/X11/xorg.conf.d and replace in it 'Option "XkbLayout" "us"' by whatever appropriate (and possibly set the "XkbVariant" option as well, picking one under "! variant" in evdev.lst).

It's easy in my case as I use "fr.map" and has just to replace "us" by "fr" in the X configuration file but that is very often *a lot* more tricky.

Thanks in advance for any clue, idea, experience, information about how it is done by other distributions or existing software, etc.

PS Debian's console-setup source package includes two interesting scripts from Anton Zinoviev, namely ckbcomp-mini (shell) and ckb-comp (perl). I'll simply quote their manual page below:
Code:

NAME
      ckbcomp  -  compile a XKB keyboard description to a keymap suitable for
      loadkeys or kbdcontrol


SYNOPSIS
      ckbcomp [OPTION...] [XKBLAYOUT [XKBVARIANT [XKBOPTIONS]...]]


DESCRIPTION
      The ckbcomp keymap compiler converts a description of an  XKB  keyboard
      layout  into  a console keymap that can be read directly by loadkeys(1)
      or kbdcontrol(1).

That looks very nice, indeed. The only problem being that I want to make the reverse conversion :scratch:

eloi 03-23-2013 06:40 AM

Hi Didier,

Perhaps I didn't understand what you want. Do you know setxkbmap command?

Didier Spaier 03-23-2013 07:13 AM

Hi Walter,

setxkbmap maps the keyboard to use the layout determined by the options specified in the command (or in the config files if no option is given), IOW put in effect an existing XKB keyboard description.

What I want to do is compute an XKB keyboard description matching a given kernel keymap.

Let's take an example.

Assuming that I have chosen the kernel keymap pt-latin9.map, how to set appropriately XkbLayout, XkbVariant, ... so that pressing a given key output the same character on an X terminal as it does on the console?

eloi 03-23-2013 11:09 AM

Debian uses its own software to setup console (console-setup). I know that Debian lets you write xkboptions on /etc/default/keyboard. But I didn't investigate in which way debian do that trick.

Now in the opposite way. I have a personal es.map for Slackware just to add euro sing and slight modifications and another highly modified for a machitosh keyboard, but I would not try to write a "translator" to xkboptions for that :).

I couldn't make some modifications to the standard keymap using xkboptions. In this cases I must use a Xmodmap file.

Resuming depending on how complex are the modifications you need I think that translating them to xkboptions could be not possible or very tricky. Even doing it manually (I understand you want to automatize).

Well that's what I know. I didn't help too much this time.

Didier Spaier 03-23-2013 11:26 AM

Thanks anyway. Quizás la próxima vez.

Didier Spaier 03-23-2013 03:51 PM

I sent an email to Anton Zinoviev:
Quote:

My question is: would it be possible to make the reverse conversion, i.e. knowing the kernel keymap, compute a matching XKB kernel description?
His response was fast and clear:
Code:

No.  However you can use an approximate guesswork similar to the one
used in Debian before console-setup was utilized by the installer:

    case "$console_keymap" in
        be2) XKBLAYOUT="be";;
        bg) XKBLAYOUT="us,bg";;
        br) XKBLAYOUT="us"; XKBVARIANT="intl";;
        br-abnt2) XKBLAYOUT="br"; XKBVARIANT="abnt2";;
        by) XKBLAYOUT="us,by";;
        cf) XKBLAYOUT="ca"; XKBVARIANT="fr";;
        croat) XKBLAYOUT="hr";;
        cz-lat2) XKBLAYOUT="cz";;
        de-latin1-nodeadkeys) XKBLAYOUT="de"; XKBVARIANT="nodeadkeys";;
        de) XKBLAYOUT="de";;
        dvorak) XKBLAYOUT="us"; XKBVARIANT="dvorak";;
        dk) XKBLAYOUT="dk";;
        es) XKBLAYOUT="es";;
        et) XKBLAYOUT="ee";;
        'fi') XKBLAYOUT="fi";;
        fr-latin9) XKBLAYOUT="fr"; XKBVARIANT="latin9";;
        fr_CH) XKBLAYOUT="ch"; XKBVARIANT="fr";;
        fr) XKBLAYOUT="fr";;
        hebrew) XKBLAYOUT="us,il";;
        hu) XKBLAYOUT="hu";;
        gb) XKBLAYOUT="gb";;
        is) XKBLAYOUT="is";;
        it) XKBLAYOUT="it";;
        jp106) XKBLAYOUT="jp"; XKBVARIANT="106";;
        la) XKBLAYOUT="latam";;
        lt) XKBLAYOUT="lt";;
        lv-latin4) XKBLAYOUT="lv";;
        mac-us-std) XKBLAYOUT="us";;
        mac-de2-ext) XKBLAYOUT="de"; XKBVARIANT="nodeadkeys";;
        mac-fr2-ext) XKBLAYOUT="fr";;
        mac-fr3) XKBLAYOUT="fr";;
        mac-es) XKBLAYOUT="es";;
        ky) XKBLAYOUT="us,kg";;
        mk) XKBLAYOUT="us,mk";;
        nl) XKBLAYOUT="nl";;
        no) XKBLAYOUT="no";;
        pl) XKBLAYOUT="pl";;
        pt) XKBLAYOUT="pt";;
        ro) XKBLAYOUT="ro";;
        ru) XKBLAYOUT="us,ru";;
        se) XKBLAYOUT="se";;
        sg) XKBLAYOUT="ch"; XKBVARIANT="de";;
        sk-qwerty) XKBLAYOUT="sk"; XKBVARIANT="qwerty";;
        slovene) XKBLAYOUT="si";;
        sr-cy) XKBLAYOUT="cs,cs"; XKBVARIANT="latin,basic" ;;
        trf|trfu) XKBLAYOUT="tr"; XKBVARIANT="f";;
        trq|trqu) XKBLAYOUT="tr";;
        ua) XKBLAYOUT="us,ua";;
        uk) XKBLAYOUT="gb";;
        us) XKBLAYOUT="us";;
        *)
            XKBLAYOUT="us"
        ;;
    esac

I'll do just that (at the end of 'setup' in Slackware's unofficial internationalized installer).

So I mark this thread [solved]. Thanks to all who took the time to read it.

eloi 03-24-2013 04:08 AM

After *trying* it you will find out that my not so clear response was an explanation for the starting Anton's "No".

Didier Spaier 03-24-2013 04:31 AM

Well, I'm not looking for nor needing something perfect.

If the mapping for [A-7,a-z,0-9], punctuation, and some other characters useful for shell scripting and password typing is correct, that's good enough for me.

Users will still have to make customization in some cases, but at least they won't have to figure out any more "Why the password which works on the console doesn't after startx?" ;)

PS I didn't ask Anton to elaborate his "No", as I tend to simply trust someone able to write a 4728 lines and 147645 characters long perl script to perform the conversion one way who tells me that reverse is not possible ;)

<OT>@BDFL: just in case you didn't know already, Anton is volunteer to make or help making a Slackware package of console-setup (or parts of it which could benefit to Slackware).</OT>

eloi 03-24-2013 05:30 AM

More puzzles?
 
Quote:

Originally Posted by Didier Spaier (Post 4917623)
Well, I'm not looking for nor needing something perfect.

If the mapping for [A-7,a-z,0-9], punctuation, and some others useful for shell scripting and password typing is correct, that's good enough for me.

Users will still have to make customization in some cases, but at least they won't have to figure out any more "Why the password which works on the console doesn't after startx?" ;)

That's why I suggest you setxkbmap.

Didier Spaier 03-24-2013 05:56 AM

Quote:

Originally Posted by eloi (Post 4917645)
That's why I suggest you setxkbmap.

That would be the way to go once the system is installed.

But I'm doing that from the installer (near the end of the 'setup' script). So I'll simply propose the user to do for him or her during installation what is suggested in CHANGES_AND_HINTS.TXT: copy /usr/share/X11/xorg.conf.d/90-keyboard-layout.conf to /etc/X11/xorg.conf.d and edit the copy.

I just need to know how to set XkbLayout and XkbVariant options for a given locale (asking the user at this point is not an option I'd consider).

As I don't expect the installer to include more than ~350 locales before end of current year, what Anton suggests (and to which I am ashamed not having thought of myself from the beginning) fits my needs ;)

gnashley 03-24-2013 01:23 PM

Seems to me that one could in the shell, loop the program through all possible translations and have it echo out a translation table similar to the one above. Have it print it out both ways to convert both ways. I just did a similar trick last week to create tables to convert unix permissions from octal-to-human and human-to-octal.

Didier Spaier 03-24-2013 02:40 PM

Quote:

Originally Posted by gnashley (Post 4917836)
Seems to me that one could in the shell, loop the program through all possible translations and have it echo out a translation table similar to the one above. Have it print it out both ways to convert both ways. I just did a similar trick last week to create tables to convert unix permissions from octal-to-human and human-to-octal.

Maybe... This is not my priority but would you want to try, the source console-setup package for squeeze is here (aforementioned scripts are in /Keyboard).

"All possible" may be a bit tricky to determine though, as maybe not all variants are relevant for all layouts, for instance. That's only a question as my knowledge in this matter would hardly fill a thimble.


All times are GMT -5. The time now is 03:21 AM.