Skip to content

ext_window

The ext_window crate provides comprehensive window management for Forge applications through the host:window module. It offers full control over windows, dialogs, menus, and system tray.

Overview

ext_window handles:

  • Window lifecycle - Create, close, minimize, maximize, restore
  • Window properties - Position, size, title, visibility, decorations
  • Window state - Fullscreen, focus, always-on-top
  • Dialogs - File open/save, message dialogs
  • Menus - Application menu, context menus
  • System tray - Tray icons with menus
  • Native handles - Platform-specific window handles
  • Window events - Close, resize, move, focus

Module: host:window

import {
createWindow,
closeWindow,
dialog,
menu,
tray
} from "host:window";

Key Types

Error Types

enum WindowErrorCode {
Generic = 6000,
PermissionDenied = 6001,
WindowNotFound = 6002,
TrayNotFound = 6003,
DialogCancelled = 6004,
MenuError = 6005,
InvalidOperation = 6006,
}
struct WindowError {
code: WindowErrorCode,
message: String,
}

Window Types

struct WindowOpts {
url: Option<String>,
width: Option<u32>,
height: Option<u32>,
title: Option<String>,
resizable: Option<bool>,
decorations: Option<bool>,
visible: Option<bool>,
transparent: Option<bool>,
always_on_top: Option<bool>,
x: Option<i32>,
y: Option<i32>,
min_width: Option<u32>,
min_height: Option<u32>,
max_width: Option<u32>,
max_height: Option<u32>,
channels: Option<Vec<String>>,
}
struct Position {
x: i32,
y: i32,
}
struct Size {
width: u32,
height: u32,
}
struct NativeHandle {
platform: String, // "windows", "macos", "linux-x11", "linux-wayland"
handle: u64,
}
struct WindowSystemEvent {
window_id: String,
event_type: String, // "close", "focus", "blur", "resize", "move"
payload: serde_json::Value,
}

Dialog Types

struct FileDialogOpts {
title: Option<String>,
default_path: Option<String>,
filters: Option<Vec<FileFilter>>,
multiple: Option<bool>,
directory: Option<bool>,
}
struct FileFilter {
name: String,
extensions: Vec<String>,
}
struct MessageDialogOpts {
title: Option<String>,
message: String,
kind: Option<String>, // "info", "warning", "error"
buttons: Option<Vec<String>>,
}
struct MenuItem {
id: Option<String>,
label: String,
accelerator: Option<String>,
enabled: Option<bool>,
checked: Option<bool>,
submenu: Option<Vec<MenuItem>>,
item_type: Option<String>, // "normal", "checkbox", "separator"
}
struct MenuEvent {
menu_id: String,
item_id: String,
label: String,
}

Tray Types

struct TrayOpts {
icon: Option<String>,
tooltip: Option<String>,
menu: Option<Vec<MenuItem>>,
}

Operations

Window Lifecycle (10 ops)

OpTypeScriptDescription
op_window_createcreateWindow(opts?)Create window
op_window_closewin.close()Close window
op_window_minimizewin.minimize()Minimize
op_window_maximizewin.maximize()Maximize
op_window_unmaximizewin.unmaximize()Restore from maximize
op_window_restorewin.restore()Restore from minimize
op_window_set_fullscreenwin.setFullscreen(bool)Set fullscreen
op_window_is_fullscreenwin.isFullscreen()Check fullscreen
op_window_focuswin.focus()Focus window
op_window_is_focusedwin.isFocused()Check focused

Window Properties (16 ops)

OpTypeScriptDescription
op_window_get_positionwin.getPosition()Get position
op_window_set_positionwin.setPosition(x, y)Set position
op_window_get_sizewin.getSize()Get size
op_window_set_sizewin.setSize(w, h)Set size
op_window_get_titlewin.getTitle()Get title
op_window_set_titlewin.setTitle(title)Set title
op_window_set_resizablewin.setResizable(bool)Set resizable
op_window_is_resizablewin.isResizable()Check resizable
op_window_set_decorationswin.setDecorations(bool)Set decorations
op_window_has_decorationswin.hasDecorations()Check decorations
op_window_set_always_on_topwin.setAlwaysOnTop(bool)Set always on top
op_window_is_always_on_topwin.isAlwaysOnTop()Check always on top
op_window_set_visiblewin.setVisible(bool)Set visibility
op_window_is_visiblewin.isVisible()Check visible
op_window_is_maximizedwin.isMaximized()Check maximized
op_window_is_minimizedwin.isMinimized()Check minimized

Dialogs (3 ops)

OpTypeScriptDescription
op_window_dialog_opendialog.open(opts?)File open dialog
op_window_dialog_savedialog.save(opts?)File save dialog
op_window_dialog_messagedialog.message(opts)Message dialog
OpTypeScriptDescription
op_window_set_app_menumenu.setAppMenu(items)Set app menu
op_window_show_context_menumenu.showContextMenu(items)Show context menu
op_window_menu_recvmenu.events()Receive menu events

Tray (3 ops)

OpTypeScriptDescription
op_window_create_traytray.create(opts?)Create tray
op_window_update_traytrayHandle.update(opts)Update tray
op_window_destroy_traytray.destroy(id)Destroy tray

Events & Native (2 ops)

OpTypeScriptDescription
op_window_events_recvwindowEvents()Receive window events
op_window_get_native_handlewin.getNativeHandle()Get native handle

File Structure

crates/ext_window/
├── src/
│ └── lib.rs # Extension implementation (37 ops)
├── ts/
│ └── init.ts # TypeScript module shim
├── build.rs # forge-weld build configuration
└── Cargo.toml

Dependencies

DependencyPurpose
deno_coreOp definitions
taoWindow management
wryWebView
rfdFile dialogs
mudaMenu system
tray-iconSystem tray
imageIcon processing
tokioAsync runtime
forge-weldBuild-time code generation