Skip to main content

window

@tauri-apps/api / window

Module: window

Provides APIs to create windows, communicate with other windows and manipulate the current window.

This package is also accessible with window.__TAURI__.window when tauri.conf.json > build > withGlobalTauri is set to true.

The APIs must be allowlisted on tauri.conf.json:

{
"tauri": {
"allowlist": {
"window": {
"all": true, // enable all window APIs
"create": true, // enable window creation
"center": true,
"requestUserAttention": true,
"setResizable": true,
"setTitle": true,
"maximize": true,
"unmaximize": true,
"minimize": true,
"unminimize": true,
"show": true,
"hide": true,
"close": true,
"setDecorations": true,
"setAlwaysOnTop": true,
"setSize": true,
"setMinSize": true,
"setMaxSize": true,
"setPosition": true,
"setFullscreen": true,
"setFocus": true,
"setIcon": true,
"setSkipTaskbar": true,
"setCursorGrab": true,
"setCursorVisible": true,
"setCursorIcon": true,
"setCursorPosition": true,
"startDragging": true,
"print": true
}
}
}
}

It is recommended to allowlist only the APIs you use for optimal bundle size and security.

Window events

Events can be listened using appWindow.listen:

import { appWindow } from "@tauri-apps/api/window"
appWindow.listen("tauri://move", ({ event, payload }) => {
const { x, y } = payload; // payload here is a `PhysicalPosition`
});

Window-specific events emitted by the backend:

'tauri://resize'

Emitted when the size of the window has changed. EventPayload:

type ResizePayload = PhysicalSize

'tauri://move'

Emitted when the position of the window has changed. EventPayload:

type MovePayload = PhysicalPosition

'tauri://close-requested'

Emitted when the user requests the window to be closed. If a listener is registered for this event, Tauri won't close the window so you must call appWindow.close() manually.

import { appWindow } from "@tauri-apps/api/window";
import { confirm } from '@tauri-apps/api/dialog';
appWindow.listen("tauri://close-requested", async ({ event, payload }) => {
const confirmed = await confirm('Are you sure?');
if (confirmed) {
await appWindow.close();
}
});

'tauri://focus'

Emitted when the window gains focus.

'tauri://blur'

Emitted when the window loses focus.

'tauri://scale-change'

Emitted when the window's scale factor has changed. The following user actions can cause DPI changes:

  • Changing the display's resolution.
  • Changing the display's scale factor (e.g. in Control Panel on Windows).
  • Moving the window to a display with a different scale factor. Event payload:
interface ScaleFactorChanged {
scaleFactor: number
size: PhysicalSize
}

'tauri://menu'

Emitted when a menu item is clicked. EventPayload:

type MenuClicked = string

Enumerations

Classes

Interfaces

Type Aliases

CursorIcon

Ƭ CursorIcon: "default" | "crosshair" | "hand" | "arrow" | "move" | "text" | "wait" | "help" | "progress" | "notAllowed" | "contextMenu" | "cell" | "verticalText" | "alias" | "copy" | "noDrop" | "grab" | "grabbing" | "allScroll" | "zoomIn" | "zoomOut" | "eResize" | "nResize" | "neResize" | "nwResize" | "sResize" | "seResize" | "swResize" | "wResize" | "ewResize" | "nsResize" | "neswResize" | "nwseResize" | "colResize" | "rowResize"

Defined in

window.ts:247


Theme

Ƭ Theme: "light" | "dark"

Defined in

window.ts:126

Variables

appWindow

appWindow: WebviewWindow

The WebviewWindow for the current window.

Defined in

window.ts:1615

Functions

availableMonitors

availableMonitors(): Promise<Monitor[]>

Returns the list of all the monitors available on the system.

example

import { availableMonitors } from '@tauri-apps/api/window';
const monitors = availableMonitors();

Returns

Promise<Monitor[]>

Defined in

window.ts:1754


currentMonitor

currentMonitor(): Promise<Monitor | null>

Returns the monitor on which the window currently resides. Returns null if current monitor can't be detected.

example

import { currentMonitor } from '@tauri-apps/api/window';
const monitor = currentMonitor();

Returns

Promise<Monitor | null>

Defined in

window.ts:1709


getAll

getAll(): WebviewWindow[]

Gets an instance of WebviewWindow for all available webview windows.

Returns

WebviewWindow[]

The list of WebviewWindow.

Defined in

window.ts:305


getCurrent

getCurrent(): WebviewWindow

Get an instance of WebviewWindow for the current webview window.

Returns

WebviewWindow

The current WebviewWindow.

Defined in

window.ts:293


primaryMonitor

primaryMonitor(): Promise<Monitor | null>

Returns the primary monitor of the system. Returns null if it can't identify any monitor as a primary one.

example

import { primaryMonitor } from '@tauri-apps/api/window';
const monitor = primaryMonitor();

Returns

Promise<Monitor | null>

Defined in

window.ts:1732