Mir
Introducing the Miral API

The main() program

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

/*
* Copyright © 2016-2020 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
* 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>
#include <unistd.h>
#include <boost/filesystem.hpp>
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(); });
ExternalClientLauncher external_client_launcher;
std::string terminal_cmd{"weston-terminal"};
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;
{
case KEY_BACKSPACE:
runner.stop();
return true;
case KEY_T:
{
std::vector<std::string> command_line{terminal_cmd};
if (terminal_cmd == "gnome-terminal" && boost::filesystem::exists("/usr/bin/gnome-terminal.real"))
{
// gnome-terminal is a horrid wrapper script on Ubuntu that needs frigging
command_line.emplace_back("--disable-factory");
command_line.emplace_back("--app-id");
command_line.emplace_back("com.canonical.miral.Terminal");
}
external_client_launcher.launch(command_line);
}
return false;
case KEY_X:
external_client_launcher.launch_using_x11({"xterm"});
return false;
default:
return false;
};
};
Keymap config_keymap;
DebugExtension debug_extensions;
return runner.run_with(
{
CursorTheme{"default:DMZ-White"},
window_managers,
external_client_launcher,
launcher,
config_keymap,
debug_extensions,
AppendEventFilter{quit_on_ctrl_alt_bksp},
pre_init(CommandLineOption{[&](std::string const& typeface) { ::wallpaper::font_file(typeface); },
"shell-wallpaper-font", "font file to use for wallpaper", ::wallpaper::font_file()}),
CommandLineOption{[&](std::string const& cmd) { terminal_cmd = cmd; },
"shell-terminal-emulator", "terminal emulator to use", terminal_cmd}
});
}

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.

miral::pre_init
auto pre_init(CommandLineOption const &clo) -> CommandLineOption
Update the option to be called back before Mir initialization starts.
MirKeyboardEvent
struct MirKeyboardEvent MirKeyboardEvent
An event type describing a change in keyboard state.
Definition: keyboard_event.h:41
mir_event_type_input
@ mir_event_type_input
Definition: event.h:50
miral::ExternalClientLauncher
Definition: external_client.h:32
miral
Mir Abstraction Layer.
Definition: floating_window_manager.h:29
SpinnerSplash
Definition: splash.h:24
mir_input_event_type_key
@ mir_input_event_type_key
Definition: input_event.h:37
MirInputEventModifiers
unsigned int MirInputEventModifiers
Definition: input_event.h:67
display_configuration_option.h
miral::display_configuration_options
void display_configuration_options(mir::Server &server)
mir_keyboard_event_action
MirKeyboardAction mir_keyboard_event_action(MirKeyboardEvent const *event)
Retrieve the action which triggered a given key event.
window_management_options.h
mir_event_get_type
MirEventType mir_event_get_type(MirEvent const *event)
Retrieves the type of a MirEvent.
wayland_extensions.h
miral::Keymap
Load a keymap.
Definition: keymap.h:30
floating_window_manager.h
MirEvent
struct MirEvent MirEvent
Definition: event.h:84
mir_event_get_input_event
MirInputEvent const * mir_event_get_input_event(MirEvent const *event)
Retrieve the MirInputEvent associated with a MirEvent of type mir_event_type_input.
miral::WindowManagerOptions
Definition: window_management_options.h:53
miral::StartupInternalClient
Wrapper for running an internal Mir client at startup.
Definition: internal_client.h:41
mir_input_event_modifier_alt
@ mir_input_event_modifier_alt
Definition: input_event.h:49
mir_keyboard_event_scan_code
int mir_keyboard_event_scan_code(MirKeyboardEvent const *event)
Retrieve the raw hardware scan code associated with the key acted on.
external_client.h
command_line_option.h
wallpaper_config.h
keymap.h
miral::MirRunner::add_stop_callback
void add_stop_callback(std::function< void()> const &stop_callback)
Add a callback to be invoked when the server is about to stop, If multiple callbacks are added they w...
wallpaper::font_file
void font_file(std::string const &font_file)
Definition: wallpaper_config.cpp:48
internal_client.h
miral::DebugExtension
Allow debug extension APIs to be enabled and disabled.
Definition: debug_extension.h:29
main
int main(int argc, char const *argv[])
Definition: kiosk_main.cpp:83
mir_keyboard_event_modifiers
MirInputEventModifiers mir_keyboard_event_modifiers(MirKeyboardEvent const *event)
Retrieve the modifier keys pressed when the key action occured.
mir_input_event_modifier_ctrl
@ mir_input_event_modifier_ctrl
Definition: input_event.h:57
append_event_filter.h
cursor_theme.h
miral::InternalClientLauncher
Definition: internal_client.h:70
x11_support.h
miral::ExternalClientLauncher::launch
void launch(std::vector< std::string > const &command_line) const
runner.h
miral::X11Support
Add a user configuration option for X11 support.
Definition: x11_support.h:30
MirInputEvent
struct MirInputEvent MirInputEvent
Definition: event.h:70
tiling_window_manager.h
mir_input_event_get_type
MirInputEventType mir_input_event_get_type(MirInputEvent const *event)
Retrieve the type of an input event.
miral::CursorTheme
Load an X-cursor theme, either the supplied default, or through the –cursor-theme config option.
Definition: cursor_theme.h:29
miral::CommandLineOption
Add a user configuration option to Mir's option handling. By default the callback will be invoked fol...
Definition: command_line_option.h:40
miral::AppendEventFilter
Definition: append_event_filter.h:31
miral::WaylandExtensions
Enable configuration of the Wayland extensions enabled at runtime.
Definition: wayland_extensions.h:48
miral::MirRunner
Runner for applying initialization options to Mir.
Definition: runner.h:39
mir_keyboard_action_down
@ mir_keyboard_action_down
Definition: keyboard_event.h:50
splash.h
miral::ExternalClientLauncher::launch_using_x11
void launch_using_x11(std::vector< std::string > const &command_line) const
Launch using only X11 support (if enabled). For the occasions it is desired to coerce applications in...
debug_extension.h
mir_input_event_get_keyboard_event
MirKeyboardEvent const * mir_input_event_get_keyboard_event(MirInputEvent const *event)
Retrieve the MirKeyboardEvent associated with a given input event.

Copyright © 2012-2021 Canonical Ltd.
Generated on Wed Nov 24 08:21:43 UTC 2021
This documentation is licensed under the GPL version 2 or 3.