How canonical/mir works
Project Type and Purpose
• Mir is a platform for building Wayland-based shells. It provides a set of libraries and infrastructure that abstracts and manages the hardware complexities behind graphics and input devices.
• Its goal is to offer window management, input processing (touch, mouse, tablet), multi-display support, and secure communication between client and server components. Essentially, it is the backbone for developing a compositing manager on Linux systems (and potentially beyond).
Analyzing the File Structure
• The file tree shows many well-organized directories:
– "src" holds the core implementation in modules such as "miral", "miroil", "server", "platform", and "gl".
– "include" mirrors the source structure (with common, core, miral, and platform directories) exposing the API and internal interfaces.
– "tests" and "tools" help in verifying, testing, and automating processes.
• The project uses CMake for build configuration, so many CMakeLists.txt files are present in each directory. This shows a modular design that is built to support multiple different subsystems.
Identifying the Main Components
• Server/Compositor Core: Found in directories like src/server and include/server. This is where the main event loop, scene management, and window/compositor management logic reside.
• Frontend/Protocol Layers: There are dedicated directories for frontends such as "server/frontend_wayland", "server/frontend_xwayland", and the "wayland" directory. These handle communication with Wayland clients and protocol translations.
• Input Handling: Look at directories like src/server/input, src/common/input, and the various platform-specific input implementations (evdev, libinput, for example). This layer abstracts various input devices and orchestrates event handling.
• Graphics/Rendering Layers: In directories such as src/gl, src/platform/graphics, src/renderer, and the platforms (atomic-kms, eglstream-kms, gbm-kms, etc.). They are responsible for rendering, hardware acceleration, and buffer management.
• Configuration and Abstraction Layers: With components like miral (for window management, shell interaction, and client-server behavior) and miroil (for interfacing with low-level compositor details) as well as several “configuration” files and modules.
• System Integration and Platform Abstraction: The “platform” directory and various subdirectories for different backends (X11, Wayland-specific, virtual, etc.) show the abstraction over different hardware and system components.
• Utility/Support Layers: Logging, event dispatch, thread management, and shared library loading (identified in the "common" directories) are key cross-cutting concerns.
Relationships and Interactions
– Client applications (via the Wayland protocol) communicate with the compositor’s frontend layers (Wayland, XWayland) which then interface with the compositor/core.
– The compositor core handles events (input, window management, configuration changes) and dispatches rendering calls to the appropriate graphics abstraction layer.
– The graphics layer communicates with platform-specific components to render content (e.g., atomic-kms, gbm-kms, egl, etc.).
– Input devices are abstracted through a dedicated input manager which collects events from multiple sources (evdev, libinput), passes them to the compositor, and then further to application clients.
Architectural Patterns and Design Principles
• Modular Design: Each major subsystem (input, rendering, protocol handling, configuration) is isolated into its own directory and set of libraries. This separation supports easier testing, maintenance, and scalability.
• Abstraction and Hardware Independence: The design encapsulates hardware-specific logic in platform-specific modules, allowing the core compositor logic to remain hardware agnostic.
• Event-Driven Architecture: The compositor and input layers are event-driven, clearly visible in directories handling event dispatch and message queues.
• Client/Server Model: A central idea of separate client applications interacting with a compositor server (which then delegates to the window manager/shell) should be illustrated.