Journal Articles
Browse in : |
All
> Journals
> CVu
> 314
(8)
All > Topics > Design (236) Any of these categories - All of these categories |
Note: when you create a new publication type, the articles module will automatically use the templates user-display-[publicationtype].xt and user-summary-[publicationtype].xt. If those templates do not exist when you try to preview or display a new article, you'll get this warning :-) Please place your own templates in themes/yourtheme/modules/articles . The templates will get the extension .xt there.
Title: Making a Linux Desktop
Author: Bob Schmidt
Date: 07 September 2019 17:27:40 +01:00 or Sat, 07 September 2019 17:27:40 +01:00
Summary: Alan Griffiths illustrates how to get started with Mir.
Body:
I’m working on a project (Mir) that, among other things, aims to make it easy to develop graphical ‘desktop environments’ for Linux.[1] There are a lot of features that are common between all designs for desktop environments and, in addition, a lot that are common between the majority of designs. For example, it is common for applications to draw ‘windows’ and for these to be combined onto the screen.
By providing the common features, and for the rest offering both sensible defaults and an easy way to customise them, Mir is designed to support a range of possible designs.
Last year, I wrote an article for CVu [2] about a simple graphical shell. Since then, there have been improvements in the ‘out of the box’ facilities offered by the Mir libraries and I’m revisiting the subject.
This is the first of in a new series of articles that illustrate the development of an Example Mir Desktop Environment. [3]
Wayland
Most current desktop environments for Linux are based on X11. This is the last in a line of protocols for communicating between the applications, and parts of the ‘desktop environment’. However, the environment in which it works has changed somewhat since the 1980s. That means many fundamental design decisions needed to be re-evaluated.
The result of this re-evaluation is a new protocol: ‘Wayland’. This has been implemented for a number of application ‘toolkits’ and desktop environments. Instead of being based on X11, Mir supports the newer Wayland protocol.
Preparation
The code in this article needs Mir 1.2 (or later). On Ubuntu 18.04 (and later) this is available 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. And finally, the g++ compiler and cmake.
$ sudo apt-add-repository ppa:mir-team/release $ sudo apt install libmiral-dev mir-graphics- drivers-desktop $ sudo apt install weston qtwayland5 $ sudo apt install g++ cmake
At the time of writing, Mir 1.2 isn’t available on Fedora. But I hope that will be resolved by the time you read this:
$ sudo dnf install mir-devel $ sudo dnf install weston qt5-qtwayland $ sudo dnf install gcc-c++ cmake
Mir is also available from the Arch AUR and can be built from source for many versions of Linux.
Egmde
This series of articles follow the development of a very simple desktop environment. Because this is an example, don’t expect it to be polished to a production level. But it is usable and could be the basis for further work.
Building the example
The full code for this example is available on github:
$ git clone https://github.com/AlanGriffiths/ egmde.git $ git checkout Article-1
Naturally, the code is likely to evolve, so you will find other branches, but the Article-1 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
Running the example
After this you can start egmde:
$ ./egmde
You should see a black Mir-on-X window with a cursor. You can launch a terminal window with Ctrl-Alt-T (or, if that conflicts with your desktop, Ctrl-Alt-Shift-T).
You should see the same black screen with a weston-terminal window. From this you can run commands and, in particular, start graphical applications. Perhaps qtcreator to examine the code?
You should find that you can do all the normal things – use the keyboard and mouse to switch between and resize windows. If you have a touchscreen, then that will work too.
Running a full desktop type session is also possible, but first I should mention that it is possible to close egmde using the keyboard combination Ctrl-Alt-BkSp. Now switch to a virtual terminal (Ctrl-Alt-F4 for example) log in and run egmde-desktop.
Installing the example
If you install egmde, it will be added to the greeter menu (typically a ‘cog wheel’ on the sign-on screen):
$ sudo make install
Depending upon the greeter used on your system, it may be necessary to reboot before egmde appears as a login shell.
Installing the example
To register applications with desktop environments we install a .desktop file in /usr/share/applications and to register Wayland based desktops with the greeter we install a .desktop file in /usr/share/wayland-sessions/. The content needed for both cases is similar, so for this example we use the same .desktop file and install it to both places.
The example code
A lot of the functionality (default placement of windows, menus etc.) comes with the MirAL library. This means that there’s very little code needed to get this basic shell running:
$ wc -l *.cpp 75 egmde.cpp
The main program for this article is shown in Listing 1.
using namespace miral; int main(int argc, char const* argv[]) { MirRunner runner{argc, argv}; ExternalClientLauncher external_client_launcher; auto const keyboard_shortcuts = [&](MirEvent const* event) { if (mir_event_get_type(event) != mir_event_type_input) return false; MirInputEvent const* input_event = mir_event_get_input_event(event); if (mir_input_event_get_type(input_event) != mir_input_event_type_key) return false; MirKeyboardEvent const* kev = mir_input_event_get_keyboard_event (input_event); if (mir_keyboard_event_action(kev) != mir_keyboard_action_down) return false; MirInputEventModifiers mods = mir_keyboard_event_modifiers(kev); if (!(mods & mir_input_event_modifier_alt) || !(mods & mir_input_event_modifier_ctrl)) return false; switch (mir_keyboard_event_scan_code(kev)) { case KEY_BACKSPACE: runner.stop(); return true; case KEY_T: external_client_launcher.launch ({"weston-terminal"}); return true; default: return false; } }; return runner.run_with( { set_window_management_policy <MinimalWindowManager>(), external_client_launcher, AppendEventFilter{keyboard_shortcuts}, Keymap{}, }); } |
Listing 1 |
This breaks down into three blocks, the first is:
MirRunner runner{argc, argv}; ExternalClientLauncher external_client_launcher;
These are two objects from the MirAL library. The ‘runner’ takes care of running Mir; it takes the command line arguments to handle configuration options. The external_client_launcher
is used later to launch the terminal window.
The second block is a lambda – keyboard_shortcuts
– that does some basic input handling. For Ctrl-Alt-T it starts a terminal using external_client_launcher
; for Ctrl-Alt-BkSp it tells runner to stop the server.
The final block is a call to runner.run_with()
, which takes a list of customizations, applies them to the server and runs it. This is the main way of customizing your server (we’ll be looking at other options next time). The customizations used here include the keyboard_shortcuts
and external_client_launcher
mentioned above. There are also a couple more MirAL library objects: Keymap
and MinimalWindowManager
which respectively manage the keyboard layout and provide some default window management.
The MirAL API
The ‘Mir Abstraction Layer’ is an API designed to make it easy to use Mir. It provides a way to use Mir that avoids the complexities, and other issues, associated with the earlier mirserver API. (The development of the MirAL API is described in Overload 136, December 2016 [4].)
The API can be split into the MirRunner
and a number of classes that are passed to the MirRunner
to provide customizations. The customizations seen here are for launching external clients, filtering input, finding the current keyboard layout and setting the window manager.
From this point it is possible to extend the ‘desktop’ in various ways – for example, the MinimalWindowManager
can be replaced with one that implements ‘tiling’ (there’s an example in the Mir code that does this).
Conclusion
This article shows how the Mir library makes it easy to get started with a limited, but working ‘desktop environment’.
The next article will continue from this point and add features such as a ‘wallpaper’ background and a ‘launcher’ for selecting applications.
References
[1] The Mir homepage: https://mir-server.io/
[2] Alan Griffiths (2018) ‘Writing a Wayland Server Using Mir’ in CVu 30.2 May 2018
[3] The egmde git repo: https://github.com/AlanGriffiths/egmde
[4] Alan Griffiths (2016) ‘The MirAL Story’ in Overload 136 December 2016
Alan Griffiths has delivered working software and development processes to a range of organizations, written for a number of magazines, spoken at several conferences, and made many friends.
Notes:
More fields may be available via dynamicdata ..