    <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/">
     <channel>
        <title>ACCU  :: Making a Linux Desktop</title>
        <link>https://members.accu.org/index.php/articles/2696</link>
        <description>Professionalism in Programming</description>
        <dc:language>en-us</dc:language> 
        <dc:creator>Administrator</dc:creator> 
        <admin:generatorAgent rdf:resource="http://www.xaraya.org" /> 
        <admin:errorReportsTo rdf:resource="mailto:webeditor@accu.org" />
       <sy:updatePeriod>hourly</sy:updatePeriod>
       <sy:updateFrequency>1</sy:updateFrequency>
       <docs>http://backend.userland.com/rss</docs>




<div class="xar-mod-head"><span class="xar-mod-title">Design of applications and programs + CVu Journal Vol 31, #4 - September 2019</span></div>

<table border="0" cellpadding="1" cellspacing="0">
    <tbody>
    <tr>
        <td valign="top">
            Browse in :
       </td>
       <td valign="top">

                                            <a href="https://members.accu.org/index.php/articles/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c13/">Topics</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c67/">Design</a>
<br />

                                            <a href="https://members.accu.org/index.php/articles/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c76/">Journals</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c77/">CVu</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c402/">314</a>
<br />

                                            <a href="https://members.accu.org/index.php/articles/c67-402/">Any of these categories</a>

                    -                        <a href="https://members.accu.org/index.php/articles/c67+402/">All of these categories</a>
<br />
</td>
   </tr>
   </tbody>
</table>




<div class="xar-error">
   <p>
 <strong>Note:</strong> when you create a new publication type,
the articles module will automatically use the templates
<em>user-display-[publicationtype].xt</em>
and <em>user-summary-[publicationtype].xt</em>.
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/<em>yourtheme</em>/modules/articles . The templates will get the extension .xt there. </p>
</div>
<div class="xar-norm xar-standard-box-padding">
   <h1><strong>Title:</strong>&nbsp;Making a Linux Desktop</h1>
<p><strong>Author:</strong>&nbsp;Bob Schmidt</p>
<p>
<strong>Date:</strong> 07 September 2019 17:27:40 +01:00 or Sat, 07 September 2019 17:27:40 +01:00</p>
<p><strong>Summary:</strong>&nbsp;Alan Griffiths illustrates how to get started with Mir.</p>
<p><strong>Body:</strong>&nbsp;<p>Iâ€™m working on a project (Mir) that, among other things, aims to make it easy to develop graphical â€˜desktop environmentsâ€™ for Linux.<a href="#[1]">[1]</a> 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.</p>

<p>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.</p>

<p>Last year, I wrote an article for <em>CVu</em> <a href="#[2]">[2]</a> 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.</p>

<p>This is the first of in a new series of articles that illustrate the development of an Example Mir Desktop Environment. <a href="#[3]">[3]</a></p>

<h2>Wayland</h2>

<p>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.</p>

<p>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.</p>

<h2>Preparation</h2>

<p>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.</p>

<pre class="programlisting">
  $ 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</pre>
  
<p>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:</p>

<pre class="programlisting">
  $ sudo dnf install mir-devel
  $ sudo dnf install weston qt5-qtwayland
  $ sudo dnf install gcc-c++ cmake</pre>
  
<p>Mir is also available from the Arch AUR and can be built from source for many versions of Linux.</p>

<h2>Egmde</h2>

<p>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.</p>

<h3>Building the example</h3>

<p>The full code for this example is available on github:</p>

<pre class="programlisting">
  $ git clone https://github.com/AlanGriffiths/    egmde.git
  $ git checkout Article-1</pre>
  
<p>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:</p>

<pre class="programlisting">
  $ mkdir egmde/build
  $ cd egmde/build
  $ cmake ..
  $ make</pre>

<h3>Running the example</h3>

<p>After this you can start egmde:</p>

<pre class="programlisting">
  $ ./egmde</pre>
  
<p>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).</p>

<p>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?</p>

<p>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.</p>

<p>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.</p>

<h3>Installing the example</h3>

<p>If you install egmde, it will be added to the greeter menu (typically a â€˜cog wheelâ€™ on the sign-on screen):</p>

<pre class="programlisting">
  $ sudo make install</pre>
  
<p>Depending upon the greeter used on your system, it may be necessary to reboot before egmde appears as a login shell.</p>

