Sunday, March 6, 2016

Mac like Hindi / Sanskrit Keyboard in Ubuntu 14.04

Mac Keyboard was the most intuitive one I ever came across for typing Devanagari (देवनागरी). MacBook has two dedicated keys for क्ष & ज्ञ. I don't know the unicode key set for these two letters to make a dedicated keys.

2011 MacBook Pro blue screen of death - this post describes what to do in case you ran out of all options on your Macbook Pro. Well in my case I did run out of all options and I choose to wipe it clean and start with free OS - Ubuntu Linux instead of spending another $2499+tax to get new one.

Installing Ubuntu 14.04 was breeze. Everything was great at first, then I realized that Unicode keyboard is not same. That meant waste a lot of time to learn a new type of keyboard layout. Instead I decided to customize existing unicode layout called Bolnagari to appear more like MacBook.
This post describes how to get Hindi keyboard on Mac

Hindi keyboard in Ubuntu has many variations. MacHindi is the one  I created for my personal use to replicate MacBook Pro.


Post below gives more information about understanding the folders and its purpose and whole keyboard layout.

Step - 1  - cd to this folder
cd /usr/share/X11/xkb/symbols/

Step - 2  - Back up Indian Keyboard layout "in"- This is to save original incase you mess something up, you can delete "in" layout and create it back from backup.

sudo cp in in_backup

Step - 3 - Open "in" layout to modify. This is a system level file so it would not allow you to modify and save without sudo command.  You can pick your fav text editor I was ok with gedit.
sudo gedit in

Step - 4 
// This is the code created by SitaRaama to replicate Devanagari input method just like MacBook Pro
//Name        :    Machindi (Combined)
//Description    :    Replica of Macbook Pro Keyboard for Devanagari Input
//            https://ubcsanskrit.ca/keyboards.html
//NOTE        :     Replica of MacBook Pro Keyboard
//Inspired by "devrom" keymap by Steve Smith for the windows tool "keyman"
//Original Author :    Noah Levitt<nlevitt at columbia.edu>
//Past Authors  : Raamakoti (raamakoti at gmail.com)
//Current Main. :

