From f001fb2eb2a65a802b9fb0e903ed46781d7c568d Mon Sep 17 00:00:00 2001 From: foxnne Date: Fri, 9 Oct 2026 15:05:49 -0500 Subject: [PATCH] backend: fizzy's native backend is a package of its own `src/backend/native` becomes `backend/`, a package beside `sdk/`: SDLBackend, GpuRenderer, viewport_map, platform/** and the shaders, with SDL, zig-objc and zigwin32 pinned in its own build.zig.zon. Its build.zig wires it under the caller's dvui (`backendModule`, `platformModule`) and attaches its Objective-C to its own modules rather than to fizzy's executable; dvui stays pinned in sdk/ alone. Fizzy depends on it by path and reaches objc and win32 through it. No change in behaviour: the first step toward an app on dvui and this backend without the rest of fizzy. --- .sb/layout.zon | 27 --- .sb/log.txt | 41 ----- .sb/recents.zon | 6 - CLAUDE.md | 2 + backend/build.zig | 163 ++++++++++++++++++ backend/build.zig.zon | 29 ++++ .../native => backend/src}/GpuRenderer.zig | 0 .../native => backend/src}/SDLBackend.zig | 2 +- .../native => backend/src}/macos_monitor.m | 0 .../src}/platform/blur_region.zig | 0 .../src}/platform/dialogs.zig | 0 .../src}/platform/geometry.zig | 0 .../src}/platform/gestures.zig | 0 .../src}/platform/linux_titlebar.zig | 0 .../src}/platform/macos/live_resize_trace.m | 0 .../src}/platform/macos/menu_target.m | 0 .../src}/platform/macos/visual_effect_view.m | 0 .../src}/platform/macos/window_monitor.m | 0 .../src}/platform/macos_monitor.zig | 0 .../native => backend/src}/platform/menu.zig | 0 .../src}/platform/open_events.zig | 0 .../native => backend/src}/platform/root.zig | 2 +- .../src}/platform/titlebar.zig | 0 .../src}/platform/wayland_blur.zig | 0 .../src}/platform/win32_titlebar.zig | 0 .../src}/platform/window.zig | 0 .../src}/platform/window_layout.zig | 0 {src/backend/native => backend/src}/sdl3-c.h | 0 .../compiled/dxil/default.fragment.dxil | Bin .../shaders/compiled/dxil/default.vertex.dxil | Bin .../shaders/compiled/msl/default.fragment.msl | 0 .../shaders/compiled/msl/default.vertex.msl | 0 .../compiled/msl/program_example.fragment.msl | 0 .../shaders/compiled/spv/default.fragment.spv | Bin .../shaders/compiled/spv/default.vertex.spv | Bin .../src}/shaders/default.fragment.hlsl | 0 .../src}/shaders/default.vertex.hlsl | 0 .../shaders/program_example.fragment.hlsl | 0 .../src}/shaders/shared.hlsl | 0 .../native => backend/src}/viewport_map.zig | 0 build.zig.zon | 24 +-- build/app.zig | 30 ++-- build/exe.zig | 119 +++---------- core/gfx/programs.zig | 2 +- core/gfx/shaders/liquid_glass.metal | 2 +- docs/DEPENDENCIES.md | 18 +- docs/MACOS_LIVE_RESIZE.md | 2 +- scripts/live-resize/record.swift | 2 +- spikes/windows-composition/build.zig.zon | 2 +- spikes/windows-composition/src/sdl3-c.h | 2 +- src/backend/backend_native.zig | 4 +- 51 files changed, 263 insertions(+), 216 deletions(-) delete mode 100644 .sb/layout.zon delete mode 100644 .sb/log.txt delete mode 100644 .sb/recents.zon create mode 100644 backend/build.zig create mode 100644 backend/build.zig.zon rename {src/backend/native => backend/src}/GpuRenderer.zig (100%) rename {src/backend/native => backend/src}/SDLBackend.zig (99%) rename {src/backend/native => backend/src}/macos_monitor.m (100%) rename {src/backend/native => backend/src}/platform/blur_region.zig (100%) rename {src/backend/native => backend/src}/platform/dialogs.zig (100%) rename {src/backend/native => backend/src}/platform/geometry.zig (100%) rename {src/backend/native => backend/src}/platform/gestures.zig (100%) rename {src/backend/native => backend/src}/platform/linux_titlebar.zig (100%) rename {src/backend/native => backend/src}/platform/macos/live_resize_trace.m (100%) rename {src/backend/native => backend/src}/platform/macos/menu_target.m (100%) rename {src/backend/native => backend/src}/platform/macos/visual_effect_view.m (100%) rename {src/backend/native => backend/src}/platform/macos/window_monitor.m (100%) rename {src/backend/native => backend/src}/platform/macos_monitor.zig (100%) rename {src/backend/native => backend/src}/platform/menu.zig (100%) rename {src/backend/native => backend/src}/platform/open_events.zig (100%) rename {src/backend/native => backend/src}/platform/root.zig (90%) rename {src/backend/native => backend/src}/platform/titlebar.zig (100%) rename {src/backend/native => backend/src}/platform/wayland_blur.zig (100%) rename {src/backend/native => backend/src}/platform/win32_titlebar.zig (100%) rename {src/backend/native => backend/src}/platform/window.zig (100%) rename {src/backend/native => backend/src}/platform/window_layout.zig (100%) rename {src/backend/native => backend/src}/sdl3-c.h (100%) rename {src/backend/native => backend/src}/shaders/compiled/dxil/default.fragment.dxil (100%) rename {src/backend/native => backend/src}/shaders/compiled/dxil/default.vertex.dxil (100%) rename {src/backend/native => backend/src}/shaders/compiled/msl/default.fragment.msl (100%) rename {src/backend/native => backend/src}/shaders/compiled/msl/default.vertex.msl (100%) rename {src/backend/native => backend/src}/shaders/compiled/msl/program_example.fragment.msl (100%) rename {src/backend/native => backend/src}/shaders/compiled/spv/default.fragment.spv (100%) rename {src/backend/native => backend/src}/shaders/compiled/spv/default.vertex.spv (100%) rename {src/backend/native => backend/src}/shaders/default.fragment.hlsl (100%) rename {src/backend/native => backend/src}/shaders/default.vertex.hlsl (100%) rename {src/backend/native => backend/src}/shaders/program_example.fragment.hlsl (100%) rename {src/backend/native => backend/src}/shaders/shared.hlsl (100%) rename {src/backend/native => backend/src}/viewport_map.zig (100%) diff --git a/.sb/layout.zon b/.sb/layout.zon deleted file mode 100644 index cd178a5cd..000000000 --- a/.sb/layout.zon +++ /dev/null @@ -1,27 +0,0 @@ -.{ - .x = 300, - .y = 165, - .w = 1200, - .h = 800, - .maximized = false, - .regions = .{ .{ - .name = "Panel", - .extent = 196, - .surfaces = null, - .parent = null, - .from = null, - .shows = null, - .order = null, - .floating = null, - }, .{ - .name = "Sidebar", - .extent = 260, - .surfaces = null, - .parent = null, - .from = null, - .shows = null, - .order = null, - .floating = null, - } }, - .tree = null, -} \ No newline at end of file diff --git a/.sb/log.txt b/.sb/log.txt deleted file mode 100644 index 06d829dc4..000000000 --- a/.sb/log.txt +++ /dev/null @@ -1,41 +0,0 @@ -info: Fizzy version 0.2.0 (Debug) -info(singleton): profile: /Users/foxnne/dev/fizzy-output-scroll/.sb -info(SDLBackend): version: 3.4.16 callbacks -info(SDL_SYSTEM): App name: Fizzy -info(SDL_SYSTEM): App version: 0.2.0 -info(SDL_SYSTEM): App ID: com.foxnne.fizzy -info(SDL_SYSTEM): SDL revision: https://github.com/allyourcodebase/SDL 1.0.3+3.4.16 -debug(SDL_SYSTEM): SDL chose video backend 'cocoa' -info(SDLBackend): SDL3 backend scale 1 -debug(SDL_SYSTEM): SDL chose gpu backend 'metal' -info(SDL_GPU): SDL_GPU Driver: Metal -info(SDL_GPU): Metal Device: Apple M5 Pro -info(GpuRenderer): GPU driver: metal -debug(dvui): adding embedded font Vera Sans -debug(dvui): adding embedded font Vera Sans Bold -debug(dvui): adding embedded font Vera Sans Italic -debug(dvui): adding embedded font Vera Sans Bold Italic -debug(dvui): adding embedded font Vera Sans Mono -debug(dvui): adding embedded font Vera Sans Mono Bold -debug(dvui): adding embedded font Vera Sans Mono Italic -debug(dvui): adding embedded font Vera Sans Mono Bold Italic -debug(dvui): adding embedded font Vera Serif -debug(dvui): adding embedded font Vera Serif Bold -info(dvui): window logical Size.Natural{ 1200 800 } pixels Size.Physical{ 2400 1600 } pixel scale 2 initial content scale 1 snap_to_pixels true accesskit false - -info(macos_monitor): live resize: SDL draws each step in its transaction (fizzy's SDL patches) -debug(dvui): adding embedded font CozetteVector -debug(dvui): adding embedded font CozetteVector Bold -debug(dvui): adding embedded font Comfortaa -debug(dvui): adding embedded font Comfortaa Bold -debug(dvui): adding embedded font Nunito -debug(dvui): adding embedded font Nunito Bold -debug(dvui): adding embedded font Nunito Italic -debug(dvui): adding embedded font Nunito Bold Italic -debug(dvui): adding embedded font PlusJakartaSans -debug(dvui): adding embedded font PlusJakartaSans Bold -debug(dvui): adding embedded font PlusJakartaSans Italic -debug(dvui): adding embedded font PlusJakartaSans Bold Italic -info(dvui): layout: fizzy -debug(menu): menu bar: 4 menus, 20 items, 1 lists -debug(menu): menu bar extras: 0 menus, 1 items diff --git a/.sb/recents.zon b/.sb/recents.zon deleted file mode 100644 index 49b075590..000000000 --- a/.sb/recents.zon +++ /dev/null @@ -1,6 +0,0 @@ -.{ - .last_save_folder = "", - .last_open_folder = "", - .folders = .{}, - .commands = .{}, -} \ No newline at end of file diff --git a/CLAUDE.md b/CLAUDE.md index 1d31c94fc..7f488fa32 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -102,6 +102,8 @@ That constrains how these are written, and the constraint is the point: core/ the shared floor both an app and a plugin dylib draw with — widgets (Split, DockingWidget, Tabs, Tree, Canvas), anim, dialogs, draw, icon, image, fs, paths, math, fuzzy, lsp +backend/ fizzy's native backend, a package of its own: SDL3, its GPU renderer and the platform + pieces (title bars, glass, OS windows); pins SDL, zig-objc and zigwin32 sdk/ the plugin contract: `sdk/src/**` is the SDK itself, the files beside it are its build surface (this directory ships standalone as `fizzy-sdk-v*.tar.gz`); `sdk/tape/` is the std-only demo-tape library shipped with it, `sdk/replay/` the diff --git a/backend/build.zig b/backend/build.zig new file mode 100644 index 000000000..d834644fd --- /dev/null +++ b/backend/build.zig @@ -0,0 +1,163 @@ +//! Fizzy's native backend, as a package an app depends on: SDL3 for the window and its events, an +//! SDL_GPU renderer of its own with custom fragment programs (`GpuRenderer`), and the platform +//! pieces (title bars, the OS's glass, OS windows for floats, menus and dialogs: `platform`). +//! +//! An app builds dvui in its `custom` mode and wires this under it (`backendModule`); +//! `platformModule` gives the platform pieces to an app on this backend or on dvui's own SDL3 one. +//! dvui is the caller's and never pinned here, so the backend compiles against the app's dvui. +const std = @import("std"); + +pub fn build(b: *std.Build) void { + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + const test_step = b.step("test", "Run the backend's std-only tests"); + for (unit_tests) |t| { + const compile = b.addTest(.{ + .name = t.name, + .root_module = b.createModule(.{ .root_source_file = b.path(t.root), .target = target, .optimize = optimize }), + }); + test_step.dependOn(&b.addRunArtifact(compile).step); + } +} + +/// The backend's std-only files with tests of their own, relative to this package: run by +/// `zig build test` here, and by an app's own test step through `dependency.path(root)`. +pub const unit_tests = [_]struct { name: []const u8, root: []const u8 }{ + .{ .name = "backend-window-layout-tests", .root = "src/platform/window_layout.zig" }, + // The hit test Windows' WM_NCHITTEST and Linux's SDL hit test both answer from. + .{ .name = "backend-titlebar-tests", .root = "src/platform/titlebar.zig" }, + // The rounded frame Linux's blur behind the window is stepped into (`wayland_blur`). + .{ .name = "backend-blur-region-tests", .root = "src/platform/blur_region.zig" }, + // Where a viewport's OS window is on the desktop and where its part of the frame lies. + .{ .name = "backend-viewport-map-tests", .root = "src/viewport_map.zig" }, +}; + +/// Where the macOS SDK is, for a macOS target that is not the host's own (`-Dtarget=aarch64-macos` +/// on Apple Silicon): Zig finds it alone for a native build only. +pub const MacosSdk = struct { + include: std.Build.LazyPath, + framework: std.Build.LazyPath, + lib: std.Build.LazyPath, +}; + +pub const Options = struct { + target: std.Build.ResolvedTarget, + optimize: std.builtin.OptimizeMode, + /// Null on a native build. + macos_sdk: ?MacosSdk = null, +}; + +/// The `backend` module wired into each dvui: one per dvui module, however many executables use +/// it. dvui imports it by name, and a second module over the same file in one compilation is an +/// error. +var backend_modules: std.AutoHashMapUnmanaged(*std.Build.Module, *std.Build.Module) = .empty; +/// The `platform` module for each backend module, for the same reason. +var platform_modules: std.AutoHashMapUnmanaged(*std.Build.Module, *std.Build.Module) = .empty; + +/// The backend under `dvui_mod`, a dvui built with `.backend = .custom`, and imported by it as +/// `backend`. Call `platformModule` with the result too: the backend imports the platform pieces. +pub fn backendModule(dep: *std.Build.Dependency, dvui_mod: *std.Build.Module, opts: Options) *std.Build.Module { + if (backend_modules.get(dvui_mod)) |m| return m; + const b = dep.builder; + + // Optimized in a Debug app too: Zig builds C in Debug unoptimized and with its undefined- + // behaviour checks on every call, and SDL is on every frame's path — event pumping, the GPU + // device, every window's present. A Debug frame spent much of itself there (`sample`), and a + // window's way into full screen ran at half the display's rate in Debug alone. The app's own + // code stays Debug; stepping into SDL's C is what a Debug app gives up. + const sdl_optimize: std.builtin.OptimizeMode = if (opts.optimize == .Debug) .ReleaseFast else opts.optimize; + const sdl_dep = if (opts.macos_sdk) |p| + b.lazyDependency("sdl", .{ + .target = opts.target, + .optimize = sdl_optimize, + .include_path = p.include, + .framework_path = p.framework, + .library_path = p.lib, + }) + else + b.lazyDependency("sdl", .{ .target = opts.target, .optimize = sdl_optimize }); + + const sdl_translate_c = b.addTranslateC(.{ + .root_source_file = b.path("src/sdl3-c.h"), + .target = opts.target, + .optimize = opts.optimize, + }); + if (sdl_dep) |sdl| sdl_translate_c.addIncludePath(sdl.artifact("SDL3").getEmittedIncludeTree()); + + const m = b.createModule(.{ + .root_source_file = b.path("src/SDLBackend.zig"), + .target = opts.target, + .optimize = opts.optimize, + .sanitize_c = .full, + .link_libc = true, + .imports = &.{ + .{ .name = "sdl3-c", .module = sdl_translate_c.createModule() }, + .{ .name = "dvui", .module = dvui_mod }, + }, + }); + if (sdl_dep) |sdl| m.linkLibrary(sdl.artifact("SDL3")); + // The backend's AppKit helpers; the module calls them by name. + if (opts.target.result.os.tag == .macos) { + addMacosSdk(m, opts); + m.addCSourceFile(.{ .file = b.path("src/macos_monitor.m") }); + } + dvui_mod.addImport("backend", m); + backend_modules.put(b.allocator, dvui_mod, m) catch @panic("OOM"); + return m; +} + +/// The window and platform pieces (`src/platform`) for an app on `backend_mod`: this package's +/// backend (`backendModule`), which imports them in turn, or dvui's own SDL3 backend. The app +/// reaches them as `platform`. +pub fn platformModule(dep: *std.Build.Dependency, dvui_mod: *std.Build.Module, backend_mod: *std.Build.Module, opts: Options) *std.Build.Module { + if (platform_modules.get(backend_mod)) |m| return m; + const b = dep.builder; + const m = b.createModule(.{ + .root_source_file = b.path("src/platform/root.zig"), + .target = opts.target, + .optimize = opts.optimize, + .link_libc = true, + }); + m.addImport("dvui", dvui_mod); + m.addImport("backend", backend_mod); + switch (opts.target.result.os.tag) { + .macos => { + if (objcModule(dep, opts)) |objc| m.addImport("objc", objc); + addMacosSdk(m, opts); + m.addCSourceFile(.{ .file = b.path("src/platform/macos/visual_effect_view.m") }); + m.addCSourceFile(.{ .file = b.path("src/platform/macos/menu_target.m") }); + m.addCSourceFile(.{ .file = b.path("src/platform/macos/window_monitor.m") }); + m.addCSourceFile(.{ .file = b.path("src/platform/macos/live_resize_trace.m") }); + }, + .windows => if (win32Module(dep)) |win32| m.addImport("win32", win32), + else => {}, + } + // This package's backend imports the platform pieces by name; dvui's SDL3 one does not. + var it = backend_modules.valueIterator(); + while (it.next()) |own| if (own.* == backend_mod) backend_mod.addImport("platform", m); + platform_modules.put(b.allocator, backend_mod, m) catch @panic("OOM"); + return m; +} + +/// zig-objc, from this package's pin, for an app's own AppKit code. Null on the configure pass +/// that fetches it (Zig runs the build again). +pub fn objcModule(dep: *std.Build.Dependency, opts: Options) ?*std.Build.Module { + const objc = dep.builder.lazyDependency("zig_objc", .{ .target = opts.target, .optimize = opts.optimize }) orelse return null; + return objc.module("objc"); +} + +/// zigwin32, from this package's pin, for an app's own Windows code. Null on the configure pass +/// that fetches it. +pub fn win32Module(dep: *std.Build.Dependency) ?*std.Build.Module { + const win32 = dep.builder.lazyDependency("zigwin32", .{}) orelse return null; + return win32.module("win32"); +} + +/// A non-native macOS target's SDK, for a module's Objective-C: zig-objc's paths do not always +/// reach `.m` compiles (Security.framework's ``). +fn addMacosSdk(m: *std.Build.Module, opts: Options) void { + const p = opts.macos_sdk orelse return; + m.addSystemIncludePath(p.include); + m.addSystemFrameworkPath(p.framework); + m.addLibraryPath(p.lib); +} diff --git a/backend/build.zig.zon b/backend/build.zig.zon new file mode 100644 index 000000000..eb06b4f9f --- /dev/null +++ b/backend/build.zig.zon @@ -0,0 +1,29 @@ +.{ + .name = .fizzy_backend, + .version = "0.1.0", + .fingerprint = 0x2bf08855a368b9a8, + .minimum_zig_version = "0.16.0", + .dependencies = .{ + // SDL3 for the window, its events and the GPU: fizzyedit/sdl_zig's `fizzy` branch, + // building fizzyedit/SDL's `fizzy-3.4` with the patches this backend needs (fizzy's + // docs/DEPENDENCIES.md). Pinned here, by the package that uses it, and nowhere else. + .sdl = .{ + .url = "https://github.com/fizzyedit/sdl_zig/archive/a02dda8d4c12bfd6132f24f4d00bcdbc8a274b52.tar.gz", + .hash = "sdl-1.0.3+3.4.16-i4QD0SIUqgAsokLeE08dWLGiUN4cL3ZDOM94hrJ-DTam", + .lazy = true, + }, + // AppKit from Zig, for the macOS platform pieces (and an app's own, `objcModule`). + .zig_objc = .{ + .url = "https://github.com/foxnne/zig-objc/archive/c8de82ff80281215ad92900866dab7103a8efa8b.tar.gz", + .hash = "zig_objc-0.0.0-Ir_Sp9gsAQCPAJc0oF5xoWePHWP6Y6tCphDeyNUThJoi", + .lazy = true, + }, + // Win32 from Zig, for the Windows platform pieces (and an app's own, `win32Module`). + .zigwin32 = .{ + .url = "https://github.com/marlersoft/zigwin32/archive/ec98bb4d9eea532320a8551720a9e3ec6de64994.tar.gz", + .hash = "win32-25.0.28-preview-mX5pFWMt5QPTVIGh3r2-OpPunpcCCjApyRbA6Zn6WALH", + .lazy = true, + }, + }, + .paths = .{ "build.zig", "build.zig.zon", "src" }, +} diff --git a/src/backend/native/GpuRenderer.zig b/backend/src/GpuRenderer.zig similarity index 100% rename from src/backend/native/GpuRenderer.zig rename to backend/src/GpuRenderer.zig diff --git a/src/backend/native/SDLBackend.zig b/backend/src/SDLBackend.zig similarity index 99% rename from src/backend/native/SDLBackend.zig rename to backend/src/SDLBackend.zig index 4e47d86b4..b526f19e0 100644 --- a/src/backend/native/SDLBackend.zig +++ b/backend/src/SDLBackend.zig @@ -18,7 +18,7 @@ const GpuRenderer = @import("GpuRenderer.zig"); pub const viewport_map = @import("viewport_map.zig"); /// What an app gets from its window beyond drawing into it: native dialogs, files the OS hands -/// over, trackpad gestures, the window's chrome and state (`src/backend/native/platform`). +/// over, trackpad gestures, the window's chrome and state (`platform/`). pub const platform = @import("platform"); /// SDL3 only. Kept as a constant so the event code below stays a verbatim copy of dvui's diff --git a/src/backend/native/macos_monitor.m b/backend/src/macos_monitor.m similarity index 100% rename from src/backend/native/macos_monitor.m rename to backend/src/macos_monitor.m diff --git a/src/backend/native/platform/blur_region.zig b/backend/src/platform/blur_region.zig similarity index 100% rename from src/backend/native/platform/blur_region.zig rename to backend/src/platform/blur_region.zig diff --git a/src/backend/native/platform/dialogs.zig b/backend/src/platform/dialogs.zig similarity index 100% rename from src/backend/native/platform/dialogs.zig rename to backend/src/platform/dialogs.zig diff --git a/src/backend/native/platform/geometry.zig b/backend/src/platform/geometry.zig similarity index 100% rename from src/backend/native/platform/geometry.zig rename to backend/src/platform/geometry.zig diff --git a/src/backend/native/platform/gestures.zig b/backend/src/platform/gestures.zig similarity index 100% rename from src/backend/native/platform/gestures.zig rename to backend/src/platform/gestures.zig diff --git a/src/backend/native/platform/linux_titlebar.zig b/backend/src/platform/linux_titlebar.zig similarity index 100% rename from src/backend/native/platform/linux_titlebar.zig rename to backend/src/platform/linux_titlebar.zig diff --git a/src/backend/native/platform/macos/live_resize_trace.m b/backend/src/platform/macos/live_resize_trace.m similarity index 100% rename from src/backend/native/platform/macos/live_resize_trace.m rename to backend/src/platform/macos/live_resize_trace.m diff --git a/src/backend/native/platform/macos/menu_target.m b/backend/src/platform/macos/menu_target.m similarity index 100% rename from src/backend/native/platform/macos/menu_target.m rename to backend/src/platform/macos/menu_target.m diff --git a/src/backend/native/platform/macos/visual_effect_view.m b/backend/src/platform/macos/visual_effect_view.m similarity index 100% rename from src/backend/native/platform/macos/visual_effect_view.m rename to backend/src/platform/macos/visual_effect_view.m diff --git a/src/backend/native/platform/macos/window_monitor.m b/backend/src/platform/macos/window_monitor.m similarity index 100% rename from src/backend/native/platform/macos/window_monitor.m rename to backend/src/platform/macos/window_monitor.m diff --git a/src/backend/native/platform/macos_monitor.zig b/backend/src/platform/macos_monitor.zig similarity index 100% rename from src/backend/native/platform/macos_monitor.zig rename to backend/src/platform/macos_monitor.zig diff --git a/src/backend/native/platform/menu.zig b/backend/src/platform/menu.zig similarity index 100% rename from src/backend/native/platform/menu.zig rename to backend/src/platform/menu.zig diff --git a/src/backend/native/platform/open_events.zig b/backend/src/platform/open_events.zig similarity index 100% rename from src/backend/native/platform/open_events.zig rename to backend/src/platform/open_events.zig diff --git a/src/backend/native/platform/root.zig b/backend/src/platform/root.zig similarity index 90% rename from src/backend/native/platform/root.zig rename to backend/src/platform/root.zig index 14237a051..b456a1709 100644 --- a/src/backend/native/platform/root.zig +++ b/backend/src/platform/root.zig @@ -1,6 +1,6 @@ //! What an app gets from its window beyond drawing into it — native file dialogs, files the OS //! asks it to open, trackpad gestures, the window's chrome and state — for apps on dvui's SDL3 -//! backends, fizzy's own (`src/backend/native`) and dvui's. Each piece takes the SDL window and +//! backends, fizzy's own (this package's `SDLBackend`) and dvui's. Each piece takes the SDL window and //! nothing of any one app: where an app has a say (which folder a dialog opens in, what to do //! with a file the OS hands over) it plugs in through a small hook. //! diff --git a/src/backend/native/platform/titlebar.zig b/backend/src/platform/titlebar.zig similarity index 100% rename from src/backend/native/platform/titlebar.zig rename to backend/src/platform/titlebar.zig diff --git a/src/backend/native/platform/wayland_blur.zig b/backend/src/platform/wayland_blur.zig similarity index 100% rename from src/backend/native/platform/wayland_blur.zig rename to backend/src/platform/wayland_blur.zig diff --git a/src/backend/native/platform/win32_titlebar.zig b/backend/src/platform/win32_titlebar.zig similarity index 100% rename from src/backend/native/platform/win32_titlebar.zig rename to backend/src/platform/win32_titlebar.zig diff --git a/src/backend/native/platform/window.zig b/backend/src/platform/window.zig similarity index 100% rename from src/backend/native/platform/window.zig rename to backend/src/platform/window.zig diff --git a/src/backend/native/platform/window_layout.zig b/backend/src/platform/window_layout.zig similarity index 100% rename from src/backend/native/platform/window_layout.zig rename to backend/src/platform/window_layout.zig diff --git a/src/backend/native/sdl3-c.h b/backend/src/sdl3-c.h similarity index 100% rename from src/backend/native/sdl3-c.h rename to backend/src/sdl3-c.h diff --git a/src/backend/native/shaders/compiled/dxil/default.fragment.dxil b/backend/src/shaders/compiled/dxil/default.fragment.dxil similarity index 100% rename from src/backend/native/shaders/compiled/dxil/default.fragment.dxil rename to backend/src/shaders/compiled/dxil/default.fragment.dxil diff --git a/src/backend/native/shaders/compiled/dxil/default.vertex.dxil b/backend/src/shaders/compiled/dxil/default.vertex.dxil similarity index 100% rename from src/backend/native/shaders/compiled/dxil/default.vertex.dxil rename to backend/src/shaders/compiled/dxil/default.vertex.dxil diff --git a/src/backend/native/shaders/compiled/msl/default.fragment.msl b/backend/src/shaders/compiled/msl/default.fragment.msl similarity index 100% rename from src/backend/native/shaders/compiled/msl/default.fragment.msl rename to backend/src/shaders/compiled/msl/default.fragment.msl diff --git a/src/backend/native/shaders/compiled/msl/default.vertex.msl b/backend/src/shaders/compiled/msl/default.vertex.msl similarity index 100% rename from src/backend/native/shaders/compiled/msl/default.vertex.msl rename to backend/src/shaders/compiled/msl/default.vertex.msl diff --git a/src/backend/native/shaders/compiled/msl/program_example.fragment.msl b/backend/src/shaders/compiled/msl/program_example.fragment.msl similarity index 100% rename from src/backend/native/shaders/compiled/msl/program_example.fragment.msl rename to backend/src/shaders/compiled/msl/program_example.fragment.msl diff --git a/src/backend/native/shaders/compiled/spv/default.fragment.spv b/backend/src/shaders/compiled/spv/default.fragment.spv similarity index 100% rename from src/backend/native/shaders/compiled/spv/default.fragment.spv rename to backend/src/shaders/compiled/spv/default.fragment.spv diff --git a/src/backend/native/shaders/compiled/spv/default.vertex.spv b/backend/src/shaders/compiled/spv/default.vertex.spv similarity index 100% rename from src/backend/native/shaders/compiled/spv/default.vertex.spv rename to backend/src/shaders/compiled/spv/default.vertex.spv diff --git a/src/backend/native/shaders/default.fragment.hlsl b/backend/src/shaders/default.fragment.hlsl similarity index 100% rename from src/backend/native/shaders/default.fragment.hlsl rename to backend/src/shaders/default.fragment.hlsl diff --git a/src/backend/native/shaders/default.vertex.hlsl b/backend/src/shaders/default.vertex.hlsl similarity index 100% rename from src/backend/native/shaders/default.vertex.hlsl rename to backend/src/shaders/default.vertex.hlsl diff --git a/src/backend/native/shaders/program_example.fragment.hlsl b/backend/src/shaders/program_example.fragment.hlsl similarity index 100% rename from src/backend/native/shaders/program_example.fragment.hlsl rename to backend/src/shaders/program_example.fragment.hlsl diff --git a/src/backend/native/shaders/shared.hlsl b/backend/src/shaders/shared.hlsl similarity index 100% rename from src/backend/native/shaders/shared.hlsl rename to backend/src/shaders/shared.hlsl diff --git a/src/backend/native/viewport_map.zig b/backend/src/viewport_map.zig similarity index 100% rename from src/backend/native/viewport_map.zig rename to backend/src/viewport_map.zig diff --git a/build.zig.zon b/build.zig.zon index 95bbb3d3f..0e409ad5a 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -10,6 +10,7 @@ "build.zig.zon", "update.zig", "sdk", + "backend", "assets", "libs", "web", @@ -19,24 +20,6 @@ .version = "0.2.0", .minimum_zig_version = "0.16.0", .dependencies = .{ - .zig_objc = .{ - .url = "https://github.com/foxnne/zig-objc/archive/c8de82ff80281215ad92900866dab7103a8efa8b.tar.gz", - .hash = "zig_objc-0.0.0-Ir_Sp9gsAQCPAJc0oF5xoWePHWP6Y6tCphDeyNUThJoi", - .lazy = true, - }, - .zigwin32 = .{ - .url = "https://github.com/marlersoft/zigwin32/archive/ec98bb4d9eea532320a8551720a9e3ec6de64994.tar.gz", - .hash = "win32-25.0.28-preview-mX5pFWMt5QPTVIGh3r2-OpPunpcCCjApyRbA6Zn6WALH", - .lazy = true, - }, - // App-only: SDL for fizzy's own native backend (`src/backend/native`). fizzyedit/sdl_zig's - // `fizzy` branch, building fizzyedit/SDL's `fizzy-3.4` — see docs/DEPENDENCIES.md. Plugins - // draw through dvui's proxy backend and never link SDL. - .sdl = .{ - .url = "https://github.com/fizzyedit/sdl_zig/archive/a02dda8d4c12bfd6132f24f4d00bcdbc8a274b52.tar.gz", - .hash = "sdl-1.0.3+3.4.16-i4QD0SIUqgAsokLeE08dWLGiUN4cL3ZDOM94hrJ-DTam", - .lazy = true, - }, .icons = .{ .url = "https://github.com/fizzyedit/icons/archive/41e7d2162b121e3798438a7da25ff4648b204dc7.tar.gz", .hash = "icons-0.1.0-iJxA-Z0TNABnFm_tPfx46ZnvojHweT6xON9ay91XZ4Xo", @@ -45,6 +28,11 @@ .fizzy_sdk = .{ .path = "sdk/", }, + // Fizzy's native backend (SDL3, its GPU renderer, the platform pieces), with SDL, + // zig-objc and zigwin32 pinned there. App-only: plugins never link it. + .fizzy_backend = .{ + .path = "backend", + }, .assetpack = .{ .url = "https://github.com/foxnne/assetpack/archive/ac7592f3f5988857840d0df4610e1e1fad690e2e.tar.gz", .hash = "assetpack-0.2.0-5DA2d1ZkAADJanNVdWrUBOGMhOzUENhrUiqXcHADxY2x", diff --git a/build/app.zig b/build/app.zig index 1bbef0a45..4f671d1ce 100644 --- a/build/app.zig +++ b/build/app.zig @@ -554,14 +554,6 @@ pub fn construct(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std. .{ "fizzy-direction-tests", "core/math/direction.zig" }, .{ "fizzy-easing-tests", "core/math/easing.zig" }, .{ "fizzy-layout-anchor-tests", "core/math/layout_anchor.zig" }, - .{ "fizzy-window-layout-tests", "src/backend/native/platform/window_layout.zig" }, - // The hit test Windows' WM_NCHITTEST and Linux's SDL hit test both answer from. - .{ "fizzy-titlebar-tests", "src/backend/native/platform/titlebar.zig" }, - // The rounded frame Linux's blur behind the window is stepped into (`wayland_blur`). - .{ "fizzy-blur-region-tests", "src/backend/native/platform/blur_region.zig" }, - // Where a viewport's OS window is on the desktop and where its part of the frame lies. - // std-only (see viewport_map.zig); `SDLBackend` applies it. - .{ "fizzy-viewport-map-tests", "src/backend/native/viewport_map.zig" }, .{ "fizzy-plugin-store-tests", "app/store/registry/store.zig" }, .{ "fizzy-paths-tests", "core/paths.zig" }, // The credential store behind `Host.secrets`: a 0600 file, keyed, round-tripped. @@ -645,6 +637,20 @@ pub fn construct(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std. .filters = test_filters, })); } + // The backend package's std-only tests (window layout, the title-bar hit test, the blur + // region, the viewport map), from its own list, so `zig build test` here still runs them. + const backend_dep = fizzy_exe.backendDependency(b); + for (@import("fizzy_backend").unit_tests) |t| { + try unit_test_artifacts.append(b.allocator, b.addTest(.{ + .name = t.name, + .root_module = b.createModule(.{ + .target = target, + .optimize = optimize, + .root_source_file = backend_dep.path(t.root), + }), + .filters = test_filters, + })); + } // Keybinding parse/resolve core. Deliberately dvui-free (see Keymap.zig) — dvui's keybind map // can't express chords and is keyed by bind name, not command. Its key spelling is `tape`'s @@ -870,12 +876,12 @@ pub fn construct(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std. })); if (target.result.os.tag == .macos) { - if (b.lazyDependency("zig_objc", .{ .target = target, .optimize = optimize })) |dep| { - fizzy_test_module.addImport("objc", dep.module("objc")); + if (@import("fizzy_backend").objcModule(fizzy_exe.backendDependency(b), fizzy_exe.backendOptions(target, optimize, macos_sdl_paths))) |objc| { + fizzy_test_module.addImport("objc", objc); } } else if (target.result.os.tag == .windows) { - if (b.lazyDependency("zigwin32", .{})) |dep| { - fizzy_test_module.addImport("win32", dep.module("win32")); + if (@import("fizzy_backend").win32Module(fizzy_exe.backendDependency(b))) |win32| { + fizzy_test_module.addImport("win32", win32); } } diff --git a/build/exe.zig b/build/exe.zig index caa905cca..3d631e5d5 100644 --- a/build/exe.zig +++ b/build/exe.zig @@ -8,6 +8,8 @@ const core_mod = @import("fizzy_sdk").core_module; const common = @import("common.zig"); const plugins = @import("plugins.zig"); const sdk = @import("sdk.zig"); +// Fizzy's native backend, a package of its own (`backend/`): its build helpers wire it under dvui. +const fizzy_backend = @import("fizzy_backend"); const workbench_plugin = plugins.workbench; const text_plugin = plugins.text; @@ -70,7 +72,7 @@ pub const FizzyExecutable = struct { /// What the native executable draws with. pub const NativeBackend = enum { - /// Fizzy's own backend (`src/backend/native/`): SDL3 for the window and events, an + /// Fizzy's own backend (the `backend/` package): SDL3 for the window and events, an /// SDL_GPU renderer of its own, custom fragment programs. fizzy, /// dvui's SDL3 backend: SDL_Renderer, fixed shaders. @@ -93,11 +95,6 @@ const NativeDvui = struct { backend: *std.Build.Module, }; -/// The `backend` module wired into each dvui built for fizzy's own backend. One per dvui -/// module, however many executables use it: dvui imports it by name, and a second module over -/// the same file in one compilation is an error. -var fizzy_backend_modules: std.AutoHashMapUnmanaged(*std.Build.Module, *std.Build.Module) = .empty; - /// dvui in its `custom` mode with fizzy's backend linked under it — as `build/web.zig` does for /// the web. Every option is the one dvui's own `sdl3` mode sets, so dvui's shape, and with it /// the plugin ABI fingerprint, is the same either way. @@ -120,87 +117,33 @@ fn fizzyNativeDvui( .@"tree-sitter" = true, }); const dvui_mod = dep.module("dvui"); - if (fizzy_backend_modules.get(dvui_mod)) |backend| return .{ .dep = dep, .dvui = dvui_mod, .backend = backend }; - - // SDL3 from fizzy's own pin, not dvui's: the backend is fizzy's, and so are the SDL patches it - // needs (docs/DEPENDENCIES.md). The wrapper already builds without GameInput. - // - // Optimized in a Debug app too: Zig builds C in Debug unoptimized and with its undefined- - // behaviour checks on every call, and SDL is on every frame's path — event pumping, the GPU - // device, every window's present. A Debug frame spent much of itself there (`sample`), and a - // window's way into full screen ran at half the display's rate in Debug alone (the user). - // Fizzy's own code stays Debug; stepping into SDL's C is what a Debug app gives up. - const sdl_optimize: std.builtin.OptimizeMode = if (optimize == .Debug) .ReleaseFast else optimize; - const sdl_dep = if (macos_sdl_paths) |p| - b.lazyDependency("sdl", .{ - .target = target, - .optimize = sdl_optimize, - .include_path = p.include, - .framework_path = p.framework, - .library_path = p.lib, - }) - else - b.lazyDependency("sdl", .{ .target = target, .optimize = sdl_optimize }); + const backend = fizzy_backend.backendModule(backendDependency(b), dvui_mod, backendOptions(target, optimize, macos_sdl_paths)); + return .{ .dep = dep, .dvui = dvui_mod, .backend = backend }; +} - const sdl_translate_c = b.addTranslateC(.{ - .root_source_file = b.path("src/backend/native/sdl3-c.h"), - .target = target, - .optimize = optimize, - }); - if (sdl_dep) |sdl| sdl_translate_c.addIncludePath(sdl.artifact("SDL3").getEmittedIncludeTree()); +/// The backend package (`backend/`), as a dependency of this build. +pub fn backendDependency(b: *std.Build) *std.Build.Dependency { + return b.dependency("fizzy_backend", .{}); +} - const backend = b.createModule(.{ - .root_source_file = b.path("src/backend/native/SDLBackend.zig"), +pub fn backendOptions(target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, macos_sdl_paths: ?MacosSdlPaths) fizzy_backend.Options { + return .{ .target = target, .optimize = optimize, - .sanitize_c = .full, - .link_libc = true, - .imports = &.{ - .{ .name = "sdl3-c", .module = sdl_translate_c.createModule() }, - .{ .name = "dvui", .module = dvui_mod }, - }, - }); - if (sdl_dep) |sdl| backend.linkLibrary(sdl.artifact("SDL3")); - dvui_mod.addImport("backend", backend); - fizzy_backend_modules.put(b.allocator, dvui_mod, backend) catch @panic("OOM"); - return .{ .dep = dep, .dvui = dvui_mod, .backend = backend }; + .macos_sdk = if (macos_sdl_paths) |p| .{ .include = p.include, .framework = p.framework, .lib = p.lib } else null, + }; } -/// The `platform` module (`src/backend/native/platform`) for each backend module: one per -/// backend, as the backend itself is, since fizzy's backend imports it by name too. -var platform_modules: std.AutoHashMapUnmanaged(*std.Build.Module, *std.Build.Module) = .empty; - -/// Window and platform pieces for apps on either SDL3 backend: dvui and the backend's SDL, plus -/// zig-objc on macOS and zigwin32 on Windows. Fizzy's own backend imports it as well, so an app on -/// that backend reaches it as `backend.platform`. +/// Window and platform pieces for apps on either SDL3 backend (the backend package's +/// `platform`). Fizzy's own backend imports it as well. fn platformModule( b: *std.Build, native: NativeDvui, - native_backend: NativeBackend, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, + macos_sdl_paths: ?MacosSdlPaths, ) *std.Build.Module { - if (platform_modules.get(native.backend)) |m| return m; - const m = b.createModule(.{ - .root_source_file = b.path("src/backend/native/platform/root.zig"), - .target = target, - .optimize = optimize, - .link_libc = true, - }); - m.addImport("dvui", native.dvui); - m.addImport("backend", native.backend); - switch (target.result.os.tag) { - .macos => if (b.lazyDependency("zig_objc", .{ .target = target, .optimize = optimize })) |dep| { - m.addImport("objc", dep.module("objc")); - }, - .windows => if (b.lazyDependency("zigwin32", .{})) |dep| { - m.addImport("win32", dep.module("win32")); - }, - else => {}, - } - if (native_backend == .fizzy) native.backend.addImport("platform", m); - platform_modules.put(b.allocator, native.backend, m) catch @panic("OOM"); - return m; + return fizzy_backend.platformModule(backendDependency(b), native.dvui, native.backend, backendOptions(target, optimize, macos_sdl_paths)); } pub fn addFizzyExecutableForTarget( @@ -293,7 +236,7 @@ pub fn addFizzyExecutableForTarget( exe.root_module.addImport("dvui", dvui_mod); exe.root_module.addImport("backend", native.backend); - exe.root_module.addImport("platform", platformModule(b, native, native_backend, resolved_target, optimize)); + exe.root_module.addImport("platform", platformModule(b, native, resolved_target, optimize, macos_sdl_paths)); // Shared `core` module (gfx/math/fs/generated atlas/platform/paths/dvui hub + // generic widgets). Import set is shared with the plugin SDK path — see sdk/core_module.zig. @@ -481,27 +424,15 @@ pub fn addFizzyExecutableForTarget( exe.root_module.addSystemFrameworkPath(p.framework); exe.root_module.addLibraryPath(p.lib); } - if (b.lazyDependency("zig_objc", .{ - .target = resolved_target, - .optimize = optimize, - })) |dep| { - exe.root_module.addImport("objc", dep.module("objc")); - } - exe.root_module.addCSourceFile(.{ .file = std.Build.path(b, "src/backend/native/platform/macos/visual_effect_view.m") }); - exe.root_module.addCSourceFile(.{ .file = std.Build.path(b, "src/backend/native/platform/macos/menu_target.m") }); - exe.root_module.addCSourceFile(.{ .file = std.Build.path(b, "src/backend/native/platform/macos/window_monitor.m") }); - exe.root_module.addCSourceFile(.{ .file = std.Build.path(b, "src/backend/native/platform/macos/live_resize_trace.m") }); - // The native backend's AppKit helpers, compiled here with fizzy's other Objective-C - // (the root module is where the SDK's headers are found on a native build); the - // backend module calls them by name. - if (native_backend == .fizzy) { - exe.root_module.addCSourceFile(.{ .file = std.Build.path(b, "src/backend/native/macos_monitor.m") }); + // zig-objc from the backend package's pin. The backend's Objective-C comes with its modules. + if (fizzy_backend.objcModule(backendDependency(b), backendOptions(resolved_target, optimize, macos_sdl_paths))) |objc| { + exe.root_module.addImport("objc", objc); } } else if (resolved_target.result.os.tag == .windows) { - if (b.lazyDependency("zigwin32", .{})) |dep| { - exe.root_module.addImport("win32", dep.module("win32")); + if (fizzy_backend.win32Module(backendDependency(b))) |win32| { + exe.root_module.addImport("win32", win32); // The updater (`app/update`) calls into Windows too, from the `app` module. - app_module.addImport("win32", dep.module("win32")); + app_module.addImport("win32", win32); } exe.root_module.linkSystemLibrary("comctl32", .{}); diff --git a/core/gfx/programs.zig b/core/gfx/programs.zig index 2d0e0d0e7..b7c2f2c11 100644 --- a/core/gfx/programs.zig +++ b/core/gfx/programs.zig @@ -191,7 +191,7 @@ pub const Program = struct { /// each backend takes the form it can and draws nothing where it has none. Native programs /// take the default vertex shader's colour and uv, the draw's own texture at 0 and the extra /// ones at 1 and 2, and the uniforms as `constant float4 *data [[buffer(0)]]` (see - /// `src/backend/native/shaders/program_example.fragment.hlsl`). + /// `backend/src/shaders/program_example.fragment.hlsl`). pub fn from(comptime sources: Sources, shape: Shape) Program { var src: Source = .{ .textures = shape.textures, .uniform_vec4s = shape.uniform_vec4s }; if (sources.glsl) |t| { diff --git a/core/gfx/shaders/liquid_glass.metal b/core/gfx/shaders/liquid_glass.metal index 171877dda..575ef2a4f 100644 --- a/core/gfx/shaders/liquid_glass.metal +++ b/core/gfx/shaders/liquid_glass.metal @@ -1,4 +1,4 @@ -// `liquid_glass.glsl` in Metal, for fizzy's native backend (`src/backend/native`): the same +// `liquid_glass.glsl` in Metal, for fizzy's native backend (`backend/`): the same // program line for line — change it, `liquid_glass.fragment.hlsl` and `LiquidField.sample` // together. To the interface the native backend's programs take: entry point `main0`, the // default vertex shader's outputs as inputs, the draw's own texture (the frost) at 0, the sharp diff --git a/docs/DEPENDENCIES.md b/docs/DEPENDENCIES.md index 09a6152aa..990d1755d 100644 --- a/docs/DEPENDENCIES.md +++ b/docs/DEPENDENCIES.md @@ -8,10 +8,10 @@ what each fork changes and how to bump it; keep it current whenever a pin or a p |---|---|---|---|---| | [`foxnne/dvui-dev`](https://github.com/foxnne/dvui-dev) | [`david-vanderson/dvui`](https://github.com/david-vanderson/dvui) | `fizzy-dev` | `sdk/build.zig.zon` | dvui changes fizzy needs | | [`fizzyedit/SDL`](https://github.com/fizzyedit/SDL) | [`libsdl-org/SDL`](https://github.com/libsdl-org/SDL) | `fizzy-3.4` | `fizzyedit/sdl_zig`'s `build.zig.zon` | SDL C patches (below) | -| [`fizzyedit/sdl_zig`](https://github.com/fizzyedit/sdl_zig) | [`Games-By-Mason/sdl_zig`](https://github.com/Games-By-Mason/sdl_zig) | `fizzy` | root `build.zig.zon` (`.sdl`) | the Zig build of SDL, pointed at `fizzyedit/SDL` | +| [`fizzyedit/sdl_zig`](https://github.com/fizzyedit/sdl_zig) | [`Games-By-Mason/sdl_zig`](https://github.com/Games-By-Mason/sdl_zig) | `fizzy` | `backend/build.zig.zon` (`.sdl`) | the Zig build of SDL, pointed at `fizzyedit/SDL` | -SDL is fizzy's own dependency, not dvui's: fizzy's native backend (`src/backend/native`) takes it -from the root `build.zig.zon` and translates its own `sdl3-c.h`. dvui's SDL pin is used only by the +SDL is fizzy's own dependency, not dvui's: fizzy's native backend (the `backend/` package) pins it +in `backend/build.zig.zon` and translates its own `sdl3-c.h`. dvui's SDL pin is used only by the `-Dnative-backend=sdl3` build (dvui's SDL_Renderer backend). Plugins draw through dvui's proxy backend and never link SDL, so an SDL bump is never an SDK release and never moves `recorded_sdk_shape_fingerprint`. @@ -27,7 +27,8 @@ backend and never link SDL, so an SDL bump is never an SDK release and never mov never moved or deleted; branches rebase freely. (The dvui rule in `docs/PLUGINS.md`, "Repinning dvui", for every fork.) 3. **One pin per dependency, held by whoever uses it.** dvui in `sdk/build.zig.zon`, SDL (through - sdl_zig) in the root `build.zig.zon`. A fork pins at most its own source, as sdl_zig pins + sdl_zig) in `backend/build.zig.zon`, with zig-objc and zigwin32, which fizzy's own code reaches + through the backend package (`objcModule`, `win32Module`). A fork pins at most its own source, as sdl_zig pins `fizzyedit/SDL`. 4. **Upstream first.** A patch that upstream would take goes up as a PR; once merged it comes out empty at the next rebase and is abandoned. @@ -82,7 +83,7 @@ released yet, and a tag never moves, so the second pin of one version takes a su fork's tags do). Fizzy builds dvui in its `custom` backend mode on every target and links its own backends -(`src/backend/native/`, `src/backend/WebBackend.zig` + `web/web.js`), so dvui's `sdl3` and `web` +(`backend/`, `src/backend/WebBackend.zig` + `web/web.js`), so dvui's `sdl3` and `web` backends are only built by `-Dnative-backend=sdl3`. A dvui change to those backends is not a change to fizzy: anything fizzy wants from one is merged into its own by hand. @@ -244,7 +245,7 @@ Tags: `fizzy-1.0.3+3.4.16-1` → `60114a1`; `fizzy-1.0.3+3.4.16-2` → `5950760` 2. In `fizzyedit/sdl_zig`: if upstream sdl_zig has moved to the same SDL release (its source lists follow SDL's files, so bump SDL when the wrapper does), rebase `fizzy` onto it. Point `.sdl` at the new SDL commit's archive (`zig fetch ` prints the hash), push, tag. -3. In fizzy: `zig fetch --save=sdl https://github.com/fizzyedit/sdl_zig/archive/.tar.gz`, +3. In fizzy's `backend/`: `zig fetch --save=sdl https://github.com/fizzyedit/sdl_zig/archive/.tar.gz`, then build macOS, Linux and Windows. **A fizzy-only SDL change:** the same, with only step 1's new change instead of a rebase. @@ -269,5 +270,6 @@ needs no build of the rest of SDL: `zig cc -target x86_64-windows-gnu -Iinclude -Iinclude/build_config -Isrc -Isrc/video/khronos -c src/gpu/d3d12/SDL_gpu_d3d12.c -o /tmp/d3d12.o`. CI's Windows cross-build (`ci.yml`) then builds it into fizzy. -For local work on either fork, point the pin at a checkout with `.path = "../sdl_zig"` (and the -wrapper's `.sdl` at `../SDL`), as `sdk/build.zig.zon` does for `../dvui-dev`. +For local work on either fork, point `backend/build.zig.zon`'s pin at a checkout with +`.path = "../../sdl_zig"` (and the wrapper's `.sdl` at `../SDL`), as `sdk/build.zig.zon` does for +`../dvui-dev`. diff --git a/docs/MACOS_LIVE_RESIZE.md b/docs/MACOS_LIVE_RESIZE.md index e39008f6b..fc7ba9ad0 100644 --- a/docs/MACOS_LIVE_RESIZE.md +++ b/docs/MACOS_LIVE_RESIZE.md @@ -234,7 +234,7 @@ steps, the press missed the edge: run it again. To iterate on the SDL patches locally without pushing: clone fizzyedit/SDL and fizzyedit/sdl_zig beside fizzy (`../SDL`, `../sdl_zig`) on `fizzy-3.4` and `fizzy`; in sdl_zig's `build.zig.zon`, -`.sdl = .{ .path = "../SDL" }`; in fizzy's root `build.zig.zon`, `.sdl = .{ .path = "../sdl_zig" }`. +`.sdl = .{ .path = "../SDL" }`; in fizzy's `backend/build.zig.zon`, `.sdl = .{ .path = "../../sdl_zig" }`. A rebuild picks up an SDL edit. ## Checking it on a Mac by hand diff --git a/scripts/live-resize/record.swift b/scripts/live-resize/record.swift index f7bc7a43a..4d34e320f 100644 --- a/scripts/live-resize/record.swift +++ b/scripts/live-resize/record.swift @@ -1,6 +1,6 @@ // Drags an edge of a fizzy window with real mouse events while recording the screen around it at // 120 fps (ScreenCaptureKit), and decodes, in every captured frame, the overlay fizzy draws with -// FIZZY_LIVE_RESIZE_TRACE (`live_resize_trace` in src/backend/native/SDLBackend.zig). One line per +// FIZZY_LIVE_RESIZE_TRACE (`live_resize_trace` in backend/src/SDLBackend.zig). One line per // screen update on stdout: // drawn= x pitch=