<h3>Installing the example</h3>

<p>To register applications with desktop environments we install a <span class="filename">.desktop </span>file in <span class="filename">/usr/share/applications</span> and to register Wayland based desktops with the greeter we install a <span class="filename">.desktop</span> file in  <span class="filename">/usr/share/wayland-sessions/</span>. The content needed for both cases is similar, so for this example we use the same <span class="filename">.desktop</span> file and install it to both places.</p>

<h2>The example code</h2>

<p>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:</p>

<pre class="programlisting">
  $ wc -l *.cpp
  75 egmde.cpp</pre>
  
<p>The main program for this article is shown in Listing 1.</p>

<table class="sidebartable">
	<tr>
		<td>
			<pre class="programlisting">
using namespace miral;
int main(int argc, char const* argv[])
{
  MirRunner runner{argc, argv};
  ExternalClientLauncher external_client_launcher;
  auto const keyboard_shortcuts 
      = [&amp;](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 &amp; mir_input_event_modifier_alt) ||
        !(mods &amp; 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
          ({&quot;weston-terminal&quot;});
        return true;
      default:
        return false;
    }
  };
  return runner.run_with(
  {
    set_window_management_policy
    &lt;MinimalWindowManager&gt;(),
    external_client_launcher,
    AppendEventFilter{keyboard_shortcuts},
    Keymap{},
  });
}
			</pre>
		</td>
	</tr>
	<tr>
		<td class="title">Listing 1</td>
	</tr>
</table>

<p>This breaks down into three blocks, the first is:</p>

<pre class="programlisting">
  MirRunner runner{argc, argv};
  ExternalClientLauncher external_client_launcher;</pre>
  
<p>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 <code>external_client_launcher</code> is used later to launch the terminal window.</p>

<p>The second block is a lambda â€“ <code>keyboard_shortcuts</code> â€“ that does some basic input handling. For Ctrl-Alt-T it starts a terminal using <code>external_client_launcher</code>; for Ctrl-Alt-BkSp it tells runner to stop the server.</p>

<p>The final block is a call to <code>runner.run_with()</code>, 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 <code>keyboard_shortcuts</code> and <code>external_client_launcher</code> mentioned above. There are also a couple more MirAL library objects: <code>Keymap</code> and <code>MinimalWindowManager</code> which respectively manage the keyboard layout and provide some default window management.</p>

<h2>The MirAL API</h2>

<p>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 <em>Overload</em> 136, December 2016 <a href="#[3]">[4]</a>.)</p>

<p>The API can be split into the <code>MirRunner</code> and a number of classes that are passed to the <code>MirRunner</code> to provide customizations. The customizations seen here are for launching external clients, filtering input, finding the current keyboard layout and setting the window manager.</p>

<p>From this point it is possible to extend the â€˜desktopâ€™ in various ways â€“ for example, the <code>MinimalWindowManager</code> can be replaced with one that implements â€˜tilingâ€™ (thereâ€™s an example in the Mir code that does this).</p>

<h2>Conclusion</h2>

<p>This article shows how the Mir library makes it easy to get started with a limited, but working â€˜desktop environmentâ€™.</p>

<p>The next article will continue from this point and add features such as a â€˜wallpaperâ€™ background and a â€˜launcherâ€™ for selecting applications.</p>

<h2>References</h2>

<p class="bibliomixed"><a id="[1]"></a>[1]	The Mir homepage: <a href="https://mir-server.io/">https://mir-server.io/</a></p>

<p class="bibliomixed"><a id="[2]"></a>[2]	Alan Griffiths (2018) â€˜Writing a Wayland Server Using Mirâ€™ in <em>CVu</em> 30.2 May 2018</p>

<p class="bibliomixed"><a id="[3]"></a>[3]	The egmde git repo: <a href="https://github.com/AlanGriffiths/egmde">https://github.com/AlanGriffiths/egmde</a></p>

<p class="bibliomixed"><a id="[4]"></a>[4]	Alan Griffiths (2016) â€˜The MirAL Storyâ€™ in <em>Overload</em> 136 December 2016</p>

<p class="bio"><span class="author"><b>Alan Griffiths</b></span> 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.</p>
</p>
<p><strong>Notes:</strong>&nbsp;</p>
<p><em>More fields may be available via dynamicdata ..</em></p>
</div>
</channel>
</rss>
