Plan 9: Devanagari Input with kbmap

 

Note: The demo uses layer 3 for better key visualization while using Devanagari. 

          The PS/2 interface presents two physical layers, switched on
          if the input scancode is one or two bytes. This second
          "escaped" layer is typically generated for keys like `Home'
          and `Ins'.  Kbdfs additionally maintains eight more virtual
          layers that are switched on `Shift', `Ctl', `AltGr', and
          `Mod4' modifier key state. Not all permutations of these
          modifiers are represented as layers, the exhaustive list is
          as follows:

          none           Key
          shift          Shift + Key
          esc            Escaped Key
          altgr          AltGr + Key
          ctl            Ctl + Key
          ctlesc         Ctl + Escaped Key
          shiftesc       Shift + Escaped Key
          shiftaltgr     Shift + AltGr + Key
          mod4           Mod4 + Key
          altgrmod4      AltGr + Mod4 + Key

To use AltGr + k = क, use one of the following:

# Layer, scan code and codepoint triplet 
echo      3 37 0x915 > /dev/kbmap
 
# /sys/lib/kbmap/hindi (can be loaded using kbmap command)
# Both forms are valid 
3 37 'क
3 37 0x915 
  

Refer to /sys/lib/kbmap/us for scan code (sc) to key mapping. Once you're satisfied with the mapping, you can generate the language file and place it in /sys/lib/kbmap/. Then you can use kbmap or kbremap (using Ctrl + space) command to change the input method on the fly.

For composing using Alt, the definitions are in /lib/keyboard.

# Hex, composition characters, unicode, description 
00A2  c$          ¢    cent sign
00A3  l$          £    pound sign
00A5  y$          ¥    yen sign
  


Pre-requisites

  1. A font supporting the unicode codepoint. You need Truetype Font for composite glyphs.
  2. Text shaping support in libdraw.

Suggested Layout for Devanagari

Layers used: 0=none, 1=shift, 3=altgr, 7=shiftaltgr (skipping esc/ctlesc/shiftesc — those only fire for 2-byte escape scancodes, irrelevant to plain letter keys; skipping ctl/mod4 to avoid clobbering editor/WM bindings).

Consonants (dental/retroflex and unaspirated/aspirated pairs share a key):

key sc 0 1 3 7
k 37

g 34

c 46

j 36

t 20
d 32
n 49

p 25

फ 


b 48

m 50


y 21


r 19


l 38


v 47


s 31
h 35


q 16


x 45




Vowels (0=independent, 1=matra, 3=independent marked, 7=matra marked):
key sc 0 1 3 7
a 30
i 23 ि
u 22
e 18
o 24

 

Marks (spare letters):

key sc 0 1 3 7
z 44
w 17


Virama: dedicated key, - (OEM_MINUS, sc 12): 0 12 0x94d. Conjuncts are 3 keystrokes — consonant, virama, consonant — same as real InScript, already confirmed correct and complete.

Digits: number-row keys, layer0=ASCII digit (unchanged), layer3(altgr)=Devanagari digit ०-९.

Compose-key hex stays the fallback for anything not on this table (Vedic accents, rare marks).

Script to generate mapping

#!/bin/sh
# load Hindi phonetic kbmap table onto altgr/shiftaltgr/mod4/altgrmod4
# (layers 3/7/8/9) -- layers 0/1 (none/shift) are left untouched so
# plain typing and /dev/kbd's k-message stay pure ASCII.
# layer sc hex

while read -r layer sc hex; do
    printf "%s %s '%s\n" "$layer" "$sc" "$hex"
done <<'EOF'
     3 37 क
8 37 ख
3 34 ग
8 34 घ
    3 46 च 
8 46 छ 
3 36 ज 
8 36 झ
    3 20 त 
7 20 ट 
8 20 थ 
9 20 ठ
    3 32 द 
7 32 ड 
8 32 ध 
9 32 ढ
    3 49 न 
7 49 ण 
3 25 प 
3 33 फ
    3 48 ब 
8 48 भ 
7 50 म 
3 21 य
    3 19 र 
3 38 ल 
3 17 व 
3 31 स
    7 31 ष 
8 31 श 
3 35 ह 
3 16 ङ
    3 45 ञ 
3 30 अ 
7 30 ा 
8 30 आ
    3 23 इ 
7 23 ि 
8 23 ई 
9 23 ी
    3 22 उ 
7 22 ु 
8 22 ऊ 
9 22 ू
    3 18 ए 
7 18 े 
8 18 ऐ 
9 18 ै
    3 24 ओ 
7 24 ो 
8 24 औ 
9 24 ौ
    3 44 ं 
7 44 ँ 
8 44 ः 
9 44 ॐ
    3 45 ऽ 
7 17 । 
8 17 ॥ 
3 12 ्
    3 2 १ 
3 3 २ 
3 4 ३ 
3 5 ४
    3 6 ५ 
3 7 ६ 
3 8 ७ 
3 9 ८
    3 10 ९ 
3 11 ०
EOF

  

 

Lessons Learnt

  1. Avoid using layers 0 and 1 while testing. Else you might need frequent restarts. Also, using kbmap command helps since it uses mouse (3rd button) to avoid restart. 

 

References

  1. Man pages kbdfs 
  2. Sample kbmap for Devanagari

 

Comments

Popular posts from this blog

Plan 9 : The Infinity Notebook

Plan 9: Quick Boot with UEFI

Plan 9: Dynamic HTML