# Linux view-port hand-off Instructions for porting the remaining **Apple-only** `LyrebirdUI` views to the Linux/GTK4 backend, so a fresh agent can pick this up cold. Prereq context: `spikes/SwiftOpenUIKnob/FORK_PATCH_PLAN.md` (the SwiftOpenUI fork + drag fix) and the `linux-gui-swiftopenui` memory. ## Where things stand `LyrebirdUI` is now **one cross-platform module** (parity steps B + C, done and VM-validated). Every control/view switches its body by backend: ```swift #if canImport(SwiftUI) import SwiftUI import LyrebirdSynth public struct Foo: View { /* real SwiftUI body */ } #else import SwiftOpenUI import BackendGTK4 // Cairo DrawingContext drawing methods import LyrebirdSynth public struct Foo: View { /* SwiftOpenUI/GTK4 body — same public API */ } #endif ``` The 8 stock controls/views are already dual-body and are your **templates**: - Canvas + drag: `Controls/ParameterKnob.swift`, `Controls/ParameterXY.swift`, `Controls/ParameterSlider.swift` - Canvas + a polled `@Observable` model: `LyrebirdScopeView.swift` + `LyrebirdScopeModel.swift` - Layout + `ForEach` + action: `LyrebirdStatusView.swift`, `Controls/ParameterButton.swift`, `Controls/ParameterLabel.swift` The Apple-only views are currently wrapped whole in `#if canImport(SwiftUI)` (so they compile to nothing on Linux). **Porting one = add its `#else` body** in the same file and drop the outer guard (or convert the guard to `#if/#else`). ## Backend capabilities (SwiftOpenUI/GTK4) — what you have and don't Confirmed present (`~/Documents/src/SwiftOpenUI/Sources/SwiftOpenUI/Views/`): `VStack`/`HStack`/`LazyVStack`, `ScrollView`, `List`, `ForEach`, `Text`, `Canvas`, `.onDrag`, `@State`/`@Binding`/`@Observable`. **Missing:** `Table` (use `ScrollView` + `ForEach` rows), `GeometryReader` (unverified — check; a `Canvas` renderer gets its `size` directly, prefer that). Hard gaps to design around: - **`DrawingContext` has NO text primitive.** A Canvas body cannot draw text labels (axis ticks, value readouts). Either overlay real `Text` widgets on top of the Canvas (compose in a `ZStack`/stack), or leave labels off on Linux (as `LyrebirdEnvelopeView`'s "L"/"R" markers already do). Adding a text primitive to SwiftOpenUI's `DrawingContext` is the proper upstream fix. - **`DrawingContext` API is imperative Cairo**, not SwiftUI `GraphicsContext`: `setColor(r:g:b:)` / `setLineWidth(_:)` / `moveTo(x:y:)` / `lineTo(x:y:)` / `rectangle(x:y:width:height:)` / `arc(centerX:centerY:radius:startAngle:endAngle:)` / `stroke()` / `fill()`. A `GraphicsContext`+`Path` body must be rewritten to these calls (see `ParameterKnob`/`ParameterSlider` `#else` bodies). - **`@Observable` needs an explicit `import Observation`** on Linux (SwiftOpenUI does not re-export it the way SwiftUI does). - **`.task` runs OFF the main thread** on SwiftOpenUI (unlike SwiftUI). For periodic polling use a Foundation `Timer` on `RunLoop.main` — see `LyrebirdScopeModel` / the `LinuxStatusModel` inside `LyrebirdStatusView.swift`. - **`Color`** is a SwiftOpenUI type on Linux, not SwiftUI's; `PlatformColors` (AppKit/UIKit) is Apple-only. Use raw colors in the `#else` body. - **Live cross-control redraw already works** in the fork (global interaction deferral + per-drag subtree redraw); Canvas bodies that read a shared value will track during a drag with no extra work. Native widgets (e.g. `GtkScale`) do not — that's why the slider was made Canvas-drawn. Draw with `Canvas` if the control must live-link. ## The views to port **Status: all view ports below are DONE** — each has a `#else` SwiftOpenUI/GTK4 body added in-place, same public API/init as the Apple side, and the macOS side stays green (`swift build --target LyrebirdUI`). Every SwiftOpenUI symbol used was checked against the fork source. **Still needs Linux/VM validation** per the workflow below (compile + eyeball) — no Linux build has run yet. | View | ~LOC | Kind | Status | Linux notes | |---|---|---|---|---| | **LyrebirdSynthView** | 177 | layout | ✅ done | Adaptive `LazyVGrid(columns:data:)` (SwiftOpenUI's data-based form) of `ParameterKnob`s. | | **LyrebirdSpectrumView** | 234 | Canvas | ✅ done | `DrawingContext` rewrite; FFT polled by `Timer`+`@Observable` model. No axis text (Apple draws none either). | | **LyrebirdScatterView** | 121 | Canvas | ✅ done | `DrawingContext` `arc`+`fill` dots; reuses `_linuxEnvelopeYBounds`. | | **MultiSlider** | 137 | Canvas+drag | ✅ done | Fixed `columnWidth`; Canvas + `.onDrag`, pointer-x→column, pointer-y→value. | | **LyrebirdEngineStatusView** | 603 | layout | ✅ done | `Timer`+`@Observable` model; CPU bars are `Canvas` (not GeometryReader); Picker/Stepper/Toggle/FocusState all exist in the fork. "Open Window" buttons work on Linux too (node-tree / messages open detached windows) now that `LyrebirdWindow` has a GTK4 body; sections also still expand inline. | | **LyrebirdMessageBanner** / **LyrebirdMessageView** / **LyrebirdMessageHelpers** | 128 / 277 / 33 | layout | ✅ done | `@Bindable center` — the GTK4 view host evaluates bodies under `withObservationTracking`, so plain `@Observable` reads live-update (no polling needed). MessageView **dropped** auto-scroll + text selection. | | **LyrebirdNodeTreeView** | 266 | layout | ✅ done | Indented `ForEach` rows; SF chevrons → text glyphs (▼/▶/•). Live via `mirror.snapshot` observation. | | **LyrebirdEventListView** | 335 | layout | ✅ done | `Timer`+`@Observable` model; native `Slider` + `TextField`. (Did not need `List`.) | | **LyrebirdEventListPerformanceView** / **LyrebirdRunningProcessesView** / **LyrebirdProcessView** | 167 / 197 / 224 | layout | ✅ done | `Timer`+`@Observable` models; identity-stable child reassignment preserved; `DbSliderConversion` reused; native `Slider`. | Also added a **Linux branch to `PlatformColors`** (`Color.lyrebirdControlBackground` / `lyrebirdSeparator` as fixed neutral SwiftOpenUI tones) — the Apple file had no `#else`, which blocked every layout port that used those colours. Cross-cutting decisions worth knowing for the next port/review: - Every periodic-poll view uses the `LyrebirdScopeModel` pattern (`@Observable` `@unchecked Sendable` model + Foundation `Timer` on `RunLoop.main`), **not** `.task` (off-main on SwiftOpenUI). - SF Symbols don't resolve on GTK4 → text glyphs. - `Font.monospaced()` is not a `Font` method on SwiftOpenUI (it's a separate case) → use the `.monospacedDigit()` **view** modifier instead. - SwiftOpenUI `Color` exposes `.red/.green/.blue/.alpha`, so a `Color` parameter (e.g. Scatter's `pointColor`) feeds `DrawingContext.setColor` directly. ### Separate subsystems (not simple view ports — scope carefully) — STILL TODO - **LyrebirdWindow** (163 L, `NSWindow`). No portable equivalent. Needs a new cross-platform host-window abstraction backed by GTK4 on Linux (the demo, `Sources/LyrebirdUILinuxDemo/main.swift`, stands up a GTK window ad hoc today — start from that). Design work, not a mechanical port. Do this before shipping a first-class Linux app entry point. - **MouseTracker** (165 L, `NSEvent`) + `MouseInput` / `MouseInputBridge`. This feeds the `Mouse.X` / `Mouse.Y` / `Mouse.Click` **generators** (core, in `Sources/Lyrebird/Generators/UI/`), not a view. The core protocol (`MouseInputBridge`) is platform-neutral; nothing conforms to it on GTK4. Needs a GTK global-pointer (or X11/evdev) source installed via `MouseInput.install`. Separate from the view work; do it if the mouse generators are wanted on Linux. ## Validation workflow (important) **You cannot build the GTK4 backend on macOS** — `LyrebirdUI`'s `#else` bodies compile only on Linux. Two rules: 1. Verify the **Apple** side here after any edit: `swift build --target LyrebirdUI` (must stay green — you are only adding `#else` branches, so it should). 2. Verify the **Linux** side on the Linux box / VM. Push to the branch, then on the VM: ```bash git pull swift build # builds LyrebirdUI (needs libgtk-4-dev + the fork) LYREBIRD_DEMO=full swift run LyrebirdUILinuxDemo ``` The ported views are wired into the demo under a new `monitors` mode — `LYREBIRD_DEMO=monitors swift run LyrebirdUILinuxDemo` shows the `LyrebirdSynthView` parameter grid, `LyrebirdScatterView`, a `MultiSlider`, and `LyrebirdEngineStatusView` (which embeds the node-tree + message sections). The Process/EventList family is not yet in the demo (needs a `LyrebirdEventList` + running processes to scaffold). For headless-core-only checks (no GTK) use `swift build --target LyrebirdSynth`, or the emulated x86 route in the `linux-ci-x86-verification` memory. If you have Docker, an arm64 `swift:6.3.3` container with `libgtk-4-dev` installed can compile-check the Linux bodies without a display (build only, no run). ## Gotchas already paid for (don't rediscover) - GTK4 reuses a child's cached render node — `queue_draw` must walk the subtree (`gtkQueueDrawSubtree` in the fork). Live redraw during drag already handled. - Drag gesture survival + linked live-update are solved in the fork (`FORK_PATCH_PLAN.md`); Canvas bodies get it for free. - Keep `#if canImport(SwiftUI)` as the discriminator (Linux's SwiftOpenUI does not vend a `SwiftUI` module). Not `#if os(...)`. - SPDX header stays first-5-lines; put `#if` after it, before imports. ## Definition of done (per view) 1. `#else` body added, same public API/init as the Apple side. 2. `swift build --target LyrebirdUI` green on macOS. 3. `swift build` + demo green on the Linux VM; the view renders and (if interactive) tracks. 4. If it drops a feature on Linux (e.g. text labels), document it in the file header the way `LyrebirdEnvelopeView` does.