The main() program
The main() program from miral-shell looks like this:
#include "tiling_window_manager.h"
#include "titlebar_window_manager.h"
#include "titlebar_config.h"
#include "spinner/splash.h"
#include <linux/input.h>
int main(int argc, char const* argv[])
{
std::function<void()> shutdown_hook{[]{}};
SpinnerSplash spinner;
{
add_window_manager_policy<TitlebarWindowManagerPolicy>("titlebar", spinner, launcher, shutdown_hook),
add_window_manager_policy<TilingWindowManagerPolicy>("tiling", spinner, launcher, outputs_monitor),
};
auto const quit_on_ctrl_alt_bksp = [&](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;
if (mir_keyboard_event_scan_code(kev) != KEY_BACKSPACE)
return false;
runner.stop();
return true;
};
return runner.run_with(
{
"desktop_file_hint", "Ignored for Unity8 compatability", "miral-shell.desktop"},
window_managers,
launcher,
outputs_monitor,
config_keymap,
debug_extensions,
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 TitlebarWindowManagerPolicy, 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: TitlebarWindowManagerPolicy 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.