Architecture Overview
The Desktop component (app/components/Desktop.tsx) manages two types of windows:
- Static Windows: Pre-defined windows (Terminal, Proyectos, Experiencia, Estudios, Fotos, Calendario)
- Dynamic Windows: Runtime-created document windows when users open files
Type Definitions
WinId Type
Defines all possible static window identifiers:WinState Interface
Represents the state of a static window:id: Unique identifier from WinId typetitle: Display title in the window’s title barisOpen: Whether the window is currently openisMinimized: Whether the window is minimized to the dockzIndex: CSS z-index for layering (higher = on top)defaultPosition: Initial x/y coordinates on desktopwidth/height: Window dimensions in pixels
DynWin Interface
Represents a dynamically created document window:- Uses string
idinstead of WinId enum (generated at runtime) - Contains
contentReactNode instead of referencing a component by ID - No fixed width/height (uses default 480x420)
Z-Index Management System
The Desktop uses a ref-based z-index counter to ensure windows layer correctly:- All windows start with
zIndex: 10 - When a window gains focus,
topZRef.currentincrements - The focused window receives the new z-index value
- This ensures the most recently focused window is always on top
bringToFront(): When user clicks a static windowopenWindow(): When opening/restoring a windowopenDoc(): When creating a dynamic document windowfocusDynWin(): When user clicks a dynamic window
Initial Window Configuration
Window Operations
Static Window Operations
openWindow()
openWindow()
- Dock item clicks
- Folder icon double-clicks
- Terminal
opencommands (indirectly)
closeWindow()
closeWindow()
minimizeWindow()
minimizeWindow()
bringToFront()
bringToFront()
Dynamic Window Operations
openDoc()
openDoc()
- Generates unique ID using timestamp
- Cascades windows (offset based on z-index % 6)
- Used by Finder windows when double-clicking files
closeDynWin()
closeDynWin()
Folder Icons & Desktop Layout
Desktop Structure
Dock Integration
isOpenprop adds visual indicator (dot under icon) when window is open- Clicking dock item calls
openWindow(), which restores minimized windows or opens closed ones - Dynamic windows don’t appear in the dock
Content Resolver Pattern
- Centralizes content rendering logic
- Passes
openDoccallback to Finder-style components - Handles prop passing (e.g.,
nfqEventsto Calendar) - Type-safe with WinId enum
Best Practices
Managing Window State
Always use the provided callbacks:
openWindow()for static windowsopenDoc()for dynamic document windowsbringToFront()when user interacts with a window- Never mutate
zIndexdirectly—always incrementtopZRef.current
Creating New Window Types
- Add the window ID to the
WinIdtype - Add configuration to
INITIAL_WINDOWS - Add a case to
getContent()function - Add to
foldersarray (if desktop icon needed) - Add to
dockItemsarray (if dock icon needed)
Performance Considerations
- Window operations use
useCallbackto prevent unnecessary re-renders - Only open windows are rendered (filtered by
isOpen) topZRefis a ref, not state, to avoid re-renders on z-index changes- Dynamic windows use timestamp-based IDs to ensure uniqueness
See Also
- Window Manager - Window component implementation
- Terminal Commands - Terminal integration
- Components: FolderIcon - Desktop folder icons
- Components: Dock - Dock implementation