<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>API Reference - DWN Documentation</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<button class="mobile-menu-btn">Menu</button>
<div class="layout">
<aside class="sidebar">
<div class="sidebar-header">
<h1>DWN</h1>
<span class="version">v1.0.0</span>
</div>
<div class="search-box">
<input type="text" class="search-input" placeholder="Search docs...">
</div>
<nav class="sidebar-nav">
<div class="nav-section">
<div class="nav-section-title">Getting Started</div>
<a href="index.html" class="nav-link">Introduction</a>
<a href="installation.html" class="nav-link">Installation</a>
<a href="quickstart.html" class="nav-link">Quick Start</a>
</div>
<div class="nav-section">
<div class="nav-section-title">User Guide</div>
<a href="features.html" class="nav-link">Features</a>
<a href="shortcuts.html" class="nav-link">Keyboard Shortcuts</a>
<a href="configuration.html" class="nav-link">Configuration</a>
<a href="layouts.html" class="nav-link">Layouts</a>
<a href="ai-features.html" class="nav-link">AI Integration</a>
</div>
<div class="nav-section">
<div class="nav-section-title">API Reference</div>
<a href="api-overview.html" class="nav-link">API Overview</a>
<a href="api-reference.html" class="nav-link active">API Reference</a>
<a href="api-examples.html" class="nav-link">API Examples</a>
</div>
<div class="nav-section">
<div class="nav-section-title">Advanced</div>
<a href="architecture.html" class="nav-link">Architecture</a>
<a href="building.html" class="nav-link">Building from Source</a>
</div>
</nav>
</aside>
<main class="main-content">
<div class="content">
<div class="page-header">
<h1>API Reference</h1>
<p class="lead">Complete WebSocket API command reference</p>
</div>
<div class="toc">
<div class="toc-title">On this page</div>
<ul class="toc-list">
<li><a href="#windows">Window Commands</a></li>
<li><a href="#workspaces">Workspace Commands</a></li>
<li><a href="#layout">Layout Commands</a></li>
<li><a href="#keyboard">Keyboard Commands</a></li>
<li><a href="#mouse">Mouse Commands</a></li>
<li><a href="#screenshot">Screenshot Commands</a></li>
<li><a href="#ocr">OCR Commands</a></li>
<li><a href="#events">Event Subscription</a></li>
<li><a href="#system">System Commands</a></li>
</ul>
</div>
<h2 id="windows">Window Commands</h2>
<h3>list_windows</h3>
<p>Get list of all managed windows.</p>
<div class="code-block">
<pre><code>// Request
{"command": "list_windows"}
// Response
{
"status": "ok",
"windows": [
{
"id": 12345678,
"title": "Window Title",
"class": "window-class",
"workspace": 0,
"x": 0,
"y": 32,
"width": 960,
"height": 540,
"focused": true,
"floating": false,
"fullscreen": false,
"maximized": false,
"minimized": false
}
]
}</code></pre>
</div>
<h3>focus_window</h3>
<p>Focus a window by ID.</p>
<div class="code-block">
<pre><code>// Request
{"command": "focus_window", "window": 12345678}
// Response
{"status": "ok"}</code></pre>
</div>
<h3>close_window</h3>
<p>Close a window by ID.</p>
<div class="code-block">
<pre><code>// Request
{"command": "close_window", "window": 12345678}
// Response
{"status": "ok"}</code></pre>
</div>
<h3>move_window</h3>
<p>Move a window to specified position.</p>
<div class="code-block">
<pre><code>// Request
{
"command": "move_window",
"window": 12345678,
"x": 100,
"y": 100
}
// Response
{"status": "ok"}</code></pre>
</div>
<h3>resize_window</h3>
<p>Resize a window to specified dimensions.</p>
<div class="code-block">
<pre><code>// Request
{
"command": "resize_window",
"window": 12345678,
"width": 800,
"height": 600
}
// Response
{"status": "ok"}</code></pre>
</div>
<h3>minimize_window</h3>
<p>Minimize a window.</p>
<div class="code-block">
<pre><code>{"command": "minimize_window", "window": 12345678}</code></pre>
</div>
<h3>maximize_window</h3>
<p>Maximize a window.</p>
<div class="code-block">
<pre><code>{"command": "maximize_window", "window": 12345678}</code></pre>
</div>
<h3>restore_window</h3>
<p>Restore a minimized or maximized window.</p>
<div class="code-block">
<pre><code>{"command": "restore_window", "window": 12345678}</code></pre>
</div>
<h3>set_fullscreen</h3>
<p>Set window fullscreen state.</p>
<div class="code-block">
<pre><code>{"command": "set_fullscreen", "window": 12345678, "fullscreen": true}</code></pre>
</div>
<h3>set_floating</h3>
<p>Set window floating state.</p>
<div class="code-block">
<pre><code>{"command": "set_floating", "window": 12345678, "floating": true}</code></pre>
</div>
<h3>raise_window</h3>
<p>Raise window to top of stack.</p>
<div class="code-block">
<pre><code>{"command": "raise_window", "window": 12345678}</code></pre>
</div>
<h3>lower_window</h3>
<p>Lower window to bottom of stack.</p>
<div class="code-block">
<pre><code>{"command": "lower_window", "window": 12345678}</code></pre>
</div>
<h2 id="workspaces">Workspace Commands</h2>
<h3>list_workspaces</h3>
<p>Get list of all workspaces.</p>
<div class="code-block">
<pre><code>// Request
{"command": "list_workspaces"}
// Response
{
"status": "ok",
"workspaces": [
{
"index": 0,
"name": "1",
"layout": "tiling",
"window_count": 3,
"current": true
}
],
"current": 0
}</code></pre>
</div>
<h3>switch_workspace</h3>
<p>Switch to specified workspace (0-8).</p>
<div class="code-block">
<pre><code>{"command": "switch_workspace", "workspace": 2}</code></pre>
</div>
<h3>move_to_workspace</h3>
<p>Move focused window to specified workspace.</p>
<div class="code-block">
<pre><code>{"command": "move_to_workspace", "workspace": 3}</code></pre>
</div>
<h3>move_window_to_workspace</h3>
<p>Move specific window to workspace.</p>
<div class="code-block">
<pre><code>{
"command": "move_window_to_workspace",
"window": 12345678,
"workspace": 3
}</code></pre>
</div>
<h2 id="layout">Layout Commands</h2>
<h3>get_layout</h3>
<p>Get current workspace layout.</p>
<div class="code-block">
<pre><code>// Request
{"command": "get_layout"}
// Response
{
"status": "ok",
"layout": "tiling",
"master_ratio": 0.55,
"master_count": 1
}</code></pre>
</div>
<h3>set_layout</h3>
<p>Set workspace layout mode.</p>
<div class="code-block">
<pre><code>// Options: "tiling", "floating", "monocle"
{"command": "set_layout", "layout": "floating"}</code></pre>
</div>
<h3>cycle_layout</h3>
<p>Cycle to next layout mode.</p>
<div class="code-block">
<pre><code>{"command": "cycle_layout"}</code></pre>
</div>
<h3>set_master_ratio</h3>
<p>Set master area ratio (0.1 to 0.9).</p>
<div class="code-block">
<pre><code>{"command": "set_master_ratio", "ratio": 0.6}</code></pre>
</div>
<h3>adjust_master_ratio</h3>
<p>Adjust master ratio by delta.</p>
<div class="code-block">
<pre><code>{"command": "adjust_master_ratio", "delta": 0.05}</code></pre>
</div>
<h3>set_master_count</h3>
<p>Set number of master windows (1 to 10).</p>
<div class="code-block">
<pre><code>{"command": "set_master_count", "count": 2}</code></pre>
</div>
<h3>adjust_master_count</h3>
<p>Adjust master count by delta.</p>
<div class="code-block">
<pre><code>{"command": "adjust_master_count", "delta": 1}</code></pre>
</div>
<h2 id="keyboard">Keyboard Commands</h2>
<h3>key_press</h3>
<p>Simulate key press. Supports modifiers.</p>
<div class="code-block">
<pre><code>// Simple key
{"command": "key_press", "key": "a"}
// With modifiers
{"command": "key_press", "key": "c", "modifiers": ["ctrl"]}
// Special keys
{"command": "key_press", "key": "Return"}
{"command": "key_press", "key": "Tab"}
{"command": "key_press", "key": "Escape"}
{"command": "key_press", "key": "F1"}</code></pre>
</div>
<p>Available modifiers: <code>ctrl</code>, <code>shift</code>, <code>alt</code>, <code>super</code></p>
<h3>key_release</h3>
<p>Simulate key release.</p>
<div class="code-block">
<pre><code>{"command": "key_release", "key": "a"}</code></pre>
</div>
<h3>type_text</h3>
<p>Type a string of text.</p>
<div class="code-block">
<pre><code>{"command": "type_text", "text": "Hello, World!"}</code></pre>
</div>
<h3>key_combo</h3>
<p>Press a key combination.</p>
<div class="code-block">
<pre><code>// Ctrl+Alt+T
{
"command": "key_combo",
"keys": ["ctrl", "alt", "t"]
}
// Ctrl+Shift+S
{
"command": "key_combo",
"keys": ["ctrl", "shift", "s"]
}</code></pre>
</div>
<h2 id="mouse">Mouse Commands</h2>
<h3>mouse_move</h3>
<p>Move mouse to absolute position.</p>
<div class="code-block">
<pre><code>{"command": "mouse_move", "x": 500, "y": 300}</code></pre>
</div>
<h3>mouse_move_relative</h3>
<p>Move mouse relative to current position.</p>
<div class="code-block">
<pre><code>{"command": "mouse_move_relative", "dx": 10, "dy": -5}</code></pre>
</div>
<h3>mouse_click</h3>
<p>Click mouse button.</p>
<div class="code-block">
<pre><code>// Left click at current position
{"command": "mouse_click", "button": 1}
// Right click at position
{"command": "mouse_click", "button": 3, "x": 100, "y": 200}
// Double click
{"command": "mouse_click", "button": 1, "count": 2}</code></pre>
</div>
<p>Buttons: 1=left, 2=middle, 3=right, 4=scroll up, 5=scroll down</p>
<h3>mouse_down</h3>
<p>Press mouse button without releasing.</p>
<div class="code-block">
<pre><code>{"command": "mouse_down", "button": 1}</code></pre>
</div>
<h3>mouse_up</h3>
<p>Release mouse button.</p>
<div class="code-block">
<pre><code>{"command": "mouse_up", "button": 1}</code></pre>
</div>
<h3>mouse_drag</h3>
<p>Drag from one position to another.</p>
<div class="code-block">
<pre><code>{
"command": "mouse_drag",
"from_x": 100,
"from_y": 100,
"to_x": 500,
"to_y": 300,
"button": 1
}</code></pre>
</div>
<h3>mouse_scroll</h3>
<p>Scroll mouse wheel.</p>
<div class="code-block">
<pre><code>// Scroll up
{"command": "mouse_scroll", "direction": "up", "amount": 3}
// Scroll down
{"command": "mouse_scroll", "direction": "down", "amount": 3}</code></pre>
</div>
<h2 id="screenshot">Screenshot Commands</h2>
<h3>screenshot</h3>
<p>Capture screenshot. Returns base64-encoded PNG.</p>
<h4>Async Mode (Default)</h4>
<p>By default, screenshot operations run asynchronously to avoid blocking the API. Set <code>"async": false</code> for synchronous behavior.</p>
<div class="code-block">
<pre><code>// Async (default) - returns when capture completes
{"command": "screenshot", "mode": "fullscreen"}
// Synchronous - blocks until complete
{"command": "screenshot", "mode": "fullscreen", "async": false}</code></pre>
</div>
<h4>Fullscreen Mode</h4>
<div class="code-block">
<pre><code>// Request
{"command": "screenshot", "mode": "fullscreen"}
// Response
{
"status": "ok",
"format": "png",
"encoding": "base64",
"width": 1920,
"height": 1080,
"data": "iVBORw0KGgoAAAANSUhEUg..."
}</code></pre>
</div>
<h4>Active Window Mode</h4>
<div class="code-block">
<pre><code>{"command": "screenshot", "mode": "active"}</code></pre>
</div>
<h4>Specific Window Mode</h4>
<div class="code-block">
<pre><code>{"command": "screenshot", "mode": "window", "window": 12345678}</code></pre>
</div>
<h4>Area Mode</h4>
<div class="code-block">
<pre><code>{
"command": "screenshot",
"mode": "area",
"x": 100,
"y": 100,
"width": 400,
"height": 300
}</code></pre>
</div>
<h2 id="ocr">OCR Commands</h2>
<h3>ocr</h3>
<p>Extract text from image using OCR.</p>
<h4>Async Mode (Default)</h4>
<p>OCR operations run asynchronously by default since text extraction can take 1-10 seconds. Set <code>"async": false</code> for synchronous behavior.</p>
<div class="code-block">
<pre><code>// Async (default)
{"command": "ocr", "image": "...", "language": "eng"}
// Synchronous
{"command": "ocr", "image": "...", "language": "eng", "async": false}</code></pre>
</div>
<h4>Request/Response</h4>
<div class="code-block">
<pre><code>// Request
{
"command": "ocr",
"image": "iVBORw0KGgoAAAANSUhEUg...", // base64 PNG
"language": "eng" // optional, default "eng"
}
// Response
{
"status": "ok",
"text": "Extracted text from image...",
"confidence": 0.95
}</code></pre>
</div>
<p>Common language codes: <code>eng</code> (English), <code>deu</code> (German), <code>fra</code> (French), <code>spa</code> (Spanish)</p>
<h2 id="events">Event Subscription</h2>
<p>DWN supports real-time event streaming over WebSocket. Subscribe to events to receive notifications about window actions, workspace changes, input events, and more.</p>
<h3>list_events</h3>
<p>Get list of all available event types.</p>
<div class="code-block">
<pre><code>// Request
{"command": "list_events"}
// Response
{
"status": "ok",
"events": [
"window_created",
"window_destroyed",
"window_focused",
"window_unfocused",
"window_moved",
"window_resized",
"window_minimized",
"window_restored",
"window_maximized",
"window_unmaximized",
"window_fullscreen",
"window_unfullscreen",
"window_floating",
"window_unfloating",
"window_title_changed",
"window_raised",
"window_lowered",
"workspace_switched",
"workspace_window_added",
"workspace_window_removed",
"workspace_layout_changed",
"workspace_master_ratio_changed",
"workspace_master_count_changed",
"workspace_arranged",
"layout_changed",
"key_pressed",
"key_released",
"shortcut_triggered",
"mouse_moved",
"mouse_button_pressed",
"mouse_button_released",
"drag_started",
"drag_ended",
"show_desktop_toggled",
"notification_shown",
"notification_closed"
]
}</code></pre>
</div>
<h3>subscribe</h3>
<p>Subscribe to specific events or all events.</p>
<div class="code-block">
<pre><code>// Subscribe to specific events
{"command": "subscribe", "events": ["window_focused", "window_created"]}
// Subscribe to all events
{"command": "subscribe", "all": true}
// Response
{
"status": "ok",
"subscribed": ["window_focused", "window_created"]
}</code></pre>
</div>
<h3>unsubscribe</h3>
<p>Unsubscribe from specific events or all events.</p>
<div class="code-block">
<pre><code>// Unsubscribe from specific events
{"command": "unsubscribe", "events": ["window_focused"]}
// Unsubscribe from all events
{"command": "unsubscribe", "all": true}
// Response
{"status": "ok"}</code></pre>
</div>
<h3>Event Message Format</h3>
<p>When subscribed, events are pushed to the client as JSON messages:</p>
<div class="code-block">
<pre><code>// Window focus event
{
"type": "event",
"event": "window_focused",
"data": {
"window": 12345678,
"title": "Firefox",
"previous_window": 87654321
}
}
// Window moved event
{
"type": "event",
"event": "window_moved",
"data": {
"window": 12345678,
"old_x": 0,
"old_y": 32,
"new_x": 100,
"new_y": 100
}
}
// Workspace switched event
{
"type": "event",
"event": "workspace_switched",
"data": {
"old_workspace": 0,
"new_workspace": 2
}
}
// Keyboard shortcut triggered
{
"type": "event",
"event": "shortcut_triggered",
"data": {
"name": "Return",
"description": "Open terminal"
}
}
// Notification shown
{
"type": "event",
"event": "notification_shown",
"data": {
"id": 1,
"summary": "New Message",
"body": "You have a new message"
}
}</code></pre>
</div>
<h3>Event Types Reference</h3>
<div class="table-container">
<table>
<thead>
<tr>
<th>Event</th>
<th>Description</th>
<th>Data Fields</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>window_created</code></td>
<td>New window managed</td>
<td>window, title, class, workspace</td>
</tr>
<tr>
<td><code>window_destroyed</code></td>
<td>Window closed</td>
<td>window, title, workspace</td>
</tr>
<tr>
<td><code>window_focused</code></td>
<td>Window received focus</td>
<td>window, title, previous_window</td>
</tr>
<tr>
<td><code>window_unfocused</code></td>
<td>Window lost focus</td>
<td>window, title</td>
</tr>
<tr>
<td><code>window_moved</code></td>
<td>Window position changed</td>
<td>window, old_x, old_y, new_x, new_y</td>
</tr>
<tr>
<td><code>window_resized</code></td>
<td>Window size changed</td>
<td>window, old_width, old_height, new_width, new_height</td>
</tr>
<tr>
<td><code>window_minimized</code></td>
<td>Window minimized</td>
<td>window</td>
</tr>
<tr>
<td><code>window_restored</code></td>
<td>Window restored from minimized</td>
<td>window</td>
</tr>
<tr>
<td><code>window_maximized</code></td>
<td>Window maximized/unmaximized</td>
<td>window, maximized</td>
</tr>
<tr>
<td><code>window_fullscreen</code></td>
<td>Fullscreen toggled</td>
<td>window, fullscreen</td>
</tr>
<tr>
<td><code>window_floating</code></td>
<td>Floating mode toggled</td>
<td>window, floating</td>
</tr>
<tr>
<td><code>window_title_changed</code></td>
<td>Window title updated</td>
<td>window, old_title, new_title</td>
</tr>
<tr>
<td><code>workspace_switched</code></td>
<td>Active workspace changed</td>
<td>old_workspace, new_workspace</td>
</tr>
<tr>
<td><code>workspace_layout_changed</code></td>
<td>Workspace layout changed</td>
<td>workspace, old_layout, new_layout</td>
</tr>
<tr>
<td><code>key_pressed</code></td>
<td>Key pressed</td>
<td>keycode, keysym, modifiers</td>
</tr>
<tr>
<td><code>shortcut_triggered</code></td>
<td>Keyboard shortcut executed</td>
<td>name, description</td>
</tr>
<tr>
<td><code>mouse_button_pressed</code></td>
<td>Mouse button pressed</td>
<td>button, x, y</td>
</tr>
<tr>
<td><code>drag_started</code></td>
<td>Window drag/resize started</td>
<td>window, is_resize</td>
</tr>
<tr>
<td><code>drag_ended</code></td>
<td>Window drag/resize ended</td>
<td>window, is_resize</td>
</tr>
<tr>
<td><code>show_desktop_toggled</code></td>
<td>Show desktop mode toggled</td>
<td>shown</td>
</tr>
<tr>
<td><code>notification_shown</code></td>
<td>Notification displayed</td>
<td>id, summary, body</td>
</tr>
<tr>
<td><code>notification_closed</code></td>
<td>Notification closed</td>
<td>id</td>
</tr>
</tbody>
</table>
</div>
<h2 id="system">System Commands</h2>
<h3>get_monitors</h3>
<p>Get monitor information.</p>
<div class="code-block">
<pre><code>// Response
{
"status": "ok",
"monitors": [
{
"index": 0,
"x": 0,
"y": 0,
"width": 1920,
"height": 1080,
"primary": true
}
]
}</code></pre>
</div>
<h3>spawn</h3>
<p>Spawn a process.</p>
<div class="code-block">
<pre><code>{"command": "spawn", "program": "firefox"}</code></pre>
</div>
<h3>notify</h3>
<p>Show a notification.</p>
<div class="code-block">
<pre><code>{
"command": "notify",
"summary": "Title",
"body": "Notification body text",
"timeout": 5000
}</code></pre>
</div>
<h3>get_focused</h3>
<p>Get currently focused window.</p>
<div class="code-block">
<pre><code>// Response
{
"status": "ok",
"window": {
"id": 12345678,
"title": "...",
...
}
}</code></pre>
</div>
<h3>show_desktop</h3>
<p>Toggle show desktop mode.</p>
<div class="code-block">
<pre><code>{"command": "show_desktop"}</code></pre>
</div>
<h3>quit</h3>
<p>Quit DWN.</p>
<div class="code-block">
<pre><code>{"command": "quit"}</code></pre>
</div>
<h2>Error Responses</h2>
<p>All commands may return errors:</p>
<div class="code-block">
<pre><code>{
"status": "error",
"message": "Window not found"
}
{
"status": "error",
"message": "Invalid parameter: workspace must be 0-8"
}
{
"status": "error",
"message": "Unknown command: invalid_command"
}</code></pre>
</div>
<footer>
<p>DWN Window Manager - retoor &lt;retoor@molodetz.nl&gt;</p>
</footer>
</div>
</main>
</div>
<script src="js/main.js"></script>
</body>
</html>