partial alphanumeric_keys
xkb_symbols "machindi" {
     name[Group1] = "Hindi (machindi)";
     key.type="FOUR_LEVEL";
    //Top Alphanumeric row
    // Roman digits
   
// 6 Desired Levels - The reason for 6 levels is to stop switching between English and Hindi Keyboard. In Mac you can work both languages with one keyboard layout
// No Modifier Keys
// Shift
// Option
// Shift + Option
// Caps Lock
// Shift Caps Lock

// key<AE01> { [ Level 1 , Level 2 , Level 3 , Level 4 , Level 5, Level 6 ] }
// key<AE01> { [ No modifier Keys , Shift , Option , Option+Shift , Caps Lock, Caps Lock + shift ] }

// key<AE01> { [ No modifier Keys , Shift , Option , Option+Shift } ]
// for this keyboard laytouts only four levels are used.

    key <TLDE>  { [   U0902,    U0901,        apostrophe,     asciitilde ] }; // apostrophe: anusvara, candrabindu
    key <AE01>  { [   U0967,    exclam,        1,        1F549       ] };
    key <AE02>  { [   U0968,    at,        2,        at       ] };
    key <AE03>  { [   U0969,    numbersign,     3,        numbersign ] };
    key <AE04>  { [   U096A,    dollar,        4                ] }; // Rupee symbol on AltGr+4
    key <AE05>  { [   U096B,    percent,    5,        percent    ] };
    key <AE06>  { [   U096C,    asciicircum,    6,        asciicircum ] };
    key <AE07>  { [   U096D,    ampersand,    7,        ampersand  ] };
    key <AE08>  { [   U096E,    asterisk,    8,        asterisk   ] };
    key <AE09>  { [   U096F,    parenleft,    9,        parenleft  ] };
    key <AE10>  { [   U0966,    parenright,    0,        parenright ] };
    key <AE11>    { [   minus,    underscore         ] };
    key <AE12>    { [   equal,    plus             ] };
    key <BKSL>  { [   U0964,    U0965,        U007C,        U005C   ] }; //pipe : danda, double danda

    //Q Row   
    key <AD01>   { [   U200D,     U200C   ] };  // Q: ZWNJ, ZWJ
    key <AD02>   { [   U0905,      U0906    ] };  // W: अ, अा
    key <AD03>   { [   U0947,   U0948,    U090F,    U0910   ] };  // E: े, ै , ए, ऐ
    key <AD04>   { [   U0930,    U0943,    U090B,  U0944      ] };  // R: र, ृ, ऋ, ॄ
    key <AD05>   { [   U0924,   U0925,  U091F,  U0920  ] };  // T: त, थ
    key <AD06>   { [   U092f,    U091E,  U095F ] };  // Y: य, ञ, य़
    key <AD07>   { [   U0941,   U0942,    U0909,    U090A   ] };  // U: ु, ू , उ, ऊ
    key <AD08>   { [   U093F,   U0940,    U0907,    U0908   ] };  // I: ि, ी, इ, ई
    key <AD09>   { [   U094B,   U094C,    U0913,    U0914   ] };  // O: ो, ौ, ओ, औ
    key <AD10>   { [   U092A,   U092B   ] };  // P: प, फ
    key <AD11>   { [   bracketleft,   braceleft   ] }; 
    key <AD12>     { [   bracketright, braceright   ] };
   
    //A Row
    key <AC01>   { [   U093E,     U093E,  U0905, U0906 ] };   // A: ा, ा, अ, आ
    key <AC02>   { [   U0938,    U0936   ] };  // S: स, श,
    key <AC03>   { [   U0926,    U0927,  U0921, U0922  ] };  // D: द, ध, ड, ढ
    key <AC04>   { [   U094D,    U093C  ] };  // F: ्, ़
    key <AC05>   { [   U0917,    U0918   ] };  // G: ग, घ
    key <AC06>   { [   U0939,    U0903   ] };  // H: ह,ः
    key <AC07>   { [   U091C,    U091D, U091E   ] };  // J: ज, jha
    key <AC08>   { [   U0915,    U0916, U1CF2   ] };  // K: क, ख
    key <AC09>   { [   U0932,     U090C,    U0962  ] };  // L: ल, ऌ,  ॢ
    key <AC10>   { [   semicolon, U0903  ] };
    key <AC11>   { [apostrophe, quotedbl, U093D ] };

    //Z Row
    key <AB01>   { [   U0919,     U0901,  U0951, U090D      ] };  // Z: ङ, ँ, ॑,॒
    key <AB02>   { [   U0937,    U0949,  U0952, U0911     ] };  // X: ष, ॉ,
    key <AB03>   { [   U091A,    U091B,  U0973  ] };  // C: च, छ, ॳ
    key <AB04>   { [   U0935,    U0922,  U0974  ] };  // V: व, ढ, ॴ
    key <AB05>   { [   U092C,    U092D   ] };  // B: ब, भ
    key <AB06>   { [   U0928,    U0923,  U091E   ] };  // N: न, ण, ञ
    key <AB07>   { [   U092E,    U0902,     U0950,    U093D   ] };  // M: म, ं, ॐ
    key <AB08>   { [   comma,    U0970     ] };// comma: comma, ॰,
    key <AB09>   { [   U0964,   U0965,   U0966     ] };  // । , ॥, ०
    key <AB10>     { [   slash,   question ] };

//    modifier_map Shift  { Shift_L };
//    modifier_map Lock   { Caps_Lock };
//    modifier_map Control{ Control_L };
//    modifier_map Mod3   { Mode_switch };

    include "level3(lalt_switch)"
    include "rupeesign(4)"
};
// This is the end of edits from Sita Raama 
 
 save and close the "in" file.

Step - 5 - Now add Machindi to keyboard layout to search-able list
go /usr/share/X11/xkb/rules 
 edit evdev.xml - Find for Bolnagari and below code
       <variant>
          <configItem>
            <name>machindi</name>
            <shortDescription>hi</shortDescription>
            <description>Hindi (machindi)</description>
            <languageList>
              <iso639Id>hin</iso639Id>
            </languageList>
          </configItem>
        </variant>

Step - 6
Open evdev.lst file and add MacHindi before or after Bolnagari - save and exit. Technically you can add anywhere you like but I did it to keep both layouts next to each other. 

 Step - 7 Almost done - Go back to terminal and run following command.
sudo dpkg-reconfigure xkb-data

Step - 8  logout - log back in
If that does not work restart. Logout and logback in one more time.

Special Note: - 
At the end of the code it has - "include "level3(ralt_switch)"
ralt = right alt key
lalt = left alt key.  My personal preference was left side "Alt" key.

Enjoy MacBook Pro like Devangari Keyboard on Ubuntu 14.04