1. Download the Snap package

snap download yourpackage

This will result in the following files in your current directory:

  • yourpackage_version.snap (we will continue to work with this file)
  • yourpackage_version.assert (this file can be ignored or deleted)

2. Extract the Snap package

Every Snap package is secretly just a SquashFS file, so we can extract it using unsquashfs:

unsquashfs -d yourpackage_version yourpackage_version.snap

This results in a directoy yourpackage_version/, which contains the entire contents of the Snap package.

3. Modify the Snap metadata

To enable Maliit support, we need to modify the metadata file of the Snap package. This file is located in yourpackage_version/meta/snap.yaml and can be edited using a standard text editor.

3.1 Add the maliit plug

In order to communicate with the Maliit server special permissions are required. Therefore, we need to add the maliit plug to every GUI application packaged by the Snap.

name: yourpackage
title: Your Package
...
apps:
  yourpackage: # this is the main app, it usually has the same name as the Snap package itself
    command: usr/bin/yourpackage
    ...
    plugs:
      - desktop # It will most likely already have this plug.
      - desktop-legacy # And this one maybe as well
      - ... # and some other plugs it needs
      - maliit # THIS IS THE PLUG WE ADD
  otherapp: # A Snap package might contain multiple GUI apps
    command: usr/bin/otherapp
    plugs:
      - desktop # It will most likely already have this plug.
      - desktop-legacy # And this one maybe as well
      - ... # and some other plugs it needs
      - maliit # THIS IS THE PLUG WE ADD
...

3.2 Set required environment variables

Next we need to set some environment to ensure that Qt will chose Maliit as the input method. For that we want to locate the environment section in the YAML file (or create it should it not exist) and add the following entries:

environment:
  QT_IM_MODULE: Maliit
  QT_SCALE_FACTOR: 2 # This can optionally be added to adjust the scaling of the app

4. Copy the Qt Maliit plugin into the Snap

mkdir -p yourpackage_version/usr/lib/aarch64-linux-gnu/platforminputcontexts/
cp -r /usr/lib/aarch64-linux-gnu/qt5/plugins/platforminputcontexts/libmaliitplatforminputcontextplugin.so yourpackage_version/usr/lib/aarch64-linux-gnu/platforminputcontexts/

5. Repack the Snap package

mksquashfs yoursnap_version/ yoursnap_version_mod.snap

If you need to try again/make additional changes, make sure to delete yoursnap_version_mod.snap manually before executing this command again.

6. Install the modified Snap package

snap install --dangerous yoursnap_version_mod.snap

The --dangerous flag is neccessary, because the modified Snap is no longer signed and therefore snapd does not trust it.