Layout as policy
Doc status: proposal. Nothing built or decided; open owner questions. Checked 2026-11-10.
Status
Proposal of 2026-11-10, stream B of audit-2026-11-10.md (finding F2). Nothing in this file is built or decided. It needs owner decisions (section Open questions) before any phase starts. The current contracts stay those of tiling-spec.md, canvas-windows.md and grid-on-canvas.md.
Problem
Every layout is Rust code in the compositor: the cell grid of native/smithay/src/grid.rs (6 x 4 cells, fill, step, resize, place), the Canvas camera and its row of canvas_arrange and canvas_organize (native/smithay/src/desktop/canvas_mode.rs), and the closed Layout enum of native/smithay/src/desktop.rs (Floating, Grid, Focus, Monocle, Pair, Canvas). A new tiling (columns, master and stack) or a snap to halves and quarters needs a compositor change, a build and a new login. The philosophy of the project asks for window mechanics that change with no compositor code and no restart.
Keys and animation timing already moved to data (the keybinding table and the motion timing that the core sends, contextual-actions.md). Layout is the larger part of F2 and is only proposed here.
What stays in the compositor
A layout policy only answers "where does each window go". Everything else stays where it is, with no new authority:
- Input, focus, the keyboard rule of client requests, grabs, gestures and the Super mode.
- Stacking and the bands of window-layers.md. A policy never places a shell window, the chat, a panel or the lock, and never changes a band.
- Every refusal: a window that the user holds (
userHeld) keeps its place, nothing moves while locked, the agent limits (user_active,rate_limited) stay, and client minimum sizes always win over a rectangle. - The camera of Canvas, its fit, its clamp and its lease.
- Window pixels never reach web code. A policy sees ids, application ids, titles only if the owner allows it (open question 3), sizes and minimums.
- The rejection of 2026-10-28 stays: no dragging windows between overview cards.
Who may set a policy
Only the core, on the control connection, like hot_corners and the keybinding table. Where the user picks or edits a policy (a protected setting or a profile file) is open question 1. No agent tool, MCP entry, scheduled turn, generated HTML or plugin panel sets, edits or runs a policy. The agent keeps its typed window actions; a later decision could let arrange_windows name a policy id from the installed list.
Option A: declarative slots
A policy is a JSON document that the compositor evaluates itself, in the same frame as today's layouts, with no round trip.
{
"id": "halves",
"label": "Metades",
"gap": 8,
"layouts": [
{ "count": 1, "slots": [[0, 0, 1, 1]] },
{ "count": 2, "slots": [[0, 0, 0.5, 1], [0.5, 0, 0.5, 1]] },
{ "count": 3, "slots": [[0, 0, 0.5, 1], [0.5, 0, 0.5, 0.5], [0.5, 0.5, 0.5, 0.5]] }
],
"overflow": "float",
"snapZones": [
{ "edge": "left", "slot": [0, 0, 0.5, 1] },
{ "edge": "right", "slot": [0.5, 0, 0.5, 1] },
{ "corner": "topLeft", "slot": [0, 0, 0.5, 0.5] }
]
}
- A slot is
[x, y, width, height]in fractions of the work area of the output (the area after the bars and the chat margin that the compositor already computes). layoutspicks the entry whosecountequals the number of tiled windows;overflowsays what happens past the largest count:float(as the grid does when no cell is free) orlast(the extra windows share the last slot as a stack).- Windows fill slots in the order the compositor keeps today (focus recency or the order of arrival, the same as
grid::fill). The user can swap two windows with the existing move keys, which become "next slot" and "previous slot" under a policy. snapZonesdrive a snap while the user drags a window: entering an edge or corner zone of the output shows the target with the existing window finish outline (tiling-spec.md uses it for the cell outline), and the release places the window in that slot. No native UI is added.- Validation, in the core and again in the compositor: at most 16 entries in
layoutsand 16 slots in each, every fraction finite and in [0, 1], every slot inside the area,gapfrom 0 to 64, at most 12 snap zones, ids from a closed character set. A slot smaller than the minimum size of its client floats that window, as the grid does today.
Strengths: synchronous, deterministic, testable with the existing in-process harness, and easy to bound. Limit: no logic past "count picks a template", so master and stack with a variable ratio or a scrolling layout need option B.
Option B: a policy script
The core runs a policy function and sends the result. The function gets a snapshot (work area, ordered tiled windows with ids, minimum sizes and the held flags) and returns rectangles. The core sends:
{ "action": "layout_apply", "workspace": 3, "revision": 41, "rects": [{ "window_id": 7, "x": 0, "y": 32, "width": 960, "height": 1016 }] }
- The compositor checks each rectangle (inside the area, at least the client minimum, a known tiled window of that workspace, not held) and refuses a stale
revision(the window set changed after the snapshot). A refused rectangle leaves that window where it is. - A new window cannot wait for the core with nothing on screen: the compositor places it with the built-in layout first, then applies the answer if it comes within a short timeout. This costs one visible move per map, the main reason to prefer option A for common layouts.
- The script runs in the core, never in generated HTML, a plugin iframe or the agent. If it is a profile file it has the authority of the core process; open question 2.
Recommendation
Start with option A for the Grid base: it covers snap to halves and quarters and the common tilings, keeps every rule in the compositor and needs no round trip. Keep the current grid as the built-in policy grid so nothing changes for a profile that sets nothing. Treat option B as a later phase, only if a wanted layout does not fit slots.
On Canvas the same slots could feed "Organizar janelas" and Super+G (today a row): a slot in fractions of the fit viewport maps to a canvas rectangle at zoom 1. This keeps the camera rules and is a separate step.
Phases (proposal)
- Data and validation: the policy shape in the core and the compositor, with unit tests and no behavior change.
- Compositor evaluation behind a capability flag, the built-in
gridunchanged, one installed policy (halves) selectable only by the core, in-process tests and nested QA throughscripts/nested-qa.py(one output, no gestures). - Snap zones while dragging, with the existing outline.
- Persistence:
window-session.jsonsaves the slot index of each window under a policy, like the cells today. - Canvas arrangement from slots.
- Option B, if the owner wants it.
Each phase keeps the rollback a git revert and the version skew safe through the capability flag: an older compositor gets no policy command, an older core sends none and the built-in layouts run.
Open questions
- Where does the user pick and edit a policy: a protected setting in Configurações with a closed list of installed policies, a profile file (
<profile>/layouts/*.json) that the core watches, or both? - Is option B wanted at all, and if so may a policy script live in the profile (it then runs with the authority of the core, like the overlay of the chat host)?
- May a policy see application ids and titles to place known applications (for example a terminal always on the right), or only ids and sizes?
- Does a policy replace the 6 x 4 cell grid as the Grid layout, or is it a new layout next to Grid and Canvas?