Skip to main content

window.WindowManager

@tauri-apps/api / window / WindowManager

Class: WindowManager

window.WindowManager

Manage the current window object.

Hierarchy

Constructors

constructor

new WindowManager(label)

Parameters

NameType
labelstring

Inherited from

WebviewWindowHandle.constructor

Defined in

window.ts:329

Properties

label

label: string

The window label. It is a unique identifier for the window, can be used to reference it later.

Inherited from

WebviewWindowHandle.label

Defined in

window.ts:325


listeners

listeners: Object

Local event listeners.

Index signature

[key: string]: EventCallback<any>[]

Inherited from

WebviewWindowHandle.listeners

Defined in

window.ts:327

Methods

_handleTauriEvent

_handleTauriEvent<T>(event, handler): boolean

Type parameters

Name
T

Parameters

NameType
eventstring
handlerEventCallback<T>

Returns

boolean

Inherited from

WebviewWindowHandle._handleTauriEvent

Defined in

window.ts:391


center

center(): Promise<void>

Centers the window.

example

import { appWindow } from '@tauri-apps/api/window';
await appWindow.center();

Returns

Promise<void>

A promise indicating the success or failure of the operation.

Defined in

window.ts:707


close

close(): Promise<void>

Closes the window.

example

import { appWindow } from '@tauri-apps/api/window';
await appWindow.close();

Returns

Promise<void>

A promise indicating the success or failure of the operation.

Defined in

window.ts:1008


emit

emit(event, payload?): Promise<void>

Emits an event to the backend, tied to the webview window.

Parameters

NameTypeDescription
eventstringEvent name. Must include only alphanumeric characters, -, /, : and _.
payload?unknownEvent payload.

Returns

Promise<void>

Inherited from

WebviewWindowHandle.emit

Defined in

window.ts:380


hide

hide(): Promise<void>

Sets the window visibility to false.

example

import { appWindow } from '@tauri-apps/api/window';
await appWindow.hide();

Returns

Promise<void>

A promise indicating the success or failure of the operation.

Defined in

window.ts:983


innerPosition

innerPosition(): Promise<PhysicalPosition>

The position of the top-left hand corner of the window's client area relative to the top-left hand corner of the desktop.

example

import { appWindow } from '@tauri-apps/api/window';
const position = await appWindow.innerPosition();

Returns

Promise<PhysicalPosition>

The window's inner position.

Defined in

window.ts:446


innerSize

innerSize(): Promise<PhysicalSize>

The physical size of the window's client area. The client area is the content of the window, excluding the title bar and borders.

example

import { appWindow } from '@tauri-apps/api/window';
const size = await appWindow.innerSize();

Returns

Promise<PhysicalSize>

The window's inner size.

Defined in

window.ts:497


isDecorated

isDecorated(): Promise<boolean>

Gets the window's current decorated state.

example

import { appWindow } from '@tauri-apps/api/window';
const decorated = await appWindow.isDecorated();

Returns

Promise<boolean>

Whether the window is decorated or not.

Defined in

window.ts:598


isFullscreen

isFullscreen(): Promise<boolean>

Gets the window's current fullscreen state.

example

import { appWindow } from '@tauri-apps/api/window';
const fullscreen = await appWindow.isFullscreen();

Returns

Promise<boolean>

Whether the window is in fullscreen mode or not.

Defined in

window.ts:548


isMaximized

isMaximized(): Promise<boolean>

Gets the window's current maximized state.

example

import { appWindow } from '@tauri-apps/api/window';
const maximized = await appWindow.isMaximized();

Returns

Promise<boolean>

Whether the window is maximized or not.

Defined in

window.ts:573


isResizable

isResizable(): Promise<boolean>

Gets the window's current resizable state.

example

import { appWindow } from '@tauri-apps/api/window';
const resizable = await appWindow.isResizable();

Returns

Promise<boolean>

Whether the window is resizable or not.

Defined in

window.ts:623


isVisible

isVisible(): Promise<boolean>

Gets the window's current visible state.

example

import { appWindow } from '@tauri-apps/api/window';
const visible = await appWindow.isVisible();

