← Back to docs

Core · wm

Portal WM — Window Manager Daemon

Daemon that monitors Wayland toplevel windows and assigns them to spatial zones. Uses ext_foreign_toplevel_list_v1 to track windows and IPC to send zone assignments to portal-spatial.

portal-wmv0.2.0wm
2.1K
Lines of Code
111
Tests
13
Files

Architecture

The binary has 4 modules: main.rs (entry point, Wayland connection, event loop, IPC dispatch), config.rs (future configuration loading), spatial_ipc.rs (IPC client wrapper around portal-spatial), zone_policy.rs (policy engine: utility apps prefer peripheral zones, center fills first). The main event loop dispatches Wayland events, then periodically sends pending zone assignments via IPC.

Overview

portal-wm is the window manager daemon that bridges the Wayland compositor and the spatial zone system. It connects to Wayfire as a Wayland client, uses the ext_foreign_toplevel_list_v1 protocol to discover application windows (tracking their title, app_id, and identifier), and applies a zone assignment policy to determine which spatial zone each window should occupy. Zone assignments are then sent to the portal-spatial plugin via IPC at /run/portal/spatial.sock. The daemon runs as a systemd service (portal-wm.service) and gracefully handles missing IPC connections (logs a warning, continues tracking windows without zone assignment).

Key Types

WindowManagerMain state holder — tracks all toplevels in a HashMap, holds the ZonePolicy, and manages the foreign toplevel list proxy.
ToplevelInfoPer-window metadata: title, app_id, identifier, assigned_zone, and ipc_sent flag for tracking assignment delivery.
ZonePolicyPolicy engine that determines zone assignment — utility apps prefer peripheral zones, center fills first, stacking when full.
SpatialIpcIPC client that connects to portal-spatial's Unix socket and sends AssignZone messages.

Modules

main

Entry point — connects to Wayland, binds ext_foreign_toplevel_list_v1, enters event loop dispatching Wayland events and sending IPC assignments.

config

Configuration (future: per-app zone preferences, custom zone policies, dimension-specific layouts).

spatial_ipc

IPC client wrapper using portal-spatial — connects to /run/portal/spatial.sock, sends AssignZone messages.

zone_policy

Zone assignment policy engine — fills center first, then peripherals; utility apps prefer peripherals; stacking when all zones occupied.

Data Flow

Wayfire announces new toplevel → portal-wm tracks title/app_id → ZonePolicy assigns zone → IPC sends AssignZone to portal-spatial plugin → plugin applies spatial transform

Dependencies

External (10)

tokio 1tracing 0.1tracing-subscriber 0.3anyhow 1.0thiserror workspaceserde 1serde_json 1toml workspacewayland-client 0.31wayland-protocols 0.32

Depends on portal-spatial (zone types, IPC protocol). External: wayland-client, wayland-protocols (foreign toplevel management), tokio (async runtime), tracing (logging).