Mir
Introducing the Miral API

The main() program

The main() program from miral-shell looks like this:

/*
* Copyright © 2016-2017 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* under the terms of the GNU General Public License version 2 or 3 as as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authored by: Alan Griffiths <alan@octopull.co.uk>
*/
#include "spinner/splash.h"
#include <miral/runner.h>
#include <miral/keymap.h>
#include <linux/input.h>
int main(int argc, char const* argv[])
{
using namespace miral;
std::function<void()> shutdown_hook{[]{}};
SpinnerSplash spinner;
WindowManagerOptions window_managers
{
add_window_manager_policy<FloatingWindowManagerPolicy>("floating", spinner, launcher, shutdown_hook),
add_window_manager_policy<TilingWindowManagerPolicy>("tiling", spinner, launcher),
};
MirRunner runner{argc, argv};
runner.add_stop_callback([&] { shutdown_hook(); });
auto const quit_on_ctrl_alt_bksp = [&](MirEvent const* event)
{
return false;
MirInputEvent const* input_event = mir_event_get_input_event(event);
return false;
return false;
return false;
if (mir_keyboard_event_scan_code(kev) != KEY_BACKSPACE)
return false;
runner.stop();
return true;
};
Keymap config_keymap;
DebugExtension debug_extensions;
return runner.run_with(
{
CommandLineOption{[&](std::string const& ) { },
"desktop_file_hint", "Ignored for Unity8 compatibility", "miral-shell.desktop"},
CursorTheme{"default:DMZ-White"},
window_managers,
launcher,
config_keymap,
debug_extensions,
AppendEventFilter{quit_on_ctrl_alt_bksp},
pre_init(CommandLineOption{[&](std::string const& typeface) { ::titlebar::font_file(typeface); },
"shell-titlebar-font", "font file to use for titlebars", ::titlebar::font_file()})
});
}

This shell is providing FloatingWindowManagerPolicy, TilingWindowManagerPolicy and SpinnerSplash. The rest is from MirAL.

If you look for the corresponding code in lp:qtmir and lp:mir you’ll find it less clear, more verbose and scattered over multiple files.

A shell has to provide a window management policy (miral-shell provides two: FloatingWindowManagerPolicy and TilingWindowManagerPolicy). A window management policy needs to implement the miral::WindowManagementPolicy interface for handling a set of window management events.

The way these events are handled determines the behaviour of the shell.

The miral::WindowManagerTools interface provides the principle methods for a window management policy to control Mir.


Copyright © 2012-2018 Canonical Ltd.
Generated on Thu 12 Jul 10:49:10 UTC 2018