Returns

Promise<boolean>

Whether the window is visible or not.

Defined in

window.ts:648


listen

listen<T>(event, handler): Promise<UnlistenFn>

Listen to an event emitted by the backend that is tied to the webview window.

Type parameters

Name
T

Parameters

NameTypeDescription
eventEventNameEvent name. Must include only alphanumeric characters, -, /, : and _.
handlerEventCallback<T>Event handler.

Returns

Promise<UnlistenFn>

A promise resolving to a function to unlisten to the event.

Inherited from

WebviewWindowHandle.listen

Defined in

window.ts:342


maximize

maximize(): Promise<void>

Maximizes the window.

example

import { appWindow } from '@tauri-apps/api/window';
await appWindow.maximize();

Returns

Promise<void>

A promise indicating the success or failure of the operation.

Defined in

window.ts:833


minimize

minimize(): Promise<void>

Minimizes the window.

example

import { appWindow } from '@tauri-apps/api/window';
await appWindow.minimize();

Returns

Promise<void>

A promise indicating the success or failure of the operation.

Defined in

window.ts:908


once

once<T>(event, handler): Promise<UnlistenFn>

Listen to an one-off event emitted by the backend that is tied to the webview window.

Type parameters

Name
T

Parameters

NameTypeDescription
eventstringEvent name. Must include only alphanumeric characters, -, /, : and _.
handlerEventCallback<T>Event handler.

Returns

Promise<UnlistenFn>

A promise resolving to a function to unlisten to the event.

Inherited from

WebviewWindowHandle.once

Defined in

window.ts:363


outerPosition

outerPosition(): Promise<PhysicalPosition>

The position of the top-left hand corner of the window relative to the top-left hand corner of the desktop.

example

import { appWindow } from '@tauri-apps/api/window';
const position = await appWindow.outerPosition();

Returns

Promise<PhysicalPosition>

The window's outer position.

Defined in

window.ts:471


outerSize

outerSize(): Promise<PhysicalSize>

The physical size of the entire window. These dimensions include the title bar and borders. If you don't want that (and you usually don't), use inner_size instead.

example

import { appWindow } from '@tauri-apps/api/window';
const size = await appWindow.outerSize();

Returns

Promise<PhysicalSize>

The window's outer size.

Defined in

window.ts:523


requestUserAttention

requestUserAttention(requestType): Promise<void>

Requests user attention to the window, this has no effect if the application is already focused. How requesting for user attention manifests is platform dependent, see UserAttentionType for details.

Providing null will unset the request for user attention. Unsetting the request for user attention might not be done automatically by the WM when the window receives input.

Platform-specific

  • macOS: null has no effect.
  • Linux: Urgency levels have the same effect.

example

import { appWindow } from '@tauri-apps/api/window';
await appWindow.requestUserAttention();

Parameters

NameType
requestTypenull | UserAttentionType

Returns

Promise<void>

A promise indicating the success or failure of the operation.

Defined in

window.ts:743


scaleFactor

scaleFactor(): Promise<number>

The scale factor that can be used to map physical pixels to logical pixels.

example

import { appWindow } from '@tauri-apps/api/window';
const factor = await appWindow.scaleFactor();

Returns

Promise<number>

The window's monitor scale factor.

Defined in

window.ts:421


setAlwaysOnTop

setAlwaysOnTop(alwaysOnTop): Promise<void>

Whether the window should always be on top of other windows.

example

import { appWindow } from '@tauri-apps/api/window';
await appWindow.setAlwaysOnTop(true);

Parameters

NameTypeDescription
alwaysOnTopbooleanWhether the window should always be on top of other windows or not.

Returns

Promise<void>

A promise indicating the success or failure of the operation.

Defined in

window.ts:1061


setCursorGrab

setCursorGrab(grab): Promise<void>

Grabs the cursor, preventing it from leaving the window.

There's no guarantee that the cursor will be hidden. You should hide it by yourself if you want so.

Platform-specific

  • Linux: Unsupported.
  • macOS: This locks the cursor in a fixed location, which looks visually awkward.

