Creating Graphical Shells – Try Mir in a Virtual Machine

Alan Griffiths

on 25 February 2021

This article was last updated 3 years ago.


What is Mir?

Mir is a set of libraries for creating graphical shells for Linux on a range of hardware. This means that there are a number of shells based on Mir and they work on some very different form factors. Mir is what glues together the “shell” experience, the applications and the hardware:

Mir works with the modern Wayland protocol which, in principle, provides many advantages over the traditional X protocol used by legacy systems. With Wayland becoming more widely supported the practice is now catching up with the theory.

There are a range of graphical shells created with Mir ranging from the simple “kiosk” used for IoT by the mir-kiosk snap to the Lomiri shell used by the Ubuntu Touch phone.

We have made it simple to try out a range of Mir-based shells in a virtual machine. This should give you some idea of the possibilities of using Mir.

Creating a virtual machine for Mir Desktop

We’re going to use Multipass to create a virtual machine [VM] and, as we’re going to use “X-forwarding” we’ll also assume that you have an ssh client and an ssh key set up on your computer. To install Multipass:

snap install multipass

We’re also going to use a utility script to facilitate the setup. This is shown in full here, and is available from github:

git clone https://github.com/AlanGriffiths/multipass-utils
cd multipass-utils

To create the VM:

./mir-demos

Choose the Mir server you'd like to try ("0" to exit):
1) egmde
2) miral-app
3) miral-app -kiosk
4) miral-app -demo-server
5) miral-app --window-manager tiling
6) cp --force .Xauthority snap/mircade/current/&&mircade
7) cp --force .Xauthority snap/egmde-confined-desktop/current/&&egmde-confined-desktop
#?

We have created a VM called “mir-demos” which has been set up for running some Mir shells on your current desktop environment. The script can be used again to restart, or reconnect to the same VM. To make this faster, this is left running by default, but you can stop it with “multipass stop mir-demos” or delete it with “multipass delete --purge mir-demos”.

The example shells

1) egmde

Egmde is a “worked example” of building a desktop shell with Mir, there are some tutorials for developers interested in how it works on the Mir forum.

You can launch applications using Ctrl-Alt-A and scrolling. But, because there are not many apps installed in this “bare bones” VM, you don’t get a lot of choice. However, you can use the terminal (Ctrl-Alt-T) to install more.

Installing wallpaper

To add wallpaper we need both the actual wallpaper and a program to show it. For this example we’ll use the ubuntu-wallpapers package and swaybg. In the terminal in the VM type:

sudo apt install swaybg ubuntu-wallpapers

As the egmde configuration doesn’t (currently) allow parameters to be passed to “shell components” we need a simple script to do that:

mkdir bin
cat > bin/my-swaybg <<EOF
#!/bin/sh
exec swaybg -i '/usr/share/backgrounds/warty-final-ubuntu.png'
EOF
chmod +x bin/my-swaybg

We now need to tell egmde that my-swaybg is a “shell components” which allows it to become a background.

echo "shell-components=my-swaybg" >> ~/.config/egmde.config

Now close the session with Ctrl-Alt-BkSp and start it again:

It is possible to install other “shell components” such as Waybar and MATE-panel with a similar approach. First install them, then add them to shell-components in ~/.config/egmde.config. They may need a little tweaking to integrate with Mir, but they basically work.

Installing other apps

As mentioned above, other applications can be installed using snap or apt from the terminal. For example:

sudo apt install neofetch
sudo snap install gnome-chess

These can be launched via egmde’s Ctrl-Alt-A app launcher:

2) miral-app

There are some other Mir shells provided in the mir-demos and mir-test-tools packages. “miral-app” is a script to run these and the next few examples use this. These are simpler than the egmde example, but help show the range of possibilities.

The first of these “miral-app” runs the default miral-shell:

3) miral-app -kiosk

This runs the same “kiosk” server used in the popular mir-kiosk snap. The “kiosk” server would be fairly useless without a way to launch applications, so the script also connects a terminal to it from which you can run other applications. With this server everything runs fullscreen:

4) miral-app -demo-server

The Mir “demo server” is useful for testing as it enables all the Wayland extensions supported by Mir. This is particularly useful if you are testing shell components (panels, backgrounds etc.) as all the Wayland extensions needed by these are enabled by default. (They can be configured for other shells, and egmde only enables them for “shell components”)

Try starting miral-app -demo-server and then in the terminal that comes up:

sudo apt install swaybg ubuntu-wallpapers mate-panel
swaybg -i /usr/share/backgrounds/warty-final-ubuntu.png &
mate-panel&

There will be a few error dialogs from Mate Panel as some widgets don’t work or are not installed. If you select “Delete” they are removed from the panel and won’t bother you again.

6) cp –force .Xauthority snap/mircade/current/&&mircade

