OrbitEngine
Workspaces, profiles, tab organisation, Split, Blink (tab suspension), Focus and session orchestration.
Packages/NavigatorKit/Sources/OrbitEngine. Pure logic: imports NavigatorCore, Persistence, Foundation and
CoreGraphics (for CGPoint / CGSize / CGRect only). No WebKit, no SwiftUI. The UI layer draws and releases
web views; this module decides and keeps the books.
| File | What it is |
|---|---|
OrbitalLayout.swift |
Geometry of the orbital view (pure) |
TabLayout.swift, TabOperations.swift |
The five tab layouts and tab rules (pure) |
SplitEngine.swift |
Split layouts, geometry, device limits (pure) |
BlinkPolicy.swift, BlinkCoordinator.swift |
Suspension policy (pure) and its bookkeeping (actor) |
FocusSession.swift |
Focus state machine (pure) and FocusController (actor) |
SessionOrchestration.swift |
Coalescing, debounced session writes, launch restoration |
FuzzySearch.swift |
Fuzzy matcher and search across spaces and tabs (pure) |
OrbitService.swift |
The actor the UI calls for anything that is stored |
Orbital view
Spaces are satellites on concentric rings around a core. OrbitSpace.ring and OrbitSpace.angle are the stored
position; everything else is computed.
- Projection. Rings are circles seen under a tilt: the point at angle
aof a ring of radiusris drawn at(cx + r·cos a, cy + r·sin a·cos tilt). Angles are radians, 0 at the right, growing clockwise on screen;-π/2is the top.depth = sin a(−1 at the back/top, 1 at the front/bottom) scales the satellite by1 + depthScale·depthand gives the painter's order (OrbitalLayout.satellitesreturns back to front). - Metrics (
OrbitalMetrics.standard): first ring radius 150, ring spacing 110, satellite diameter 56, minimum gap 18, tilt 0.45 rad, depth scale 0.12, rings 0…7. Zoom (OrbitalViewport, 0.25…4) scales everything together, so placement does not depend on zoom or on the window size. - No overlap. Two satellites of a ring separated by a chord
care at leastc·cos tiltapart on screen, so the minimum angular separation of a ring is2·asin((largestDiameter + gap) / (2·r·cos tilt))and the ring capacity is⌊2π / separation⌋. With the standard metrics the capacities are 10, 18, 25, … and the total isOrbitalLayout.totalCapacity(). Adjacent rings areringSpacing·cos tilt≈ 99 points apart at their closest point, more than the largest satellite plus the gap. - Automatic placement (
placement(forNewSpaceAmong:)): innermost ring with room, in the middle of its widest gap; the top of the ring when it is empty. Existing satellites are never moved, so a ring can be left before its nominal capacity (see the function's comment);evenSlots/OrbitService.tidySpacesis the arrangement that reaches it. - Hit-testing (
hitTest): front-most satellite containing the point, optional slop for touch. - Drag (
drop): nearest ring; the angle snaps to the ring's regular grid when the pointer is within a quarter of a grid step of a grid position; if the place is taken, the nearest free angle of the ring, then the nearest ring with room. The result says whether it snapped or was displaced. - Accessible equivalents.
listOrder(the user's order:order, creation date, id) is what VoiceOver, the sidebar and the grid use.spatialOrder(ring, then clockwise from the top) is for arrow keys inside the orbital view.gridFrameslays the same list out as a grid. Archived spaces are in none of them.
Tab layouts
TabLayout.presentation(mode:tabs:groups:selected:size:) returns what each TabLayoutMode displays:
| Mode | Result |
|---|---|
vertical |
Sections: pinned (flat), each group in order (a collapsed group keeps its header, a hidden count, and the selected tab if it is inside), ungrouped tabs. Rows carry a tree depth from parentID (capped at 6; orphans and cycles become roots; subtrees can be collapsed). |
horizontal |
The same flat order fitted in the strip width: pinned tabs have a fixed width, the others share the rest between a minimum and a maximum; what does not fit goes to the overflow menu, and the selected tab is always swapped in. |
compact |
The current tab, the count, and the most-recently-used list for the switcher. |
grid |
Flat order and thumbnail frames. |
orbit |
Pinned tabs evenly on ring 0, the others on the following rings; tabs beyond the capacity have no slot and are shown in the list. |
Display order everywhere: open tabs only, pinned first, then order, creation date, id — the same rule as
storage.
Split
SplitEngine works on SplitLayout values and never touches storage: adding, removing (returns nil when
fewer than two panes remain), replacing (swaps when the tab is already shown), moving, changingAxis,
equalized, focusingNext / focusingPrevious, resizing, restored, paneRects, dividers, pane(at:).
fractionsare widths (horizontal), heights (vertical), or — forgrid— weights inside a row. Grid rows are 2 → [2], 3 → [2, 1], 4 → [2, 2], 5 → [3, 2], 6 → [3, 3], 7 → [4, 3], 8 → [4, 4], with equal row heights; in a container more than 1.2× taller than wide the lines are columns instead.- Resizing a divider changes only its two neighbours and keeps each at least
minimumLengthpoints (240 by default); when the pair is smaller than twice the minimum it splits evenly. restoredvalidates a stored layout: panes whose tab is gone and duplicates are dropped, the device limit is applied, unusable fractions fall back to equal sizes.
Pane limits (SplitCapacity.maximumPanes). Product limits, not measurements:
| Device | Panes |
|---|---|
| iPhone | 1 (no Split; the UI offers a quick switch between recent tabs) |
| iPad, compact width | 2 |
| iPad, regular width | 3, or 2 below 6 GB of physical memory |
| Mac | 8 from 24 GB, 6 from 16 GB, 4 below |
Blink
BlinkPolicy.evaluate(tabs:budget:pressure:now:) is a pure function returning suspend / resume decisions with
reasons:
- A visible tab without a web view is resumed (
becameVisible). - Protected tabs are never suspended at any pressure level: visible (including every pane of a split), capturing
camera / microphone / screen, playing audio, holding unsubmitted form input, excluded by the user (per tab for
the run, or per host — stored). They still count against the limit; the plan reports
overLimitBy. - With an idle limit, an unprotected, unpinned tab idle for longer is suspended (
idle). - While live web views exceed the limit, unprotected live tabs are suspended, unpinned before pinned, least recently active first. Under normal pressure a tab used in the last 30 s is spared; under memory pressure nothing unprotected is.
Limit by pressure: the budget (normal), half of it (warning), zero beyond the protected tabs (critical).
Automatic budget (BlinkBudget.automatic), a heuristic derived from physical memory, overridable by the user
(BlinkCoordinator.setMaximumLiveWebViews, setting blink.maximum_live_web_views, 0 = automatic):
| Physical memory | Mac | iPad | iPhone |
|---|---|---|---|
| 4 GB | 4 | 3 | 3 |
| 8 GB | 6 | 4 | 4 |
| 16 GB | 12 | 8 | 6 |
| 32 GB | 24 | 8 | 6 |
| 64 GB and more | 40 | 8 | 6 |
BlinkCoordinator (actor) holds the live signals reported by the web layer (report(_:for:),
setVisibleTabs), the exclusions and the settings, builds the plan (plan(for:pressure:)) and records each
transition the UI carried out (confirm, record) in the tab's lifecycle through database.tabs. Private
tabs are tracked in memory (trackGhostTab).
What "unsubmitted form input" means is defined by the page script of the web layer, not here: this module only receives the flag. A page that keeps its state in JavaScript without form fields is not detected and loses that state when suspended, like in other browsers.
Focus
FocusSession is a value-type state machine: idle → running ⇄ paused → finished (start, pause, resume,
end), with an optional timer. Every transition takes now; elapsed, remaining and deadline are computed,
pauses do not count, and refresh(now:) finishes a session whose timer ran out at the time it ran out.
FocusController (actor, injectable clock) keeps one session per space, stores FocusSettings with the space
(in memory for a private space), captures a FocusRestoration per window at start (sidebar, agent panel, tab
layout) and returns them at end so the UI puts the chrome back. Sessions are in memory: they do not survive a
relaunch.
Session orchestration
SessionChangeCoalescershortens a sequence ofSessionChanges while guaranteeing the same stored result (rules in its comment). A test applies random sequences both ways to two databases and compares them.SessionOrchestrator(actor):record(_:)queues changes, a flush happens 400 ms after the last change and at most 2 s after the first unflushed one;flush()andshutdown()(flush + clean-shutdown mark) are explicit. Changes of private windows, spaces and tabs are dropped before they are queued. If storage refuses the atomic batch, changes are retried one by one and the refusals reported without page data.SessionRestorer.launch(database:policy:paneLimit:)runsbeginSession()+restore()and returns aLaunchModel:firstLaunch,restored(only the selected tab and split panes of each window are intabsToLoad; the rest stays dormant),crashRecovery(windows are provided but nothing loads untilconfirmingRestore, so a page that crashed the app is not reloaded automatically) orfresh. Repairs: missing selected tab, invalid split, windows without tabs (closed in storage), windows of archived spaces (left alone).
OrbitService
Actor over the stores; holds no state. Private (ghost) profiles, spaces, windows and tabs are refused with
OrbitError.ghostNotPersisted: they live in memory in PrivacyEngine.GhostSession.
Rules worth knowing:
bootstrap()is idempotent and guarantees one profile and one active space.- A profile keeps at least one active space; the last profile cannot be deleted.
- Pinned tabs are flat: pinning removes the tab from its group and from the tree.
- Closing or moving a tab away fixes the window it leaves: selection (next tab, else previous), split (the pane is removed; the split ends below two panes), children (adopted by the tab's parent).
- Moving a tab to another space drops its group. Moving it to another profile also drops its WebKit session state: the back/forward list and form state of one profile never enter another; the page reloads from its URL in the other profile's data store.
- "Reopen closed tab" reopens in the original window when it is still open, else in an open window of the space, else in a new one.
Not verified
- Nothing here was exercised with real web views: the Blink budgets and pane limits are heuristics.
SplitCapacity.currentPlatformon a physical iPad / iPhone (model-name detection) was only compiled.- The read-modify-write in
BlinkCoordinator.setLifecyclecan overwrite a concurrenttouchTabof the same tab; a lifecycle-only update inTabStorewould remove the race.