example

import { appWindow } from '@tauri-apps/api/window';
await appWindow.setCursorGrab(true);

Parameters

NameTypeDescription
grabbooleantrue to grab the cursor icon, false to release it.

Returns

Promise<void>

A promise indicating the success or failure of the operation.

Defined in

window.ts:1377


setCursorIcon

setCursorIcon(icon): Promise<void>

Modifies the cursor icon of the window.

example

import { appWindow } from '@tauri-apps/api/window';
await appWindow.setCursorIcon('help');

Parameters

NameTypeDescription
iconCursorIconThe new cursor icon.

Returns

Promise<void>

A promise indicating the success or failure of the operation.

Defined in

window.ts:1437


setCursorPosition

setCursorPosition(position): Promise<void>

Changes the position of the cursor in window coordinates.

example

import { appWindow, LogicalPosition } from '@tauri-apps/api/window';
await appWindow.setCursorPosition(new LogicalPosition(600, 300));

Parameters

NameTypeDescription
positionPhysicalPosition | LogicalPositionThe new cursor position.

Returns

Promise<void>

A promise indicating the success or failure of the operation.

Defined in

window.ts:1464


setCursorVisible

setCursorVisible(visible): Promise<void>

Modifies the cursor's visibility.

Platform-specific

  • Windows: The cursor is only hidden within the confines of the window.
  • macOS: The cursor is hidden as long as the window has input focus, even if the cursor is outside of the window.

example

import { appWindow } from '@tauri-apps/api/window';
await appWindow.setCursorVisible(false);

Parameters

NameTypeDescription
visiblebooleanIf false, this will hide the cursor. If true, this will show the cursor.

Returns

Promise<void>

A promise indicating the success or failure of the operation.

Defined in

window.ts:1410


setDecorations

setDecorations(decorations): Promise<void>

Whether the window should have borders and bars.

example

import { appWindow } from '@tauri-apps/api/window';
await appWindow.setDecorations(false);

Parameters

NameTypeDescription
decorationsbooleanWhether the window should have borders and bars.

Returns

Promise<void>

A promise indicating the success or failure of the operation.

Defined in

window.ts:1034


setFocus

setFocus(): Promise<void>

Bring the window to front and focus.

example

import { appWindow } from '@tauri-apps/api/window';
await appWindow.setFocus();

Returns

Promise<void>

A promise indicating the success or failure of the operation.

Defined in

window.ts:1279


setFullscreen

setFullscreen(fullscreen): Promise<void>

Sets the window fullscreen state.

example

import { appWindow } from '@tauri-apps/api/window';
await appWindow.setFullscreen(true);

Parameters

NameTypeDescription
fullscreenbooleanWhether the window should go to fullscreen or not.

Returns

Promise<void>

A promise indicating the success or failure of the operation.

Defined in

window.ts:1253


setIcon

setIcon(icon): Promise<void>

Sets the window icon.

example

import { appWindow } from '@tauri-apps/api/window';
await appWindow.setIcon('/tauri/awesome.png');

Note that you need the icon-ico or icon-png Cargo features to use this API. To enable it, change your Cargo.toml file:

[dependencies]
tauri = { version = "...", features = ["...", "icon-png"] }

Parameters

NameTypeDescription
iconstring | Uint8ArrayIcon bytes or path to the icon file.

Returns

Promise<void>

A promise indicating the success or failure of the operation.

Defined in

window.ts:1312


setMaxSize

setMaxSize(size): Promise<void>

Sets the window maximum inner size. If the size argument is undefined, the constraint is unset.

example

import { appWindow, LogicalSize } from '@tauri-apps/api/window';
await appWindow.setMaxSize(new LogicalSize(600, 500));

Parameters

NameTypeDescription
sizeundefined | null | PhysicalSize | LogicalSizeThe logical or physical inner size, or null to unset the constraint.

Returns

Promise<void>

A promise indicating the success or failure of the operation.

Defined in

window.ts:1168


setMinSize

setMinSize(size): Promise<void>

Sets the window minimum inner size. If the size argument is not provided, the constraint is unset.

example

