Window Management (std.window)
The std.window module provides native capabilities for listing, focusing, minimizing, maximizing, moving, and resizing desktop application windows.
Listing Open Windows
Section titled “Listing Open Windows”Enumerate all active, visible top-level windows on your desktop:
import std.window
let windows = window.list()
for w in windows { println($"[{w.id}] {w.appName}: {w.title} ({w.x}, {w.y}, {w.width}x{w.height})")}Finding & Manipulating Windows
Section titled “Finding & Manipulating Windows”You can manipulate windows either using the module-level functions or directly calling methods on Window struct instances:
Module-Level Operations
Section titled “Module-Level Operations”Pass a window title substring, app name, or window ID:
import std.window
// Bring window to foregroundwindow.focus("Firefox")
// Minimize and maximizewindow.minimize("Discord")window.maximize("Code")
// Restore window to normal sizewindow.restore("Discord")
// Move window to top-left cornerwindow.move("Firefox", 0, 0)
// Resize windowwindow.resize("Firefox", 1920, 1080)
// Close a windowwindow.close("Calculator")Instance Methods on Window
Section titled “Instance Methods on Window”import std.window
let editor = window.find("Code")
if editor != nil { editor.focus() editor.move(100, 100) editor.resize(1280, 800)}API Reference
Section titled “API Reference”Module Functions
Section titled “Module Functions”| Method | Arguments | Returns | Description |
|---|---|---|---|
window.list |
None | [Window] |
Returns an array of all currently open top-level application windows. |
window.find |
query: String |
Window? |
Finds the first window matching title substring, app name, or ID. |
window.focus |
target: Unknown |
Bool |
Brings target window to foreground and sets input focus. |
window.minimize |
target: Unknown |
Bool |
Minimizes target window. |
window.maximize |
target: Unknown |
Bool |
Maximizes target window. |
window.restore |
target: Unknown |
Bool |
Restores target window from minimized or maximized state. |
window.move |
target: Unknown, x: Int, y: Int |
Bool |
Moves target window to $(X, Y)$ screen coordinates. |
window.resize |
target: Unknown, width: Int, height: Int |
Bool |
Resizes target window to specified width and height. |
window.close |
target: Unknown |
Bool |
Sends a close request to target window. |
Window Struct Fields
Section titled “Window Struct Fields”| Field | Type | Description |
|---|---|---|
id |
String |
Unique platform window identifier / handle. |
title |
String |
Text title currently displayed on window header bar. |
appName |
String |
Process name or window class (e.g. "firefox", "code"). |
pid |
Int |
Operating system process ID owning the window. |
x |
Int |
Horizontal pixel coordinate on desktop screen. |
y |
Int |
Vertical pixel coordinate on desktop screen. |
width |
Int |
Window pixel width. |
height |
Int |
Window pixel height. |
Window Methods
Section titled “Window Methods”| Method | Arguments | Returns | Description |
|---|---|---|---|
w.focus |
None | Bool |
Brings this window to foreground. |
w.minimize |
None | Bool |
Minimizes this window. |
w.maximize |
None | Bool |
Maximizes this window. |
w.restore |
None | Bool |
Restores this window. |
w.move |
x: Int, y: Int |
Bool |
Moves this window to coordinates $(X, Y)$. |
w.resize |
width: Int, height: Int |
Bool |
Resizes this window to $(width, height)$. |
w.close |
None | Bool |
Closes this window. |
