Development Ubuntu

Persian keyboard layout for Ubuntu phone – Part 2: Build environment

Or, how to mess with a perfectly working keyboard. Where is the Q, by the way? ?

Before making any new layout, I should first get the relevant source code and see if I can compile the package as it is, and to install the compiled package to see it in action. A quick search for “Ubuntu touch keyboard layout” landed me on this AskUbuntnu exchange, which in turn pointed me to this very useful page about keyboard layouts in the Ubuntu wiki.

The source code

The keyboard in Ubuntu touch comes from a package called ubuntu-keyboard and is hosted on Launchpad. I downloaded the repository for this package by running

bzr branch lp:ubuntu-keyboard add-persian-layout

Layouts for different languages are defined as plugins to the ubuntu-keyboard package. For example, the English layout is defined in

add-persian-layout$ ls plugins/en/*

Keyboard_en_email.qml  Keyboard_en_url.qml
Keyboard_en.qml        Keyboard_en_url_search.qml

database_en.db     englishplugin.json
englishplugin.h  overrides.csv         the_picture_of_dorian_gray.txt


From the above, files with qml suffix define key arrangements. Each of these layout variants have keys specific to their use case. For example the email layout (Keyboard_en_email.qml) has a dedicated “@” key to make it easier to type email addresses.

Compile recipe

I had no idea how to compile the ubuntnu-keyboard package. So I wrote to Mike Sheldon, an Ubuntu developer who has done many recent commits to this package. He nicely helped with the following compile recipe. Thank you Mike!

1. Start a shell session on the device: phablet-shell

2. Make the root partition writable:

sudo mount -o rw,remount /

3. Install the build dependencies:

sudo apt update
sudo apt install devscripts bzr build-essential debhelper doxygen libanthy-dev libchewing3-dev libgl1-mesa-dev libgles2-mesa-dev libglib2.0-dev libgsettings-qt-dev libmirclient-dev libhunspell-dev libpinyin7-dev libpresage-dev libxml2-utils maliit-framework-dev pkg-config python3-flake8 python3-setuptools qt5-default qtbase5-dev qtbase5-private-dev libfontconfig1-dev libfreetype6-dev libudev-dev libmtdev-dev libxrender-dev qtdeclarative5-dev qtdeclarative5-private-dev xvfb presage

4. Checkout your branch on the device:

bzr branch <your branch>

5. Run “debuild” in the root of your source checkout, this will build all the packages and place them in the directory above your source directory

6. Install the new packages:

sudo dpkg -i ../*.deb

7. As this also installs the autopilot tests the first time around you’ll need to also run:

sudo apt -f install

8. Stop the current maliit-server:

stop maliit-server

9. Restart maliit with additional debugging:

MALIIT_DEBUG=true maliit-server

I did all of the above successfully on my Nexus 4. To make sure everything has actually worked, I replaced the key for “Q” and changed it to “W”. This change does show up in the keyboard, as you can see from the image at the top of this post.

Side notes

Insufficient space on root partition

I had problems with installing the development tools (step 3 above): packages failed to install due to insufficient storage in the root partition of my Nexus 4. I uninstalled many apps to free some space. At the end, I had to completely wipe the phone and install a fresh Ubuntu image. Even more, I had to also delete some not-crucially-needed system directories

sudo rm -r /usr/share/locale-langpack/[!en]*

This is a terrible thing to do on a production system. But since I use the Nexus 4 only for development, it just provided me with the much needed free space to install dev tools.

Difficulty in editing files on the phone

Since editing any text file on the phone is very difficult, I did all the actual edits on my desktop machine, synced  it to my ownCloud instance, and downloaded the edited files via wget.

Compile process stopped by the phone OS

Each compile takes about 45 minutes to complete. During compilation, if I switch out of the terminal app, or if the phone is locked after a few minutes of inactivity, the compile process is stopped by the OS. I assume this is done to all app in order to save power. To prevent this, I disabled screen locking in Setting -> Security and Privacy -> Locking and unlocking.

What’s next?

In the next posts, I will continue to document my work on making a Persian layout for Ubuntu phone. Meanwhile, I’d love to hear your comments. If you are expert in Ubuntu touch development, do you see something that I am doing wrong or inefficient? If you are an Ubuntu phone end user, do you need a particular keyboard layout to be added or fixed?

1 reply on “Persian keyboard layout for Ubuntu phone – Part 2: Build environment”