Spring 2017/Making a keyboard layout

From LING073
Jump to: navigation, search

Classroom activities

Using a keyboard already on your system

The desktop environment that the virtual machines logs in to is Cinnamon, which is based on Gnome2. The instructions here will assume that this is what you're using, though there are a number of other linux desktop environments out there, where these instructions may need to be tweaked a bit.

  1. Open keyboard settings. One way to do this is to right click on an empty part of the panel/bar at the bottom of the screen and click "All Settings"; then find "Keyboard". (Alternatively, just click the "Menu" button at the bottom left and type "Keyboard" and press enter.)
  2. Go to the "Keyboard layouts" tab and add ("+" button) a layout of your choice. Something obviously different from the US English layout (like Russian or Hebrew) might be good for testing.
  3. Set up three keys: an Alt-Gr / 3rd level key (recommended: right ‹Alt›), a compose key (recommended: left Windows key), and a layout-switching key (recommended: ‹Caps Lock› OR left ‹Alt›+‹Shift›). In the Keyboard layouts window, click "Options..." (bottom right), and find the following (respectively): "Key to choose 3rd level", "Position of Compose key", and "Switching to another layout".
  4. Test your keys in a text editor.
    • You can preview your keyboard to see if 3rd-level options exist (they're to the left of the normal key values), and if they don't, you can try adding a keyboard layout like "Russian (Kazakhstan, with Kazakh). Then ‹Alt-Gr› + ‹f› should print "ә" (Cyrillic [æ] letter).
    • Using an English keyboard layout, you can test your Compose key as follows: press ‹Compose› once, press ‹e› twice; this should print "ə" (Latin-alphabet schwa letter). Try other combinations, like ‹Compose› + ‹t› + ‹h›, or ‹Compose› + ‹=› + ‹E›.

Adding an existing xkb layout to your system

For this exercise, you're going to download and install a Latin-alphabet layout I made that supports several Turkic languages as well as quite a bit of IPA.

  1. Download the tks file listed in my keyboard repo on github. You can click on the file, and the click raw, and save that, or you can simply use a terminal by typing something like wget https://raw.githubusercontent.com/jonorthwash/keyboards/master/xkb/tks.
  2. Put the tks file in /usr/share/X11/xkb/symbols. You can use the cp command to do it, and you'll probably need to use sudo too. E.g. sudo cp tks /usr/share/X11/xkb/symbols/
  3. Add a layout entry in the /usr/share/X11/xkb/rules/evdev.xml file for the layout. To do this, edit that file with your favourite text editor (again, you'll probably need sudo), and search for the end of the layoutList section by searching for </layoutList> in the file. Copy a simple layout block from above that line, paste it in as a new layout block (between the last </layout> and </layoutList>and modify it for this layout. You can use something like this:
            <description>Jonathan's Turkic and IPA layout</description>
  4. Save the file, exit the editor, and restart cinnamon. The quickest way to do this is to run cinnamon --replace on the command line.
  5. Go back to your keyboard layout settings, and you should be able to find the layout under "Jonathan's Turkic and IPA layout" in the list.
  6. Note: now when you switch layouts, you'll notice that this layout has no flag associated with it in the keyboard selector on the bottom panel. Since flags are not languages (and certainly aren't keyboard layouts), this is kind of silly, and might be good to disable. To do this, simply right click on the keyboard layout selector, click "Configure..." and uncheck "Use flags to display keyboard layouts".
  7. Try typing ‹Alt-Gr› + ‹shift› + ‹e›. This should display "ə" (Latin-alphabet schwa letter).
  8. Look in the tks file to see where this combination is specified. It's on the fourth level (‹shift› normally gives you second-level access, ‹Alt-Gr› gives you third level access, and their combination gives you fourth-level access). Get the line number.

Issues to consider

Technical issues

  • Many-character input (e.g., kana)
  • Compose key versus dead keys versus key combinations versus adding characters to the keyboard

Design issues

  • What to base your input method on
    • Is there a layout used in the region that already has all the characters available? Or is one character short?
  • Use of other languages

What not to do

  • Which of these xkb keyboard layouts do you think Kazakh speakers in Kazakhstan prefer to use to type Kazakh, and why? The "Russian" layout is the modern standard Russian keyboard layout, and the "Kazakh" layout has been available in Windows for at least 15 years or so. Almost all Kazakh speakers in Kazakhstan also speak Russian (but not all Russian speakers in Kazakhstan also speak Kazakh).
Kazakh (with Russian)

Russian (Kazakhstan, with Kazakh)

Using IBus

Some of you will be working with keyboard layouts that require a "dead key" approach—i.e., you need to type two or more keys in a row to get a given character. This is particularly common for languages with so-called CJK (Chinese, Japanese, Korean) orthographies, but could be equally as useful for something like https://en.wikipedia.org/wiki/Canadian_Aboriginal_syllabics or even a language where you want to have a non-standard sort of combination key (like typing ‹+› ‹p› to get "p̌" or something).

To use IBus

  1. first install IBus and the m17n features:
    sudo apt-get install ibus-m17n
  2. Then enable IBus as your default input method:
    im-config -n ibus
  3. Restart X11 on the VM (log out and log back in), and you should have a hard-to-see language switcher icon next to the time in your lower panel. Right click on that and click preferences.
  4. Go to the "Input Method" tab and you can add various keyboard layouts. Note that you have to press the "..." button at the bottom to see all the categories supported, and that there are a lot of layouts hidden under the various categories.
  5. You'll have to configure a "next layout" key combination that makes sense for you.

Developing a keyboard layout in IBus

  1. You should be able to copy a file in /usr/share/m17n/ to a different name and configure it to your liking. The layout files have the extension .mim
  2. You'll probably need to restart IBus for the new file to become available or for any further modifications to it take effect: right click on the hard-to-see IBus icon and click "restart".

The Assignment

Create an xkb keyboard layout for your language in linux. This assignment is due at midnight at the end of the day on Friday (January 27, 2017-though technically midnight at the beginning of Saturday).

Where to submit

You will submit this assignment in a new git repository titled ling073-xyz-keyboard, where xyz is the three-letter ISO code of your language. Make sure to make it a public repository, and/or a private repository to which I have access. You will also be asked to put some things on a wiki page titled Language/Keyboard, where Language is the name of your language (a page which should already exist). Add the category Keyboard layouts to the page. You should also adjust your original Language page: move all the documented resources under a "External resources" section (you'll probably want to add an extra layer of =s to your current headings), create a new "Developed resources" section, and add a link to both the keyboard page on the wiki and the keyboard repository in git.

Background Research

To the wiki page for your keyboard, add a section on existing resources. List any any keyboard layouts that already exist for your language. Check all operating systems you can think of—linux and Windows on the workstations in class, Macs around campus, Android and iOS phones or tablets—whatever you have access to or comes up in a web search.

You may find that some keyboard layouts are not included in the standard OS, but are available for download or through an app store. There may also be old "fake" layouts, in the form of a font that replaces unused character points with characters of the language. Try searching in your language or a larger regional language if you can.

Does there seem to be a standard layout, available across platforms? Briefly discuss the similarities and differences between the layouts you find, and what you think are strengths or weaknesses of these particular layouts.


If there are existing layouts, you need to choose one. If not, for ease of use, it might make sense to base the layout on something likely to be common in the area. However, this can fail in several different ways, as seen with the Kazakh example above:

  • It could seem like the less-well-resourced language is being thought of as "derived from" or a "variant of" the better-resourced language.
  • It could become difficult to type on the new layout because of awkward placement of symbols:
    • "extra" symbols placed on e.g., number row
    • "extra" symbols placed on third row (Alt-Gr)
    • characters of the original layout are replaced with symbols of the new layout (and removed or rearranged)
    • symbols of the original layout are rearranged (!)
  • While it could be useful to maintain support on the same keyboard layout for other languages speakers might use (e.g., a larger language in the area or English), it isn't necessarily crucial: speakers can always just use an alternate keyboard layout.

Document your justification for each decision you made, whether it relates to existing keyboards for the language or the modification of some other layout. Include this in a file entitled README in your new repository, and in a section called "Justification" on the wiki page (see #Where to submit above).

Development cycle

For xkb layouts, the steps to develop a keyboard are generally something like this:

  1. Make a copy of an existing layout from /usr/share/X11/xkb/symbols/ and name it something else (e.g., the 3-letter ISO-639 code for your language).
  2. Add an entry for the language in the /usr/share/X11/xkb/rules/evdev.xml file.
  3. Modify the new file and adjust it as needed for your language.
  4. Make sure the new layout is in the symbols directory and then reload cinnamon (cinnamon --replace).
  5. Add the layout to your list of active layouts, and switch to it to test it out.
  6. Make more modifications and restart cinnamon to continue testing.

Some of you may be submitting keyboards using something other than xkb (like ibus). This is okay, but you'll need to figure out some of the how-to parts and development cycle on your own. Let me know if you need help, though!

Other things to document

  • Document the steps needed to install your keyboard layout. It might be good to test this on a VM on one of the other workstations in the classroom. Write up the steps in an INSTALL file in the repository and under an "Installation" section on the wiki (write it up in one place and transfer it over—i.e., try to keep them in sync).
  • Add an AUTHORS file in the repository and put your name (or alias) and email address there.
  • Decide on an open-source license for your keyboard layout and include the text of the license in a LICENSE file in the repo. Add a mention of how it's licensed on the wiki page.
  • Include a screenshot both on the wiki page and in your repository!

Extra steps

If designing your keyboard layout involves only minor changes to an existing layout (such as adding one or two letters to 3rd-level positions) or none, then also do one of the following:

  • Make a "transcription" layout that includes most phonetic symbols needed to transcribe your language. This should include IPA symbols and any symbols used in academic transcriptions of the language.
  • Set up some Compose-key combinations for your language. E.g., for Kazakh, ‹-› could compose with ‹о›, ‹ү›, and ‹г› to result in ‹ө›, ‹ұ›, and ‹ғ›, respectively, while ‹,› could compose with ‹к› and ‹н› to result in ‹қ› and ‹ң›, respectively. (There are only three more letters in Kazakh that aren't in Russian too: ‹ә›, ‹і›, ‹һ›.) Don't forget upper-case characters too (if relevant)!
  • Make your keyboard capable of being used to type not just your language, but a range of related languages, or other languages spoken in the area, or other languages of cultural import to the community. You can do this in part using the compose key idea above, so that with the Kazakh example above, ‹,› could combine with ‹х› to create the Uzbek and Tajik letter ‹ҳ›, with ‹ч› for the Tajik letter ‹ҷ›, with ‹с› and ‹з› for the Bashqort and Chuvash letter ‹ҫ› and the Bashqort letter ‹ҙ›. You could also do something similar with dead keys or combining diacritical marks, which are like using Compose combinations except that you don't need Compose (though dead key strategies aren't easily implemented in xkb for non-Latin orthographies). You may try another input options, such as iBus, for things like this, though that requires a certain amount more effort. If you just use xkb, make sure you support the full orthography of at least two other languages besides your language and the larger language whose keyboard you're basing this on.
  • Make (an) additional keyboard layout(s) for (an)other orthography / orthographies that the language is written in, e.g. a script in use in another country, or a script that's no longer used.
  • Make an ibus layout for the orthography of Nivkh that is essentially a standard Russian layout but with two dead keys—one for stroke (-), one for hook (̡)—that combine to produce all the characters of the Nivkh alphabet. See table 2 in the Nivkh paper on Moodle for another overview of the alphabet, and see table 3 for why this is an important project!

Add what you did to the README file and the "Justification" section on the wiki.