Application and windows
An application can keep documents, services and asynchronous work alive across several windows. Each window has its own composition tree, focus, navigation, layers and local Environment. Choose the owner before installing a service or launching work.
| Owner | Good fit | Ends when |
|---|---|---|
| ApplicationHook | Shared State models, service registration, activation policy, tray | Application shuts down |
| WindowHook | A window presenter or window-local coordination service | That window retires |
| Composable scope | Local editor draft, navigation selection, transient task | Scope unmounts |
Share a model across windows
Section titled “Share a model across windows”Construct application-owned State during an ApplicationHook or later application-thread work. State is a shared observable cell; passing the model to another window does not clone it.
#include <huxerui/huxerui.h>#include <memory>#include <optional>
using namespace huxerui;
struct DocumentModel { State<int> revision{0};};
[[huxerui::composable]]View DocumentPanel(std::shared_ptr<DocumentModel> document) { auto local = UseState(0); return Column { Text::Format("Document revision: {}", document->revision), Button("Edit document").OnClick([document] { ++document->revision; }), Text::Format("Local clicks: {}", local), Button("Local action").OnClick([local] { ++local; }), }.With(Spacing(12.0F));}
View App() { auto application = UseApplication(); auto document = UseService<DocumentModel>(); auto secondary = UseState(std::optional<WindowHandle>{}); const std::optional<WindowHandle>& current = secondary; const bool open = current && current->IsOpen(); return Column { DocumentPanel(document), Button(open ? "Activate inspector" : "Open inspector") .With(Enabled(application.SupportsMultipleWindows())) .OnClick([application, document, secondary] { const std::optional<WindowHandle>& window = secondary; if (window && window->IsOpen()) { window->Activate(); } else { secondary = application.OpenWindow([document] { return DocumentPanel(document).With(Padding(24.0F)); }, {.title = "Inspector", .initial_size = {420.0F, 300.0F}}); } }), }.With(Padding(24.0F), Spacing(16.0F));}
const Application application{ App, {.application_hooks = {[](ApplicationContext& context) { context.Provide(std::make_shared<DocumentModel>()); }}},};Both panels observe one revision, but each DocumentPanel owns a distinct local counter. Closing the inspector unmounts its tree; reopening creates fresh local State. The shared model remains until application shutdown.
Window handles and configuration
Section titled “Window handles and configuration”UseWindow returns the current window’s handle. IsOpen is observable during composition; hidden or minimized windows remain open. Captured handles never target a replacement window after their original window closes.
OpenWindow is a side effect: invoke it from an event or later application work, outside composition and installation. The factory runs in the new window, with a new root Environment. Apply an explicit theme or resource policy inside it when needed; the opening window’s local providers are not inherited.
Use SupportsMultipleWindows() before offering the synchronous desktop OpenWindow() action on Windows, macOS or Linux. Android and Web applications can offer an in-window inspector.
Request an iOS window
Section titled “Request an iOS window”On iOS and iPadOS, opt into multiple scenes in the generated Info.plist. In an event handler, use CanOpenWindow() to check eligibility and launch OpenWindowAsync(content, options) in an application task. The task returns the new handle after UIKit connects and initializes the scene. Handle a rejected request by preserving the original content. UIKit decides placement and size. These methods are available only in iOS and iPadOS builds.
See the docking workspace source for an iOS scene request and a synchronous desktop counterpart that share a workspace model.
Configure a floating desktop window
Section titled “Configure a floating desktop window”Call WindowSupport() before requesting transparency, always-on-top, non-activating behavior, or pointer pass-through on a desktop host. Use WindowOptions to set the initial behavior. For an open window, SetAlwaysOnTop and SetPointerPassThrough report whether the host accepted a change. A non-activating window can still receive pointer input. Keep a separate reachable control to turn off pointer pass-through.
The Desktop Lyrics source uses these options with a small overlay. See the Window API for fullscreen and other live operations.
Close, hide and quit
Section titled “Close, hide and quit”WindowHandle::Close consults that window’s OnCloseRequest policy. Hide keeps the window alive, including its local State. ApplicationHandle::Quit requests application shutdown.
By default, closing the last framework-owned desktop window quits. Set AppOptions::quit_on_last_window_closed to false only when application-level policy provides a way to open another window or quit, such as a tray menu. An application with no initial window is not automatically terminated by this option.
Handle a composition failure
Section titled “Handle a composition failure”When an exception escapes composition of a root, component, layer, or virtual item, the built-in platform hosts retire the affected window’s content and display an error page. Other windows and application-owned services stay active. Close and reopen the affected window to start a fresh composition.
AppOptions::show_composition_error_details controls whether the page shows the failed operation and exception message. It defaults to true in debug builds and false when NDEBUG is defined. The host logs diagnostics in either mode. Recoverable domain errors can be handled in the component or item factory before they escape composition.
Direct UiWindow::BuildFrame() calls and UiTest preserve application exceptions. The built-in error page applies to failures during composition.
Put services at the right scope
Section titled “Put services at the right scope”#include <huxerui/huxerui.h>#include <memory>
using namespace huxerui;
struct InspectorSession { State<bool> show_details{false};};
void InstallInspector(WindowContext& context) { context.Provide(std::make_shared<InspectorSession>());}
View InspectorContent() { auto session = UseService<InspectorSession>(); return Checkbox("Show details", session->show_details) .OnChanged([session](bool next) { session->show_details = next; });}
const Application application{ InspectorContent, {.window_hooks = {InstallInspector}},};Each window receives a different InspectorSession. A type cannot be installed at both scopes. Do not store a borrowed WindowContext or LayerController beyond the owning window’s lifetime.
Application work without a window
Section titled “Application work without a window”UseApplicationTaskScope returns a task owner that survives UI retirement. ApplicationContext::OnActivation can update a shared route/document model or launch work through this scope without depending on a mounted component.
State reads and writes remain on the application thread. RunWorker receives ordinary input snapshots and returns a result to that thread. Retaining State, a task scope or an application handle does not revive a stopped application.
Continue with Lifecycle and activation, Tasks, and Window API. The desktop example source demonstrates real native windows.

