calin-darie / extra-keyboard-layouts

To România and beyond!
MIT License
62 stars 36 forks source link

KLC to KCM conversion #14

Open Woren opened 2 years ago

Woren commented 2 years ago

This is more as a question that real issue. And maybe it will help someone in the future. I'm using my own layout in Windows which was created by kbdedit and I have KLC file with it. Now I'm looking to a way how to export or convert it to KCM file to use it with this library. I'm Android developer so I can compile my own version of this library because this layout is not that widely used and no need to add it directly to official release. I have also attached layout for any case.

The description of this layout use case can be found for example here

I have alredy found way how to convert KLC to XKB (for Linux), but still no luck with KLC to KCM. So are there any tools or any hints how to convert KLC to KCM?

Thank you

CzechSuperProgrammer.zip .

calin-darie commented 2 years ago

keyboard_layout_kbd_layout01_czech_super_programmers_custom.zip

Does this work?

Woren commented 2 years ago

Firstly - thank you for trying! But unfortunately it's not working. Mainly missing top horizontal keyboard row which should produce Czech characters (ěščřžýáíé - now producing numbers) and dead key (should be the key on the left of Backspace) to produce rest of the Czech specific letters (úůťď etc.). Was this conversion made somehow automatically from that KLC file? 

calin-darie commented 2 years ago

The problem was the 0 key mapped twice in the KLC, which resulted in key 0 being mapped twice in the KLM. Fixed by setting the second mapping it back to EQUALS extra-keyboard-layouts-with-czech-super-programmers-unofficial.zip .

Woren commented 2 years ago

Much better now! I had to adjust EQUALS key for start to this: key EQUALS { label: '\u0301' base: '\u0301' ralt: '\u002b' shift: '\u030c' }

But these two main things about dead key are still missing:

1) \u030c (ˇ) + \u0075 (u) should produce \u016f (ů), but now it's producing \u01d4 (ǔ), which is non existing character in Czech. But for example: \u030c (ˇ) + \u0074 (t) result \u0165 (ť) is fine

2) \u030c (ˇ) + \u030c (ˇ) should produce \u003d (=). Basically double pressing key EQUALS should produce \u003d (=)

As I'm looking to documentation I'm not sure how and even if this is possible using provided syntax. Dead keys are handled "by the system automatically" which leads to problems marked 1) and I don't see a way how to handle it directly as with KLC file where there is specific mapping for case 1). Maybe somehow "programmatically"?

calin-darie commented 2 years ago

Sorry I'm pretty caught up with other projects. Just saw your stack overflow question and bounty

I don't know how such a behavior could be accomplished in klm. You're right, the dead keys are handled by the system as far as I know too.

calin-darie commented 2 years ago

https://source.android.com/devices/input/key-character-map-files

The system recognizes the following Unicode characters as combining diacritical dead key characters:

'\u0300': Grave accent. '\u0301': Acute accent. '\u0302': Circumflex accent. '\u0303': Tilde accent. '\u0308': Umlaut accent. When a dead key is typed followed by another character, the dead key and the following characters are composed. For example, when the user types a grave accent dead key followed by the letter 'a', the result is 'à'.

Refer to KeyCharacterMap.getDeadChar for more information about dead key handling.

https://developer.android.com/reference/android/view/KeyCharacterMap#getDeadChar(int,%20int)

Woren commented 2 years ago

Yes, I found that links too. Here is the source code for that getDeadChar() method.
This method is static and is using static final arrays so there is no "nice way" to override it. Also this has to be "system wide" so any software keyboard calling this method will get overrided method. Also afaik dead end.
If stackoverflow will lead nowhere I will open issue on the Android issue tracker with hope that option to edit dead key characters will be added directly to KLM. Very little chance it will happen in the end. I will post link here too.
But thanks again for help.

Woren commented 2 years ago

Android issue mentioned above about dead keys handling is created here.

Woren commented 2 years ago

Just want to add that list of dead keys handled by system linked here is not complete and complete list should be here. List is here just in case:

   static {
        addCombining('\u0300', ACCENT_GRAVE);
        addCombining('\u0301', ACCENT_ACUTE);
        addCombining('\u0302', ACCENT_CIRCUMFLEX);
        addCombining('\u0303', ACCENT_TILDE);
        addCombining('\u0304', ACCENT_MACRON);
        addCombining('\u0306', ACCENT_BREVE);
        addCombining('\u0307', ACCENT_DOT_ABOVE);
        addCombining('\u0308', ACCENT_UMLAUT);
        addCombining('\u0309', ACCENT_HOOK_ABOVE);
        addCombining('\u030A', ACCENT_RING_ABOVE);
        addCombining('\u030B', ACCENT_DOUBLE_ACUTE);
        addCombining('\u030C', ACCENT_CARON);
        addCombining('\u030D', ACCENT_VERTICAL_LINE_ABOVE);
        addCombining('\u0312', ACCENT_TURNED_COMMA_ABOVE);
        addCombining('\u0313', ACCENT_COMMA_ABOVE);
        addCombining('\u0314', ACCENT_REVERSED_COMMA_ABOVE);
        addCombining('\u0315', ACCENT_COMMA_ABOVE_RIGHT);
        addCombining('\u031B', ACCENT_HORN);
        addCombining('\u0323', ACCENT_DOT_BELOW);
        addCombining('\u0327', ACCENT_CEDILLA);
        addCombining('\u0328', ACCENT_OGONEK);
        addCombining('\u0329', ACCENT_VERTICAL_LINE_BELOW);
        addCombining('\u0331', ACCENT_MACRON_BELOW);
        addCombining('\u0335', ACCENT_STROKE);
        sCombiningToAccent.append('\u0340', ACCENT_GRAVE);
        sCombiningToAccent.append('\u0341', ACCENT_ACUTE);
        sCombiningToAccent.append('\u0343', ACCENT_COMMA_ABOVE);
        sAccentToCombining.append(ACCENT_GRAVE_LEGACY, '\u0300');
        sAccentToCombining.append(ACCENT_CIRCUMFLEX_LEGACY, '\u0302');
        sAccentToCombining.append(ACCENT_TILDE_LEGACY, '\u0303');
    }

So I ended using this list for some missing dead key handlings. The result is not perfect. Still missing custom dead keys handling to override "system" dead keys handling and some combinations are not the same as for input layout mentioned in the first post. Here is (semi)final KCM layout if anyone is interested keyboard_layout_czech_super_programmers.zip