Mircade is an example of a shell designed to run one fullscreen application at a time. In order to have a theme to these applications a few games were chosen from the archive. Obviously, you could do something similar with your choice of applications.

All the above examples have been examples of shells running in an “unconfined” environment. In contrast, these last two examples, mircade and the egmde-confined-desktop, work with full Snap confinement. Consequently, they can be used on the snap based, Ubuntu Core operating system.

Using Snap confinement means that launching this demo needs the “.Xauthority” file copying to the “right place” to be used by the snap. This makes these options look a little different.

7) cp –force .Xauthority snap/egmde-confined-desktop/current/&&egmde-confined-desktop

Egmde-confined-desktop, like mircade, is a fully confined snap. Like mircade, it can only run applications that are contained within the snap. (This is currently a limitation of the snap environment. Within this limitation, egmde-confined-desktop provides something close to a desktop environment, with floating windows and a more diverse set of example applications.)

The mir-demos script for configuring the VM

This section is simply for information. If you don’t want to see how the script work you can simply run the demos.

$ cat mir-demos
#!/bin/bash
set -euo pipefail

vm_name="${1:-mir-demos}"

until command -v multipass > /dev/null
do
  echo "Multipass is not installed, do you wish to install it?"
  select install in "Yes" "No"; do
    case $install in
      Yes ) sudo snap install multipass; break;;
      No ) break;;
    esac
  done
done

if ! multipass start "${vm_name}"
then
  set -x
  multipass launch -v -n "${vm_name}" --cloud-init - <<EOF
apt:
  preserve_sources_list: true
  sources:
      mir-team:
          source: 'ppa:mir-team/release'
ssh_authorized_keys:
    - $(cat ~/.ssh/id_rsa.pub)
packages:
    - xwayland
    - fonts-freefont-ttf
    - xfce4-terminal
    - epiphany-browser
    - mir-graphics-drivers-desktop
    - mir-demos
    - mir-test-tools
runcmd:
    - sudo snap install --classic --candidate egmde
    - sudo snap install mircade
    - sudo snap install --edge egmde-confined-desktop
EOF
  multipass exec "${vm_name}" -- mircade --help > /dev/null || true
  multipass exec "${vm_name}" -- egmde-confined-desktop --help > /dev/null || true
  multipass exec "${vm_name}" -- sh -c "mkdir --parents ~/.config"
  multipass exec "${vm_name}" -- sh -c "if ! grep -q no-of-workspaces= ~/.config/egmde.config; then echo no-of-workspaces=4 >> .config/egmde.config; fi"
  multipass exec "${vm_name}" -- sh -c "if ! grep -q enable-autostart= ~/.config/egmde.config; then echo enable-autostart=  >> .config/egmde.config; fi"
  set +x
fi

host_ip=$(multipass info "${vm_name}" --format csv | awk -F, '/^'"${vm_name}"'/ { print $3 }')

while :
do
  echo "Choose the Mir server you'd like to try (\"0\" to exit):"
  select demo in "egmde"\
             "miral-app"\
         "miral-app -kiosk"\
         "miral-app -demo-server"\
                 "miral-app --window-manager tiling"\
                 "cp --force .Xauthority snap/mircade/current/&&mircade"\
                 "cp --force .Xauthority snap/egmde-confined-desktop/current/&&egmde-confined-desktop"
  do
    if [ "$demo" = "" ]; then exit 0; fi
    ssh -X "ubuntu@${host_ip}" sh -lc "\"$demo\""
    break
  done
done

Summary

This “mir-demos” virtual machine allows you to try some of the graphical shells that can be built with Mir. These range from a desktop environment for a desktop computer to a single fullscreen application for embedded systems.

You can confirm that applications work well with Mir by installing and running them in the VM.

If none of the example Mir shells demonstrated here are quite right for your needs, it is really simple to build your own as the egmde project shows.

Did you enjoy this tutorial? Are you using Mir to power your next smart display? We’d love to hear about you and your Mir project. Send a summary to mir.community@canonical.com, and we’ll be in touch.

Internet of Things

From home control to drones, robots and industrial systems, Ubuntu Core and Snaps provide robust security, app stores and reliable updates for all your IoT devices.

Newsletter signup

Get the latest Ubuntu news and updates in your inbox.

By submitting this form, I confirm that I have read and agree to Canonical's Privacy Policy.

Related posts

Mir support for Wayland

What is Mir, what is Wayland, do I care? Shells for graphical interfaces come in many forms, from digital signage and kiosks that just show a single full...

Mir 2.5, incorporating new features to improve the development of embedded graphic applications

With another release of Mir, we have prepared a new blog with the a roundup of the product’s newest features. Mir is our flexible display server that provides...

Mir 2.4, enhancing digital signage and smart screen development

Another cycle brings another release of Mir, with new features and new innovative use cases. For those of you new to Mir, our flexible display server provides...