diff --git a/backend/src/SDLBackend.zig b/backend/src/SDLBackend.zig index 9d795a2f7..a7989b44f 100644 --- a/backend/src/SDLBackend.zig +++ b/backend/src/SDLBackend.zig @@ -17,9 +17,9 @@ const dvui = @import("dvui"); const GpuRenderer = @import("GpuRenderer.zig"); pub const viewport_map = @import("viewport_map.zig"); const TouchSlots = @import("touch_slots.zig"); +const glass_look = @import("glass_look"); /// The OS windows besides the main one an app draws with (`Viewport`). -pub const glass_look = @import("glass_look"); -const viewports = @import("viewports.zig"); +pub const viewports = @import("viewports.zig"); /// dvui's floating windows as OS windows of their own from the one frame (`floatingWindowOs`). pub const os_windows = @import("os_windows.zig"); /// What this backend keeps count of as it runs (`health`). diff --git a/backend/src/viewports_none.zig b/backend/src/viewports_none.zig index 87a205714..84f73859a 100644 --- a/backend/src/viewports_none.zig +++ b/backend/src/viewports_none.zig @@ -4,9 +4,12 @@ //! null, so an app's floats, menus and dialogs stay in the main window. //! //! An app that builds on either kind of backend imports this beside it and takes the backend's -//! own where it has one: +//! own where its build linked the backend package (fizzy passes that as a build option): //! -//! const viewports = if (@hasDecl(backend, "viewports")) backend.viewports else @import("viewports_none"); +//! const viewports = if (linked_fizzy_backend) backend.viewports else @import("viewports_none"); +//! +//! Not `@hasDecl(backend, "viewports")`: a declaration that loses its `pub` is invisible to it, +//! and the app would quietly keep every float in its main window. const dvui = @import("dvui"); /// A window's Liquid Glass this frame, as the backend package's (`platform.window.WindowGlassLook`): diff --git a/build/exe.zig b/build/exe.zig index 39ddba83d..d64f5d813 100644 --- a/build/exe.zig +++ b/build/exe.zig @@ -265,6 +265,10 @@ pub fn addFizzyExecutableForTarget( exe.root_module.addImport("platform", platformModule(b, native, resolved_target, optimize, macos_sdl_paths)); // On dvui's own SDL3 backend (`-Dnative-backend=sdl3`), which has no viewports. exe.root_module.addImport("viewports_none", fizzy_backend.viewportsNoneModule(backendDependency(b), dvui_mod)); + // Which of the two the executable links (`backend_native.viewports`). + const native_backend_opts = b.addOptions(); + native_backend_opts.addOption(bool, "fizzy", native_backend == .fizzy); + exe.root_module.addImport("native_backend", native_backend_opts.createModule()); // The glass look the backend dresses OS windows with; `core` takes the same module. const glass_look = fizzy_backend.glassLookModule(backendDependency(b)); diff --git a/src/backend/backend_native.zig b/src/backend/backend_native.zig index a80137de4..82f8aa961 100644 --- a/src/backend/backend_native.zig +++ b/src/backend/backend_native.zig @@ -150,7 +150,9 @@ pub fn windowGlass(win: *dvui.Window, look: WindowGlassLook) bool { /// OS windows besides the main one, each showing a part of the one frame — a float popped out /// (`plans/POPOUT_WINDOWS_PLAN.md`): the backend package's, for any dvui app on it. On dvui's own /// SDL3 backend (`-Dnative-backend=sdl3`) there are none, as on the web, and floats stay in. -pub const viewports = if (@hasDecl(@import("backend"), "viewports")) @import("backend").viewports else @import("viewports_none"); +/// Chosen by the backend the build linked, not by looking for the declaration: a `viewports` the +/// backend stops exporting fails the build here instead of quietly keeping every float in. +pub const viewports = if (@import("native_backend").fizzy) @import("backend").viewports else @import("viewports_none"); /// Fizzy keeps the window's geometry in `layout.zon`, beside its regions — one file for where the /// window and everything in it were left, and the file it has always kept the frame in.