Lyrebird 2.0.0 — Linux support

Consolidated release: the cross-platform Linux port (engine, generators, CLI,
REPL, NRT, portable DSP), live ALSA audio + ALSA MIDI + POSIX OSC + portable
WAV codec, the GTK4 GUI (LyrebirdUI on the SwiftOpenUI backend), and the Linux
live-coding scratchpad (LiveCompile). Apple platforms unchanged; all additive.
See RELEASES.md and LINUX_README.md.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-09-10 21:09:11 -07:00
parent 77580ee98e
commit b6fdee8bfc
293 changed files with 16800 additions and 775 deletions
+123
View File
@@ -5,6 +5,7 @@
// SPDX-License-Identifier: MIT
#if os(macOS)
#if canImport(SwiftUI)
import AppKit
import SwiftUI
@@ -159,3 +160,125 @@ public final class LyrebirdWindow {
}
}
#endif
#elseif os(Linux)
import Foundation
import SwiftOpenUI
import BackendGTK4
/// LyrebirdWindow — a standalone GTK4 window hosting SwiftOpenUI content.
///
/// The Linux counterpart to the macOS `NSWindow` + `NSHostingController` host.
/// Opens a top-level `GtkApplicationWindow` (via
/// `GTK4Backend.openStandaloneWindow`) whose child is the rendered SwiftOpenUI
/// view. Same public shape as the macOS side — `init(title:width:height:)`,
/// `open(content:)`, `close()` — so `presentInWindow(...)` convenience methods
/// work identically on both platforms.
///
/// ## Requirements
///
/// A `GtkApplication` main loop must already be running — i.e. the process is
/// inside `GTK4Backend().run(App)`. Opening a window from a CLI/REPL with no
/// running application is a no-op (`open` leaves the window closed); use the
/// declarative `App`/`WindowGroup` scene as the process entry point, then open
/// further windows imperatively with `LyrebirdWindow`.
///
/// ## Threading
///
/// GTK is single-threaded; every method must run on the GTK main thread. Unlike
/// the macOS `@MainActor` class, this is left nonisolated to match the rest of
/// the Linux/GTK4 UI and the SwiftOpenUI backend, which are all confined to the
/// GTK main loop rather than the Swift main actor — a nonisolated SwiftOpenUI
/// `body` and `Button` action can then drive it without an actor hop.
public final class LyrebirdWindow {
// MARK: - Configuration
/// Window title-bar text.
public let title: String
/// Initial window width in points.
public let width: Double
/// Initial window height in points.
public let height: Double
// MARK: - Private state
private var handle: GTK4StandaloneWindowHandle?
/// Bumped on every `open()`. The `onClose` closure captures the generation
/// live at open time and only clears `handle` if it still matches, so a stale
/// destroy signal from a previously-closed window (were it ever delivered
/// asynchronously) can't null out a newer window's handle on rapid reuse.
private var generation: Int = 0
// MARK: - Init
/// Creates a `LyrebirdWindow` with the given display properties.
///
/// The window is not shown until `open(content:)` is called.
///
/// - Parameters:
/// - title: Text shown in the window's title bar.
/// - width: Initial window width (default 400 pt).
/// - height: Initial window height (default 300 pt).
public init(
title: String = "Lyrebird",
width: Double = 400,
height: Double = 300
) {
self.title = title
self.width = width
self.height = height
}
// MARK: - State
/// Whether a window is currently open for this instance.
public var isOpen: Bool { handle?.isOpen ?? false }
// MARK: - Open
/// Opens the window and displays the provided SwiftOpenUI content.
///
/// If a window is already open for this instance, it is closed and replaced
/// with a new one hosting the updated content. If no `GtkApplication` is
/// running, this is a no-op.
///
/// - Parameter content: A `@ViewBuilder` closure returning any SwiftOpenUI
/// `View`.
public func open<Content: View>(@ViewBuilder content: () -> Content) {
closeWindow()
generation &+= 1
let token: Int = generation
// `onClose` fires on the GTK main thread when the user closes the window;
// clear our handle so `isOpen` reflects it — but only if this is still the
// current window (guard against a stale callback from a replaced one).
handle = GTK4Backend.openStandaloneWindow(
title: title,
width: Int(width),
height: Int(height),
onClose: { [weak self] in
guard let self, self.generation == token else { return }
self.handle = nil
},
content: content
)
}
// MARK: - Close
/// Closes and destroys the window.
public func close() {
closeWindow()
}
// MARK: - Private
private func closeWindow() {
handle?.close()
handle = nil
}
}
#endif