Overview

The Window API provides HWND-like window management capabilities for FreeWorld OS. It offers a complete naming convention for window classes, functions, and variables, similar to how Windows and Linux handle window management.

Architecture Update: The Window API will be updated to use the Window Manager Client (wm-client.js) to communicate with the fwcompositor service via IPC. This provides native windows with kernel integration. See Windowing Architecture and Window Manager Client for details.

Window Class

The Window class represents a single window instance.

Constructor

constructor(title, width, height)

Parameters:

  • title: Window title string
  • width: Window width in pixels
  • height: Window height in pixels

Properties

Property Type Description
id string Unique window identifier (random string)
title string Window title
width number Window width
height number Window height
x number Window X position
y number Window Y position
visible boolean Window visibility state
hwnd string Window handle (format: "FW_HWND_<id>")

Methods

show()

Makes the window visible.

hide()

Hides the window.

move(x, y)

Moves the window to specified coordinates.

resize(width, height)

Resizes the window.

WindowManager Class

The WindowManager class manages all windows in the system.

Constructor

constructor()

Properties

Property Type Description
windows Map<string, Window> Map of window handles to Window objects

Methods

createWindow(title, width, height)

Creates a new window and returns it.

getWindow(hwnd)

Retrieves a window by its handle.

destroyWindow(hwnd)

Destroys a window.

listWindows()

Returns an array of all windows.

HWND Format

Window handles follow the format:

FW_HWND_<random_id>

Example: FW_HWND_a3k9j2x1m

Usage Example

Current Implementation (Structural)

const { Window, WindowManager } = require('./window');

const wm = new WindowManager();
const window = wm.createWindow('My App', 800, 600);
window.show();
window.move(100, 100);
window.resize(1024, 768);

Future Implementation (with IPC)

Once the fwcompositor service is implemented, the Window API will use the Window Manager Client:

const WindowManagerClient = require('./wm-client');

const wm = new WindowManagerClient();
await wm.connect(); // Connect to fwcompositor service

const hwnd = await wm.createWindow('My App', 800, 600);
await wm.showWindow(hwnd);
await wm.moveWindow(hwnd, 100, 100);
await wm.resizeWindow(hwnd, 1024, 768);

Integration with Windowing System

The Window API is part of the native windowing architecture:

  • Current: Structural implementation with in-memory window registry
  • Future: Will use Window Manager Client to communicate with fwcompositor service
  • Benefits: Native windows, kernel integration, centralized management

See Windowing Architecture for the complete system design.