このページはまだ翻訳されていません。以下の本文は英語です。
Adding a window-manager backend
Home · Architecture · UI Architecture · Development · Platform support
A backend is the adapter between Tessera’s tiling core and one window manager or compositor. This guide covers the traits and atomic facets in tessera-backend, coordinate and DPI rules, and frame-extents or DWM border compensation. It also covers the shared semantic contract suite and the evidence required before a profile becomes supported. Questions and proposals go to the issue tracker.
Writing an adapter does not make a profile supported. Tessera announces support per complete profile (OS, version, session, integration, architecture) only after the evidence listed in Announcing support.
Architecture in five rules
| Rule | Where it lives |
|---|---|
| Tessera never becomes a window manager. It observes state and requests operations from the session’s own WM. | tessera-core, tessera-backend |
BackendId is a closed enum with one variant per adapter. Backends compile into the binary. There is no plugin loader and no runtime registration. |
crates/tessera-app/src/platform/backend_id.rs |
| One active adapter serves each session. A requested backend that is unknown or unavailable fails. The registry never silently falls back. | BackendRegistry::select |
Capabilities are atomic and optional: one BackendOperation per operation that can fail on a platform. The adapter reports unimplemented operations as unsupported, never as success. |
crates/tessera-backend/src/capabilities/ |
| A mutation counts as applied only when the session observes the resulting state. A delivered request is not an applied change. | OperationResult::Applied { observed, at } in operation.rs |
Crate roles you will meet:
| Crate | Role |
|---|---|
tessera-core |
Protocol-neutral tiling policy with no X11, GTK, or config dependencies. |
tessera-backend |
BackendFactory, BackendRegistry, BackendSlug, SessionDriver, capability facets, EventQueue, and the shared contract suite (tessera_backend::contract). |
tessera-backend-x11 |
The xfwm4 adapter and the only crate that uses x11rb. |
tessera-backend-kwin, tessera-backend-gnome |
The opt-in KWin and GNOME Shell Wayland adapters (IPC clients of a KWin script or GNOME extension using tessera-backend-bridge). |
tessera-backend-macos, tessera-backend-windows |
macOS Accessibility (AXUIElement) and Windows User32 and DWM adapters. |
tessera-app |
Composition root that registers adapters per OS in src/platform/. |
The adapter contract (tessera-backend)
flowchart LR
Factory["BackendFactory (id, serves, open_inspection)"] --> Probe["probe() -> Probe (OperationSet)"]
Probe -->|"Available / Degraded"| Open["open(&Probe) -> SessionDriver"]
Open --> Core["Required: snapshot(), events(), screen_space()"]
Open --> Facets["Optional Facets (geometry, focus, workspace, outputs, shortcuts, ...)"]
Open --> Queue["EventQueue + ResyncTracker"]
BackendFactory
Implement tessera_backend::registry::BackendFactory:
| Method | Obligation |
|---|---|
id() |
Return your BackendId / BackendSlug. |
serves(&SessionFacts) |
Say which sessions you target, using desktop (XDG_CURRENT_DESKTOP), session_type (XDG_SESSION_TYPE), and display (DISPLAY). The default returns true for every session, so always override it. |
probe() |
Inspect the session without taking a window-manager role. Return Probe::available(OperationSet), Probe::available_degraded(..) or Probe::unavailable(UnavailableReason). Declare only operations you really implement. |
open(&Probe) |
Return a Box<dyn SessionDriver>. Refuse when the probe was unavailable. |
open_inspection() |
Optional read-only session for debug dumps (--debug-info, debug windows). The default refuses with NotImplemented, so an adapter that cannot inspect says so instead of reporting an empty session. |
SessionDriver and atomic facets
SessionDriver (crates/tessera-backend/src/session.rs) requires:
snapshot(&self): Current window, workspace, and output inventory (Snapshot).events(&self): Drain pendingBackendEvents without blocking.screen_space(&self): Declare theScreenSpaceof all coordinates the session reports and accepts.- Optional lifecycle hooks:
tick(),tick_fresh(),wake_fd()(readable descriptor for event-driven sleep),next_deadline(),held_windows()(windows currently held by a pointer drag),native_drag_tiling(),builtin_output(), andoutput_storage_key().
Every other capability is an atomic facet accessor on SessionDriver that returns None by default (crates/tessera-backend/src/facets/):
| Facet module | Traits & purpose |
|---|---|
geometry.rs |
GeometryRequest, GeometrySubmit — move/resize requests returning GeometryOutcome (Applied, Clamped, Rejected, Suppressed). |
focus.rs |
WindowFocusRead, WindowFocusRequest — read and request active window focus. |
workspace.rs |
WorkspaceEnumeration, WorkspaceActivation, WindowWorkspaceMove — list/switch workspaces and move windows across them. |
outputs.rs |
OutputEnumeration, OutputWatch — monitor inventory and hotplug/mode observation. |
above.rs, background.rs |
WindowAbove, WindowBackground — always-on-top and stacking-layer requests. |
decorations.rs |
DecorationFacet — query or toggle server-side window decorations (NeverDecorated / DecorationRefusal). |
shortcuts.rs |
GlobalHotkeyRegister, GlobalHotkeyUnregister — register/unregister global key bindings with collision reporting (BindingCollision). |
picker.rs |
PickerFacet — interactive window/point selection with PICK_TIMEOUT. |
pointer.rs |
PointerPosition — query pointer coordinates and drop targets (DropTarget). |
inspection.rs |
InspectionFacet — read-only metadata for diagnostic dumps. |
Tiling requires the nine operations in BackendOperation::TILING_REQUIRED (starting with WindowEnumerate, WindowObserve, WindowGeometryRead, WindowMove, and WindowResize). Below that floor, a provider may open only in diagnostic mode (BackendRegistry::select_diagnostic). Always keep the OperationSet returned by probe() consistent with the facet accessors implemented on your SessionDriver.
Coordinate spaces, DPI scaling, and frame extents
Coordinate spaces (ScreenSpace)
Every SessionDriver must implement screen_space(&self) -> ScreenSpace (crates/tessera-backend/src/facets/inventory.rs):
ScreenSpace::Root: One virtual plane covers the entire screen. Output frames, window frames, and client rectangles share one origin. Outputs left of or above the primary monitor have negative coordinates. X11/RandR, macOS CoreGraphics, and Windows virtual desktop coordinates use this model.ScreenSpace::OutputRelative: Each output has its own(0, 0)origin. A window’s frame is relative to its containing output, and moving a window between outputs changes its output identity rather than its coordinates.
OutputInfo::frame always reports in screen-root coordinates (None when disconnected).
DPI scaling
tessera-core operates in a consistent coordinate model per session, while native APIs vary in how they mix physical pixels, logical points, and per-monitor DPI:
- Windows (
tessera-backend-windows): CallsSetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2)at startup and readsGetDpiForMonitor(MDT_EFFECTIVE_DPI)per monitor.MonitorInfoRecord::scale()computes an exacttessera_core::geometry::RationalScale::from_dpi(dpi_x, dpi_y)(dpi / 96) so logical-to-physical conversions never drift from floating-point rounding. - macOS (
tessera-backend-macos): CoreGraphics andAXUIElementuse display points (CGFloat), which are already DPI-independent across Retina and non-Retina displays. - X11 / Wayland: X11 (
tessera-backend-x11) operates in X11 root pixels. Wayland compositors (tessera-backend-gnome,tessera-backend-kwin) operate in compositor logical coordinates.
Frame-extents & DWM border compensation
Window managers often wrap client windows in server-side titlebars or invisible drop-shadow borders:
FrameExtents(crates/tessera-backend/src/facets/inventory.rs):FrameExtents { left, right, top, bottom }records decoration sizes around the client area.WindowInfo::extentsisOption<FrameExtents>: reportNonewhen decoration extents are unknown, andSome(FrameExtents::default())only when zero borders are a known fact.- Windows DWM extended frame bounds (
tessera-backend-windows): Win32GetWindowRectincludes invisible resize/drop-shadow borders (typically ~7px on left/right/bottom at 96 DPI). The Windows adapter queriesDwmGetWindowAttribute(hwnd, DWMWA_EXTENDED_FRAME_BOUNDS, ...)to measure the true visual frame, then compensates the targetRectpassed toSetWindowPosso tiled windows align flush with zero visual gaps. - X11
_NET_FRAME_EXTENTS: The X11 adapter reads_NET_FRAME_EXTENTSand_GTK_FRAME_EXTENTSto account for client-side shadows and server-sidexfwm4frames when placing and re-reading windows.
Semantics that tests enforce
- Unsupported is explicit. A missing operation fails with an
UnsupportedReason(for exampleNotImplemented). It never returns success. - Declare degraded operation. If an operation works with reduced fidelity, declare that through
Probe::available_degradedand aDegradedReason. - Applied means observed. Report
GeometryStatus::AppliedorOperationResult::Appliedonly after reading the effective frame back. If the WM clamped or ignored the request, reportClampedorRejectedwith the actualeffectiveRect. - Deliver events, never drop them. Document any coalescing or suppression (such as pointer-drag suppression or hover settle debouncing). A partial drain failure must never discard already-drained events silently.
Step-by-step checklist
- Create the crate
crates/tessera-backend-<name>and add it toCargo.toml. ImplementBackendFactoryandSessionDriver(Xfwm4BackendFactoryincrates/tessera-backend-x11/src/xfwm4/factory.rsis the reference). - Add identity in
crates/tessera-app/src/platform/backend_id.rs: add a variant toBackendIdand updateentry(canonical slug and accepted aliases),ALL,is_experimental, andidentity_field(WmClass,BundleId, orAppId). Exhaustive matches enforce completeness. - Register the factory in
compiled_backends()undercrates/tessera-app/src/platform/(linux.rs,macos.rs,windows.rs, orother.rs). Keep the static registration inert until a caller invokesprobeoropen. Add the crate dependency tocrates/tessera-app/Cargo.toml. - Add an integration endpoint only if selection needs one (e.g.,
serve_kwinorconnect_gnomeinINTEGRATIONSinplatform/linux.rs), returning immediately for sessions the adapter does not serve. - Add unavailable reasons to
UnavailableReasonincrates/tessera-backend/src/error.rs, map them inunavailable_reason_text(crates/tessera-app/src/error/reason_text.rs), and add the corresponding Fluent message IDs to all 10 catalogs undercrates/tessera-i18n/i18n/<locale>/tessera.ftl. - Write tests (below) and verify against the semantic contract suite.
Contract suite walkthrough & tests
| Layer | Where | What it proves |
|---|---|---|
| Registry selection | crates/tessera-app/tests/platform_backend_selection.rs |
Served, unserved, ambiguous, and served-but-unavailable sessions select or refuse as intended. |
| Registry and facets | crates/tessera-backend/tests/ (backend_registry.rs, atomic_capabilities_contract.rs, capability_matrix_and_unsupported_contract.rs, session_probe_and_refusal_contracts.rs) |
Probe and refusal behavior. Unsupported operations never return success. Unreachable integrations never report applied. |
| Semantic contract | tessera_backend::contract (ContractFixture, ContractSubject, violations) |
The shared suite every adapter must pass. Exercises only operations declared by probe() and reads effects back through snapshot() / events(). |
| Adapter-specific | crates/tessera-backend-<name>/tests/ |
Protocol behavior, coordinate/DPI math, and frame-extents handling (see crates/tessera-backend-x11/tests/). |
To run the shared semantic contract suite against a synthetic fixture or live isolated session:
let subject = ContractSubject::from_driver(session.driver());
let found = violations(&subject, session.capabilities(), &fixture);
assert!(found.is_empty(), "adapter violates the semantic contract: {found:#?}");
Run display-dependent adapter tests inside scripts/test-env.sh <profile> <cmd...> (x11, x11-dummy, kwin-wayland, gnome-wayland) so tests never touch your active desktop session. See Development for the full profile table and exit codes.
Announcing support
A new adapter stays out of the supported set until all of these hold for the complete profile:
- A verified control/event contract exists for the compositor or window manager.
- The shared semantic contract tests pass.
- CI evidence exists from the same commit.
- A smoke run passes in a real session of that profile (virtual servers and containers support development, not real-session proof).
Pin claims about window-manager behavior to the latest stable source release. The xfwm4 reference is 4.20.0 (tag xfwm4-4.20.0). If any criterion is unmet, the profile remains experimental or blocked.
Consent for compositor integrations
Some adapters need code inside the compositor (a GNOME Shell extension or a KWin script). Tessera never installs or removes these silently:
- The user manages them explicitly (for example,
tessera gnome-extension install|remove, which prompts for confirmation unless you pass--yes). - The adapter verifies handshake, health, and version compatibility before use. A missing or incompatible peer yields a typed
UnavailableReason(IntegrationAbsent { kind: IntegrationKind },IntegrationIncompatible { kind: IntegrationKind, detail }). - Persistent OS permissions (such as macOS Accessibility) require explicit user consent at the point of risk. If the user revokes permission, the adapter degrades to an explicit unsupported or unavailable result.