Sometimes, even on the “desktop” you want to run a single application without access to anything else. And that is possible with a combination of Mir and snaps.
Here’s a recipe for building this.
Ingredients
mir-kiosk-desktop
This is a “stage-snap” that contains a simple, “kiosk” display server designed for running a single fullscreen application. It also provides the boilerplate for launching a single application and for registering with the display manager.
The resulting snap needs registering with the desktop manager by running:
/snap/NAME_OF_SNAP/current/desktop/setup
And also connecting the login-session-control and ‘hardware-observe’ interfaces:
snap connect NAME_OF_SNAP:login-session-control
snap connect NAME_OF_SNAP:hardware-observe
There are certain elements that needed to be included in the final snap:
parts:
mir-kiosk-desktop:
plugin: nil
stage-snaps: [mir-kiosk-desktop]
override-build: |
snapcraftctl build
sed s/\$\{SNAPCRAFT_PROJECT_NAME}/${SNAPCRAFT_PROJECT_NAME}/g --in-place $SNAPCRAFT_PART_INSTALL/desktop/setup
sed s/\$\{SNAPCRAFT_PROJECT_NAME}/${SNAPCRAFT_PROJECT_NAME}/g --in-place $SNAPCRAFT_PART_INSTALL/desktop/mir-kiosk-desktop.desktop
layout:
/usr/share/X11:
bind: $SNAP/usr/share/X11
/usr/bin/xkbcomp:
symlink: $SNAP/usr/bin/xkbcomp
/usr/share/icons:
bind: $SNAP/usr/share/icons
/usr/share/fonts:
bind: $SNAP/usr/share/fonts
/etc/fonts:
bind: $SNAP/etc/fonts
plugs:
opengl: # For Mir
wayland: # For Mir
network-bind: # For Mir (to serve X11)
login-session-control: # To start a desktop session
hardware-observe: # To start a desktop session
An example application
The other thing you need to include in your snap is an application. I’ve created an example (mir-kiosk-desktop-example) using Kodi.
For this you need to install snapcraft, check out and build the project:
snap install snapcraft
git clone https://github.com/MirServer/mir-kiosk-desktop-example.git
cd mir-kiosk-desktop-example
snapcraft
snap install --dangerous *.snap
Then you need to register with the display manager and connect the interfaces you want:
/snap/mir-kiosk-desktop-example/current/desktop/setup
/snap/mir-kiosk-desktop-example/current/connect-interfaces
After this you can log out, select “mir-kiosk-desktop-example” instead of “Ubuntu” (or “Ubuntu on Wayland”, or whatever) from the greeter menu and login to a confined desktop session running Kodi.
When you exit from Kodi you’ll be logged out of the desktop session and you’ll be back at the greeter.
Your application
Obviously, you may want to use a different application and for that you’ll have to work on the snap packaging for that application. We’re not quite at the stage yet when you can simply configure an application installed locally on your system. It has to be part of the “kiosk-desktop” snap.
To give some clues there’s a second worked example (Zoom) in the git repository. So go back the the mir-kiosk-desktop-example
build directory and type:
git checkout zoom
snapcraft
snap install --dangerous *.snap
/snap/mir-kiosk-desktop-example/current/desktop/setup
/snap/mir-kiosk-desktop-example/current/connect-interfaces
Now you can do the same things, except with Zoom.
Testing
It is convenient to test snaps like this without logging out and logging in. To make that easier you can run the snap in a “Mir-on-X” window provided by mir-kiosk:
snap install mir-kiosk
WAYLAND_DISPLAY=wayland-99 mir-kiosk
And from a second terminal:
WAYLAND_DISPLAY=wayland-99 mir-kiosk-desktop-example