Documentation Index
Fetch the complete documentation index at: https://mintlify.com/apursley2012/old-windows/llms.txt
Use this file to discover all available pages before exploring further.
WindowContext is the state backbone of Old Windows. It stores the array of open windows, tracks which window is currently active, and exposes a complete set of management functions through the useWindows() hook. Every component in the tree — Desktop, Window, and Taskbar — reads from and writes to this single context rather than managing their own local state.
Setup
Wrap your application root inWindowProvider. Nothing in the Old Windows component tree will function without it.
WindowProvider initialises two pieces of React state:
| State | Type | Initial value |
|---|---|---|
windows | Array | [] |
activeWindowId | string | null | null |
zIndex counter initialised to 10 (let x = 10). This counter is incremented by openWindow when creating a new window and by focusWindow whenever a window is brought to front, so the newly focused window always renders on top.
useWindows() Hook
Call useWindows() inside any component that is a descendant of WindowProvider to access the full window management API.
Returned values
The live array of window state objects. Each entry is an object with
id, title, component, icon, state, zIndex, width, height, defaultX, and defaultY fields. Mutated by all the actions below.The
id of the window that currently has focus (i.e., has the navy title bar and sits on top). null when no window is focused — for example, after all windows are minimized or closed.Opens a new window or restores/focuses an existing one. See the openWindow options section below for the full signature.
closeWindow(id: string) => void — Removes the window from the windows array. If the closed window was the active window, activeWindowId is updated to the window with the next-highest zIndex, or null if no windows remain.minimizeWindow(id: string) => void — Sets the target window’s state to 'minimized'. If it was the active window, activeWindowId is cleared to null. The window’s Taskbar button remains visible.maximizeWindow(id: string) => void — Sets the target window’s state to 'maximized' and calls focusWindow(id) to bring it to front and mark it active.restoreWindow(id: string) => void — Sets the target window’s state back to 'open' and calls focusWindow(id). Used by the Taskbar when clicking a minimized window button.focusWindow(id: string) => void — Increments the module-level zIndex counter, assigns the new value to the target window, and sets activeWindowId to the window’s id. Called automatically by maximizeWindow and restoreWindow, and by Window itself on mousedown.openWindow Options
openWindow has the following signature:
| Parameter | Type | Description |
|---|---|---|
id | string | Unique identifier. If a window with this id already exists, it is restored or focused instead of duplicated. |
title | string | Text shown in the title bar and Taskbar button. |
component | ReactNode | The content to render inside the window body. |
icon | ReactNode | Emoji or element shown next to the title. |
options object:
Initial window width in pixels.
Initial window height in pixels.
Initial horizontal position from the left edge of the desktop. Cascades automatically if omitted so multiple windows do not stack directly on top of each other.
Initial vertical position from the top edge of the desktop. Cascades automatically alongside
defaultX.Re-opening an existing window
IfopenWindow is called with an id that already exists in the windows array:
- If that window is minimized, its
stateis set back to'open'andfocusWindowis scheduled viasetTimeoutto run after the state update. - If it is already open or maximized,
focusWindowis scheduled viasetTimeoutand thewindowsarray is returned unchanged — no duplicate is created.