import { appWindow, PhysicalSize } from '@tauri-apps/api/window';
await appWindow.setMinSize(new PhysicalSize(600, 500));

Parameters

NameTypeDescription
sizeundefined | null | PhysicalSize | LogicalSizeThe logical or physical inner size, or null to unset the constraint.

Returns

Promise<void>

A promise indicating the success or failure of the operation.

Defined in

window.ts:1126


setPosition

setPosition(position): Promise<void>

Sets the window outer position.

example

import { appWindow, LogicalPosition } from '@tauri-apps/api/window';
await appWindow.setPosition(new LogicalPosition(600, 500));

Parameters

NameTypeDescription
positionPhysicalPosition | LogicalPositionThe new position, in logical or physical pixels.

Returns

Promise<void>

A promise indicating the success or failure of the operation.

Defined in

window.ts:1210


setResizable

setResizable(resizable): Promise<void>

Updates the window resizable flag.

example

import { appWindow } from '@tauri-apps/api/window';
await appWindow.setResizable(false);

Parameters

NameType
resizableboolean

Returns

Promise<void>

A promise indicating the success or failure of the operation.

Defined in

window.ts:780


setSize

setSize(size): Promise<void>

Resizes the window with a new inner size.

example

import { appWindow, LogicalSize } from '@tauri-apps/api/window';
await appWindow.setSize(new LogicalSize(600, 500));

Parameters

NameTypeDescription
sizePhysicalSize | LogicalSizeThe logical or physical inner size.

Returns

Promise<void>

A promise indicating the success or failure of the operation.

Defined in

window.ts:1088


setSkipTaskbar

setSkipTaskbar(skip): Promise<void>

Whether to show the window icon in the task bar or not.

example

import { appWindow } from '@tauri-apps/api/window';
await appWindow.setSkipTaskbar(true);

Parameters

NameTypeDescription
skipbooleantrue to hide window icon, false to show it.

Returns

Promise<void>

A promise indicating the success or failure of the operation.

Defined in

window.ts:1342


setTitle

setTitle(title): Promise<void>

Sets the window title.

example

import { appWindow } from '@tauri-apps/api/window';
await appWindow.setTitle('Tauri');

Parameters

NameTypeDescription
titlestringThe new title

Returns

Promise<void>

A promise indicating the success or failure of the operation.

Defined in

window.ts:807


show

show(): Promise<void>

Sets the window visibility to true.

example

import { appWindow } from '@tauri-apps/api/window';
await appWindow.show();

Returns

Promise<void>

A promise indicating the success or failure of the operation.

Defined in

window.ts:958


startDragging

startDragging(): Promise<void>

Starts dragging the window.

example

import { appWindow } from '@tauri-apps/api/window';
await appWindow.startDragging();

Returns

Promise<void>

A promise indicating the success or failure of the operation.

Defined in

window.ts:1506


theme

theme(): Promise<null | Theme>

Gets the window's current theme.

Platform-specific

  • Linux: Not implemented, always returns light.
  • macOS: Theme was introduced on macOS 10.14. Returns light on macOS 10.13 and below.

example

import { appWindow } from '@tauri-apps/api/window';
const theme = await appWindow.theme();

Returns

Promise<null | Theme>

The window theme.

Defined in

window.ts:679


toggleMaximize

toggleMaximize(): Promise<void>

Toggles the window maximized state.

example

import { appWindow } from '@tauri-apps/api/window';
await appWindow.toggleMaximize();

Returns

Promise<void>

A promise indicating the success or failure of the operation.

Defined in

window.ts:883


unmaximize

unmaximize(): Promise<void>

Unmaximizes the window.

example

import { appWindow } from '@tauri-apps/api/window';
await appWindow.unmaximize();

Returns

Promise<void>

A promise indicating the success or failure of the operation.

Defined in

window.ts:858


unminimize

unminimize(): Promise<void>

Unminimizes the window.

example

import { appWindow } from '@tauri-apps/api/window';
await appWindow.unminimize();

Returns

Promise<void>

A promise indicating the success or failure of the operation.

Defined in

window.ts:933