setSize
Category: Window Management
Namespace: web.window.setSize
Description
Sets the window size and/or position. All parameters are optional - only specify what you want to change.
Syntax
const success = await web.window.setSize({
top: 100,
left: 100,
width: 800,
height: 600
});
Parameters
- top (optional) - Y position from screen top in pixels
- left (optional) - X position from screen left in pixels
- width (optional) - Window width in pixels
- height (optional) - Window height in pixels
Returns
Promise<boolean> - Returns a promise that resolves with true if successful, false otherwise
Examples
Set size only
// Change only the size, keep current position
const success = await web.window.setSize({
width: 1024,
height: 768
});
Set position only
// Move window to top-left corner
await web.window.setSize({
top: 0,
left: 0
});
Center window on screen
// Center window on screen
const sysInfo = await web.system.getSysInfo();
const screenWidth = 1920; // Get from system info
const screenHeight = 1080;
const windowWidth = 800;
const windowHeight = 600;
await web.window.setSize({
left: (screenWidth - windowWidth) / 2,
top: (screenHeight - windowHeight) / 2,
width: windowWidth,
height: windowHeight
});
Restore saved position
// Restore window position from saved variables
const top = await web.variables.getVar('windowTop');
const left = await web.variables.getVar('windowLeft');
const width = await web.variables.getVar('windowWidth');
const height = await web.variables.getVar('windowHeight');
if (top && left && width && height) {
await web.window.setSize({
top: parseInt(top),
left: parseInt(left),
width: parseInt(width),
height: parseInt(height)
});
}
Use Cases
- Resize window programmatically
- Move window to specific position
- Center window on screen
- Restore saved window position
- Adapt window size to content
- Position window on specific monitor
Notes
- All parameters are optional - omitted parameters keep current value
- Changes apply immediately
- Values are in pixels
- Position is relative to screen top-left corner
- Window may be constrained by minimum/maximum size limits