Introduction

Some time ago I started writing some articles about how easy it is to write a shell based on MirAL. With subsequent events that work has been neglected. But with the recent release of MirAL 2.0 in Mir 0.31 I decided to update the code that accompanied these articles.

This is the result.

Preparation

The code in this article needs Mir 0.31 or later. This exists in Ubuntu 18.04 and Fedora 28 (both unreleased at the time of writing), or from the mir-team/release PPA.

It is also useful to install the weston package as the example makes use of weston-terminal as a Wayland based terminal application and the Qt toolkit’s Wayland support : qtwayland5.

egmde [Example Mir Desktop Environment]

To illustrate MirAL I’m going to show what is involved in writing a (very simple) window manager. It runs on desktops, tablets and phones and supports keyboard, mouse and touch input. It will support applications using the GTK and Qt toolkits, SDL applications and (using Xwayland X11 applications.

Naturally, the code is likely to evolve, so you will find other branches, but this branch goes with this article. Assuming that you’ve MirAL installed as described above you can now build egmde as follows:

$ mkdir egmde/build
$ cd egmde/build
$ cmake ..
$ make

After this you can start a basic egmde based desktop. This will use VT4, so first switch to VT4 (Ctrl-Alt-F4) to sign in and switch back again. Then type:

$ ./egmde-desktop

You should see a blank screen with a weston-terminal session. From this you can run commands and, in particular, start graphical applications. Perhaps qtcreator to examine the code?

Conclusion

The example code

A lot of the functionality (default placement of windows, menus etc.) comes with the MirAL library. For this exercise we’ll implement one class and write a main function that injects it into MirAL. The main program looks like this:

I wonder if freedesktop.org would accept MIR, MirAL and Egmde as an official upstream project under its umbrella.

In an ideal world GNOME-SHELL/Mutter and KWIN would switch to MIR as much as technically feasible and thus share more code between those projects. If MIR sat between mutter and the display stack (wayland/mesa) as some kind of display server (like X was), a lengthy complete gnome-shell rewrite could probably be avoided. This display server idea stems from the GNOME4 proposal (Option B): https://wiki.gnome.org/Initiatives/Wayland/GnomeShell/GnomeShell4

Thanks much for the reply! If interested, more info about gtk3-nocsd is available here. And here’s a snippet from the “how it works” section for gtk3-nocsd:

$LD_PRELOAD is used to override several Gdk and glib/gobject APIs to intercept related calls Gtk+ 3 uses to setup CSDs. For older versions of Gtk+ 3, while it is trying to initialize CSDs, it is led to believe that there is no compositor available, so CSDs are not added. For later Gtk+ 3 versions (3.16.1+), the gtk_window_set_titlebar method is reimplemented, as tricking Gtk+ 3 into thinking the compositor is disabled has side effects and is not sufficent anymore.

Additionally, as gtk_window_set_titlebar is also called from Gtk+ internally (and LD_PRELOAD cannot override function calls within a library), several other places in Gtk+3 (e.g. buildable interfaces for GtkWindow and GtkDialog) are also overridden to ensure that CSDs are disabled.