Esta página aún no está traducida. El texto siguiente está en inglés.
UI Architecture (Neutral UI Peer Model)
Home · Architecture · Development · Platform support
Tessera builds its user interface on a Neutral UI Peer Architecture. This covers the Preferences window, HUD overlay, system tray menu, and desktop notifications. One OS-neutral and toolkit-neutral crate (tessera-ui) owns every surface’s structure, layout math, state, and visual tokens. Platform-specific provider crates (tessera-ui-*) act as thin peers that realize those declarations with native toolkit widgets.
Core principle: core commands, providers obey
tessera-ui never draws pixels and never names a toolkit widget or OS handle (gtk4::*, QObject, HWND, NSView). Instead, responsibilities split as follows:
tessera-uideclares the exact tree of nodes, stable IDs, layout rules, semantic tokens, defaults, validation, and state for every surface.- Each
tessera-ui-*provider obeys by mapping semantic token names to native toolkit values through one translation table and binding eachControlKindorNodeKindto its native widget. - Fix visual defects in
tessera-uifirst. If a spacing, alignment, or sizing defect appears in one toolkit, fix it as declared data intessera-uiso every provider receives the same fix.
flowchart TD
UI["tessera-ui: Neutral UI Tree (NodeKind, ControlKind, NodeId)"] --> Solver["LayoutSpec Solver and DrawnValues"]
Solver --> Tokens["Semantic Tokens (Spacing, Color, Text, ControlSize, Measure)"]
Tokens --> Model["UiModel, PreferencesModel, UiEvent, ApplicationHandle"]
Model -->|"Static link (macOS / Windows)"| MacOS["tessera-ui-macos (AppKit / NSView)"]
Model -->|"Static link (macOS / Windows)"| Win["tessera-ui-windows (WinUI 3 + Win32)"]
Model -->|"Runtime cdylib (tessera_ui_plugin_v1 C ABI)"| Plugin["libtessera_ui_plugin_*"]
Model -->|"Linux desktop services"| Fdo["tessera-ui-freedesktop (Tray, D-Bus, Autostart)"]
Plugin --> GTK["tessera-ui-gtk (GTK 4 + GtkLook)"]
Plugin --> Adw["tessera-ui-adwaita (Libadwaita)"]
Plugin --> Qt["tessera-ui-qt (Qt 6 / Kirigami)"]
The neutral node tree (tessera-ui/src/toolkit/)
Stable NodeIds and tree diffing
tessera-ui represents every UI surface as a tree of nodes (component.rs) identified by stable NodeIds (src/toolkit/id.rs). Rather than tearing down and recreating native widget hierarchies on every state change, realize.rs and diff.rs compute structural diffs keyed by NodeId. Providers then create, update, or remove only the changed nodes.
NodeKind and ControlKind
NodeKind(src/toolkit/component.rs) defines structural and content primitives (containers, stacks, grids, headings, labels, banners, dividers, cards, and interactive controls).ControlKind(src/view_model/descriptor.rs) defines neutral control semantics (switches, sliders, spinboxes, dropdowns, shortcut recorders, segmented choices, action buttons). Each provider must bindControlKindto the toolkit’s native control first before resorting to custom drawing.
LayoutSpec solver and DrawnValues
LayoutSpec(src/toolkit/layout.rs): Pure layout solver that resolves padding, gaps, alignment, wrapping, and sizing constraints into concrete frame geometry without querying any GUI toolkit.DrawnValues(src/toolkit/drawn.rs): Holds the single logical value of every drawn-content token and measure (for example, layout preview cards and HUD geometry). Owner-drawn surfaces therefore share the exact same proportions across all platforms.
Non-Preferences surfaces (src/toolkit/surfaces/)
Beyond the Preferences window (src/preferences/pages/), tessera-ui models every other user-facing surface as neutral trees and state:
- HUD overlay:
src/toolkit/surfaces/hud.rsandsrc/hud/(place.rsplacement and fit math,card.rs,notice.rs,message.rs), plussrc/view_model/hud_model.rs. - Tray & notifications:
src/toolkit/surfaces/tray.rs,src/tray/(menu.rs,plan.rs,TrayProvider,InMemoryTrayBackend,UnsupportedTrayBackend), andsrc/notification/(NotificationStrategy). - Autostart:
src/autostart/mod.rs(AutostartProvider,AutostartState,AutostartError).
Semantic tokens & closed native exceptions (E1–E5)
tessera-ui never embeds hex color palettes, toolkit-specific pixel constants, or OS font names. Instead, src/toolkit/names.rs defines closed enums with exhaustive ALL slices:
Spacing(e.g.,Page,Section,Related,Tight,Head,Banner,Group,Row,RowPadH,RowPadV,Sheet,Float)Color: system semantic roles for window, text, separator, accent, selection, hover, focus, field, card, sidebar, and inset. Also includes status and overlay roles.Text(semantic typographic roles and weights)ControlSizeandMeasure
Each provider crate maintains one fixed translation table from these enum variants to its native toolkit values. Examples include GNOME HIG, Greybird, Kirigami Units, Apple HIG, and Fluent. Exhaustive match arms guarantee at compile time that every provider handles every token.
src/toolkit/native_exceptions.rs defines the closed list E1 to E5—the only visual values permitted to originate in a provider crate:
| Exception | What stays in the provider |
|---|---|
| E1 | System semantic colors (Color roles mapped to native palette or theme colors, with no hex in core). |
| E2 | System font family and text scale. |
| E3 | Intrinsic native control sizes. |
| E4 | Protocol and platform API constants (including PIXMAP_SIZES). |
| E5 | Platform unit conversion (points/DIPs/logical pixels). |
PEER_TOLERANCE_CEILING in native_exceptions.rs enforces a layout-position tolerance ratchet per provider library that can only tighten over time.
Single state object, UiEvent, and application duties
All UI state lives in tessera-ui. Providers hold no authoritative state of their own:
- State & drafts:
PreferencesModel(src/preferences/model.rs) holds the values that the Preferences window renders.UiModelandPreferencesDraft(src/view_model/) manage live edits.WindowSessionandRefreshGate(src/preferences/window_session.rs,refresh_gate.rs) govern when an open window may rebuild.preferences::manifest::message_ids()(src/preferences/manifest.rs) tracks catalog IDs. - Validation & parsing:
src/preferences/parse.rsvalidates text inputs (numbers, shortcut chords, rule lists) and returns typed, localizable errors (FieldError,ChangeFailure) mapped totessera-i18nmessage IDs. - Events & changes: Native widget interactions emit neutral
UiEventvalues (src/toolkit/event.rs).src/preferences/edit/maps these viaControlId(control_id.rs) andbounds.rsinto typedPreferencesChangevariants (src/preferences/change.rs) and named application actions (PERMISSIONS_ACTION,RESET_LAYOUTS_ACTION,SET_LANGUAGE_ACTION, and others). - Application duty traits (
src/application/): Providers interact with the host application exclusively throughApplicationHandle. Its duty traits areAppLifecycle,ActionBus,Timers,Clipboard,HudHost,PreferencesHost, andTrayHost.
Native UI providers
Each provider implements UiProviderFactory and UiProvider (src/provider/):
| Crate | Platform / Desktop | Realization details |
|---|---|---|
tessera-ui-gtk |
Linux (XFCE base & GNOME base) | GTK 4 (v4_18) Preferences window, GtkLook styling seam, HUD overlay, and AT-SPI accessibility announcements. |
tessera-ui-adwaita |
Linux (GNOME) | Libadwaita look (Adw* widgets/sheets/preferences groups) loaded dynamically via libloading on top of tessera-ui-gtk. |
tessera-ui-plugin-gtk |
Linux (GTK / Adwaita plugin) | cdylib crate exporting both GTK 4 and Libadwaita UiProviderFactory instances over tessera_ui_plugin_v1. |
tessera-ui-qt |
Linux (KDE Plasma) | Qt 6 / QML / Kirigami cdylib plugin exporting the Plasma UiProviderFactory over tessera_ui_plugin_v1. |
tessera-ui-freedesktop |
Linux (Desktop services) | StatusNotifierItem system tray (ksni), D-Bus desktop notifications, and .desktop / systemd user autostart. |
tessera-ui-macos |
macOS | Native AppKit Preferences (NSWindow/NSView), NSStatusItem menu-bar icon, NSPanel HUD, UNUserNotificationCenter, and SMAppService LaunchAgent autostart. |
tessera-ui-windows |
Windows 11 | Native WinUI 3 Preferences window plus Win32 tray icon, layered HUD window, toast notifications, and Registry Run autostart. |
Runtime cdylib plugins (tessera_ui_plugin_v1 ABI)
On Linux, the tessera binary links no GUI toolkit (gtk4, libadwaita, Qt6). Instead, tessera-app (platform/ui_plugin.rs) discovers and loads libtessera_ui_plugin_gtk.so or libtessera_ui_plugin_qt.so at runtime via src/plugin/:
- Entry & language symbols: A plugin uses
export_ui_plugin!(src/plugin/mod.rs) to exportENTRY_SYMBOL(tessera_ui_plugin_v1), which returns*const PluginHeader. It also exports the optionalLANGUAGE_SYMBOL(tessera_ui_plugin_v1_set_language(ptr, len)), which the loader calls whenever the user switches languages at runtime. - Header validation (
src/plugin/validate.rs):PluginHeaderstarts with three plain C fields (ABI_VERSION = 2,RUSTC_VERSION, andTESSERA_UI_VERSION).build.rscomputesTESSERA_UI_FINGERPRINTby hashing thetessera-uiboundary sources andCargo.lock. Before touching any Rust-ABI trait object (&'static dyn UiProviderFactory),check_headervalidates that the plugin and host binary share the exact samerustcversion, target, andtessera-uisource fingerprint. - Safety & memory invariants:
src/plugin/is the only module intessera-uiallowed to useunsafe.- No workspace crate sets a
#[global_allocator]. Allocations freed across the boundary go through the factory vtables. entryruns insidestd::panic::catch_unwindso no panic ever unwinds across the C ABI.- The loader intentionally never unloads loaded plugins, keeping them for the process lifetime. Their
&'static dyn UiProviderFactoryvtables and&'static strpointers remain live, and GObject/Qt types cannot be unregistered.
Conformance suite
Every UI provider runs against a shared conformance suite in tessera-ui:
conformance::rows&conformance::peers(src/conformance/): Validates that every provider realizes allControlKinds, section rows, and navigation states consistently. It also tests probe behavior (assert_probe_follows) and enforces the position tolerance ratchet (assert_tolerance_ratchetagainstPEER_TOLERANCE_CEILING).- Focal conformance tests:
cargo test -p tessera-ui --test provider_conformance --test control_plan --test os_providers_contract_test - Cross-provider parity:
crates/tessera-app/tests/cross_provider_ui_parity.rsandui_plugin_loader.rsvalidate provider selection, plugin header rejection on mismatch, and parity across providers.
How to add a control or UI provider
Adding a new control or preference row
- Settings & config: Add any new preference key, default, and bounds to
tessera-settings, and register itsCONFIG_KEYSentry (KeyKind::Preference) intessera-config. - Localization: Add the label, description, and validation error message IDs to all 10 Fluent catalogs in
crates/tessera-i18n/i18n/<locale>/tessera.ftl. - Neutral model & tree (
tessera-ui):- Add the field to
PreferencesModel(src/preferences/model.rs) andPreferencesChange(src/preferences/change.rs). - Register a
ControlIdinsrc/preferences/edit/control_id.rsand handle its edit/validation insrc/preferences/edit/andparse.rs. - Declare the row in the appropriate page tree under
src/preferences/pages/using existingNodeKind,ControlKind, and semantic tokens (Spacing,Color,Text,ControlSize).
- Add the field to
- Providers: If you introduced a new
ControlKindor semantic token variant, exhaustivematchstatements intessera-ui-gtk,tessera-ui-adwaita,tessera-ui-qt,tessera-ui-macos, andtessera-ui-windowswill guide every native binding. - Tests: Run
cargo test -p tessera-ui --all-featuresandcargo test -p tessera-i18n --test locale_parity.
Adding a new UI provider
- Create the crate
crates/tessera-ui-<name>(and acdylibplugin crate if loaded dynamically on Linux, usingexport_ui_plugin!). - Implement
UiProviderFactoryandUiProvider(tessera_ui::provider), mapping everySpacing,Color,Text,ControlSize, andMeasuretoken in one fixed translation table and realizing theNodeIdtree viarealize/diff. - Implement application duty consumption via
ApplicationHandle, emittingUiEvents rather than mutating local state. - Register & test: Wire the provider into
UiRegistryincrates/tessera-app/src/platform/, add it to thetessera-uiconformance suite (provider_conformance,os_providers_contract_test), and validate all controls againstPEER_TOLERANCE_CEILING.