shown=x // "drawn" is the size the frame was drawn for (its barcode); "shown" the size the window shows it diff --git a/spikes/windows-composition/build.zig.zon b/spikes/windows-composition/build.zig.zon index 381369ca1..467bbd910 100644 --- a/spikes/windows-composition/build.zig.zon +++ b/spikes/windows-composition/build.zig.zon @@ -9,7 +9,7 @@ "README.md", "src", }, - // The same pins as fizzy's root `build.zig.zon`: fizzyedit/SDL (through sdl_zig), whose D3D12 + // The same pins as fizzy's `backend/build.zig.zon`: fizzyedit/SDL (through sdl_zig), whose D3D12 // presents a transparent window through a topmost DirectComposition target, and zigwin32. .dependencies = .{ .sdl = .{ diff --git a/spikes/windows-composition/src/sdl3-c.h b/spikes/windows-composition/src/sdl3-c.h index 5280d5c1f..48f5fa843 100644 --- a/spikes/windows-composition/src/sdl3-c.h +++ b/spikes/windows-composition/src/sdl3-c.h @@ -1,4 +1,4 @@ -// SDL's C API for the spike, as fizzy's native backend translates it (`src/backend/native/sdl3-c.h`). +// SDL's C API for the spike, as fizzy's native backend translates it (`backend/src/sdl3-c.h`). #define SDL_DISABLE_OLD_NAMES #include "SDL3/SDL.h" #define SDL_MAIN_HANDLED diff --git a/src/backend/backend_native.zig b/src/backend/backend_native.zig index cfbc41fe1..b55ff5f19 100644 --- a/src/backend/backend_native.zig +++ b/src/backend/backend_native.zig @@ -1,4 +1,4 @@ -//! Fizzy's own use of its window: the platform pieces any app gets (`src/backend/native/platform` +//! Fizzy's own use of its window: the platform pieces any app gets (the backend package's `platform` //! — dialogs, files from the OS, gestures, chrome, geometry, the window monitor, the menu bar) with //! fizzy's policy over them — where dialogs start, where geometry is kept (`layout.zon`), how high //! the titlebar strip is, what its menus hold and when their items are enabled. The web build has @@ -16,7 +16,7 @@ const KeybindSettings = @import("../editor/KeybindSettings.zig"); const menu_model = @import("../editor/menu_model.zig"); const AppInfo = @import("app").AppInfo; -/// The window and platform pieces any app on these backends gets (`src/backend/native/platform`): +/// The window and platform pieces any app on these backends gets (the backend package's `platform`): /// dialogs, files from the OS, gestures, the window's chrome and state, Windows' title bar. What /// follows them here is fizzy's own use of them. const platform = @import("platform");