Skip to content
Tauri
Releases

window

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

Window events

Events can be listened to using Window.listen:

import { getCurrent } from '@tauri-apps/api/window';
getCurrent().listen('my-window-event', ({ event, payload }) => {});

References

LogicalPosition

Re-exports LogicalPosition

LogicalPosition;

Source: window.ts:2266


LogicalSize

Re-exports LogicalSize

LogicalSize;

Source: window.ts:2264


PhysicalPosition

Re-exports PhysicalPosition

PhysicalPosition;

Source: window.ts:2267


PhysicalSize

Re-exports PhysicalSize

PhysicalSize;

Source: window.ts:2265

Enumerations

Effect

Platform-specific window effects

Since

2.0.0

Enumeration Members

Acrylic
Acrylic: 'acrylic';

Windows 10/11

Notes

This effect has bad performance when resizing/dragging the window on Windows 10 v1903+ and Windows 11 build 22000.

Source: window.ts:2004


AppearanceBased
AppearanceBased: 'appearanceBased';

A default material appropriate for the view’s effectiveAppearance. macOS 10.14-

Deprecated

since macOS 10.14. You should instead choose an appropriate semantic material.

Source: window.ts:1904


Blur
Blur: 'blur';

Windows 7/10/11(22H1) Only

Notes

This effect has bad performance when resizing/dragging the window on Windows 11 build 22621.

Source: window.ts:1996


ContentBackground
ContentBackground: 'contentBackground';

macOS 10.14+

Source: window.ts:1976


Dark
Dark: 'dark';

macOS 10.14-

Deprecated

since macOS 10.14. Use a semantic material instead.

Source: window.ts:1916


FullScreenUI
FullScreenUI: 'fullScreenUI';

macOS 10.14+

Source: window.ts:1968


HeaderView
HeaderView: 'headerView';

macOS 10.14+

Source: window.ts:1952


HudWindow
HudWindow: 'hudWindow';

macOS 10.14+

Source: window.ts:1964


Light
Light: 'light';

macOS 10.14-

Deprecated

since macOS 10.14. Use a semantic material instead.

Source: window.ts:1910


MediumLight
MediumLight: 'mediumLight';

macOS 10.14-

Deprecated

since macOS 10.14. Use a semantic material instead.

Source: window.ts:1922


Menu: 'menu';

macOS 10.11+

Source: window.ts:1940


Mica
Mica: 'mica';

Windows 11 Only

Source: window.ts:1988


Popover
Popover: 'popover';

macOS 10.11+

Source: window.ts:1944


Selection
Selection: 'selection';

macOS 10.10+

Source: window.ts:1936


Sheet
Sheet: 'sheet';

macOS 10.14+

Source: window.ts:1956


Sidebar: 'sidebar';

macOS 10.11+

Source: window.ts:1948


Tabbed
Tabbed: 'tabbed';

Tabbed effect that matches the system dark perefence Windows 11 Only

Source: window.ts:2008


TabbedDark
TabbedDark: 'tabbedDark';

Tabbed effect with dark mode but only if dark mode is enabled on the system Windows 11 Only

Source: window.ts:2012


TabbedLight
TabbedLight: 'tabbedLight';

Tabbed effect with light mode Windows 11 Only

Source: window.ts:2016


Titlebar
Titlebar: 'titlebar';

macOS 10.10+

Source: window.ts:1932


Tooltip
Tooltip: 'tooltip';

macOS 10.14+

Source: window.ts:1972


UltraDark
UltraDark: 'ultraDark';

macOS 10.14-

Deprecated

since macOS 10.14. Use a semantic material instead.

Source: window.ts:1928


UnderPageBackground
UnderPageBackground: 'underPageBackground';

macOS 10.14+

Source: window.ts:1984


UnderWindowBackground
UnderWindowBackground: 'underWindowBackground';

macOS 10.14+

Source: window.ts:1980


WindowBackground
WindowBackground: 'windowBackground';

macOS 10.14+

Source: window.ts:1960


EffectState

Window effect state macOS only

See

https://developer.apple.com/documentation/appkit/nsvisualeffectview/state

Since

2.0.0

Enumeration Members

Active
Active: 'active';

Make window effect state always active macOS only

Source: window.ts:2034


FollowsWindowActiveState
FollowsWindowActiveState: 'followsWindowActiveState';

Make window effect state follow the window’s active state macOS only

Source: window.ts:2030


Inactive
Inactive: 'inactive';

Make window effect state always inactive macOS only

Source: window.ts:2038


ProgressBarStatus

Enumeration Members

Error
Error: 'error';

Error state. Treated as Normal on linux

Source: window.ts:184


Indeterminate
Indeterminate: 'indeterminate';

Indeterminate state. Treated as Normal on Linux and macOS

Source: window.ts:176


None
None: 'none';

Hide progress bar.

Source: window.ts:168


Normal
Normal: 'normal';

Normal state.

Source: window.ts:172


Paused
Paused: 'paused';

Paused state. Treated as Normal on Linux

Source: window.ts:180


UserAttentionType

Attention type to request on a window.

Since

1.0.0

Enumeration Members

Critical
Critical: 1;

Platform-specific

  • macOS: Bounces the dock icon until the application is in focus.
  • Windows: Flashes both the window and the taskbar button until the application is in focus.

Source: window.ts:93


Informational
Informational: 2;

Platform-specific

  • macOS: Bounces the dock icon once.
  • Windows: Flashes the taskbar button until the application is in focus.

Source: window.ts:99

Classes

CloseRequestedEvent

Constructors

constructor()
new CloseRequestedEvent(event): CloseRequestedEvent
Parameters
ParameterType
eventEvent< null >
Returns

CloseRequestedEvent

Source: window.ts:109

Properties

PropertyTypeDescription
private _preventDefaultboolean-
eventEventNameEvent name
idnumberEvent identifier used to unlisten

Methods

isPreventDefault()
isPreventDefault(): boolean
Returns

boolean

Source: window.ts:118


preventDefault()
preventDefault(): void
Returns

void

Source: window.ts:114


Window

Create new window or get a handle to an existing one.

Windows are identified by a label a unique identifier that can be used to reference it later. It may only contain alphanumeric characters a-zA-Z plus the following special characters -, /, : and _.

Example

import { Window } from '@tauri-apps/api/window';
const appWindow = new Window('theUniqueLabel');
appWindow.once('tauri://created', function () {
// window successfully created
});
appWindow.once('tauri://error', function (e) {
// an error happened creating the window
});
// emit an event to the backend
await appWindow.emit('some-event', 'data');
// listen to an event from the backend
const unlisten = await appWindow.listen('event-name', (e) => {});
unlisten();

Since

2.0.0

Extended By

Constructors

constructor()
new Window(label, options = {}): Window

Creates a new Window.

Example
import { Window } from '@tauri-apps/api/window';
const appWindow = new Window('my-label');
appWindow.once('tauri://created', function () {
// window successfully created
});
appWindow.once('tauri://error', function (e) {
// an error happened creating the window
});
Parameters
ParameterTypeDescription
labelstringThe unique window label. Must be alphanumeric: a-zA-Z-/:_.
optionsWindowOptions-
Returns

Window

The Window instance to communicate with the window.

Source: window.ts:283

Properties

PropertyTypeDescription
labelstringThe window label. It is a unique identifier for the window, can be used to reference it later.
listenersRecord< string, EventCallback< any >[] >Local event listeners.

Methods

center()
center(): Promise< void >

Centers the window.

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

Promise< void >

A promise indicating the success or failure of the operation.

Source: window.ts:801


clearEffects()
clearEffects(): Promise< void >

Clear any applied effects if possible.

Returns

Promise< void >

Source: window.ts:1152


close()
close(): Promise< void >

Closes the window.

Note this emits a closeRequested event so you can intercept it. To force window close, use Window.destroy.

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

Promise< void >

A promise indicating the success or failure of the operation.

Source: window.ts:1073


destroy()
destroy(): Promise< void >

Destroys the window. Behaves like Window.close but forces the window close instead of emitting a closeRequested event.

Example
import { getCurrent } from '@tauri-apps/api/window';
await getCurrent().destroy();
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Source: window.ts:1089


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

Emits an event to all targets.

Example
import { getCurrent } from '@tauri-apps/api/window';
await getCurrent().emit('window-loaded', { loggedIn: true, token: 'authToken' });
Parameters
ParameterTypeDescription
eventstringEvent name. Must include only alphanumeric characters, -, /, : and _.
payload?unknownEvent payload.
Returns

Promise< void >

Source: window.ts:431


emitTo()
emitTo(
target,
event,
payload?): Promise< void >

Emits an event to all targets matching the given target.

Example
import { getCurrent } from '@tauri-apps/api/window';
await getCurrent().emit('main', 'window-loaded', { loggedIn: true, token: 'authToken' });
Parameters
ParameterTypeDescription
targetstring | EventTargetLabel of the target Window/Webview/WebviewWindow or raw EventTarget object.
eventstringEvent name. Must include only alphanumeric characters, -, /, : and _.
payload?unknownEvent payload.
Returns

Promise< void >

Source: window.ts:458


hide()
hide(): Promise< void >

Sets the window visibility to false.

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

Promise< void >

A promise indicating the success or failure of the operation.

Source: window.ts:1055


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 { getCurrent } from '@tauri-apps/api/window';
const position = await getCurrent().innerPosition();
Returns

Promise< PhysicalPosition >

The window’s inner position.

Source: window.ts:519


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 { getCurrent } from '@tauri-apps/api/window';
const size = await getCurrent().innerSize();
Returns

Promise< PhysicalSize >

The window’s inner size.

Source: window.ts:552


isClosable()
isClosable(): Promise< boolean >

Gets the window’s native close button state.

Platform-specific

  • iOS / Android: Unsupported.
Example
import { getCurrent } from '@tauri-apps/api/window';
const closable = await getCurrent().isClosable();
Returns

Promise< boolean >

Whether the window’s native close button is enabled or not.

Source: window.ts:732


isDecorated()
isDecorated(): Promise< boolean >

Gets the window’s current decorated state.

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

Promise< boolean >

Whether the window is decorated or not.

Source: window.ts:653


isFocused()
isFocused(): Promise< boolean >

Gets the window’s current focus state.

Example
import { getCurrent } from '@tauri-apps/api/window';
const focused = await getCurrent().isFocused();
Returns

Promise< boolean >

Whether the window is focused or not.

Source: window.ts:637


isFullscreen()
isFullscreen(): Promise< boolean >

Gets the window’s current fullscreen state.

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

Promise< boolean >

Whether the window is in fullscreen mode or not.

Source: window.ts:591


isMaximizable()
isMaximizable(): Promise< boolean >

Gets the window’s native maximize button state.

Platform-specific

  • Linux / iOS / Android: Unsupported.
Example
import { getCurrent } from '@tauri-apps/api/window';
const maximizable = await getCurrent().isMaximizable();
Returns

Promise< boolean >

Whether the window’s native maximize button is enabled or not.

Source: window.ts:690


isMaximized()
isMaximized(): Promise< boolean >

Gets the window’s current maximized state.

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

Promise< boolean >

Whether the window is maximized or not.

Source: window.ts:621


isMinimizable()
isMinimizable(): Promise< boolean >

Gets the window’s native minimize button state.

Platform-specific

  • Linux / iOS / Android: Unsupported.
Example
import { getCurrent } from '@tauri-apps/api/window';
const minimizable = await getCurrent().isMinimizable();
Returns

Promise< boolean >

Whether the window’s native minimize button is enabled or not.

Source: window.ts:711


isMinimized()
isMinimized(): Promise< boolean >

Gets the window’s current minimized state.

Example
import { getCurrent } from '@tauri-apps/api/window';
const minimized = await getCurrent().isMinimized();
Returns

Promise< boolean >

Source: window.ts:605


isResizable()
isResizable(): Promise< boolean >

Gets the window’s current resizable state.

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

Promise< boolean >

Whether the window is resizable or not.

Source: window.ts:669


isVisible()
isVisible(): Promise< boolean >

Gets the window’s current visible state.

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

Promise< boolean >

Whether the window is visible or not.

Source: window.ts:748


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

Listen to an emitted event on this window.

Example
import { getCurrent } from '@tauri-apps/api/window';
const unlisten = await getCurrent().listen<string>('state-changed', (event) => {
console.log(`Got error: ${payload}`);
});
// you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
unlisten();
Type parameters
Parameter
T
Parameters
ParameterTypeDescription
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. Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.

Source: window.ts:372


maximize()
maximize(): Promise< void >

Maximizes the window.

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

Promise< void >

A promise indicating the success or failure of the operation.

Source: window.ts:959


minimize()
minimize(): Promise< void >

Minimizes the window.

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

Promise< void >

A promise indicating the success or failure of the operation.

Source: window.ts:1007


onCloseRequested()
onCloseRequested(handler): Promise< UnlistenFn >

Listen to window close requested. Emitted when the user requests to closes the window.

Example
import { getCurrent } from '@tauri-apps/api/window';
import { confirm } from '@tauri-apps/api/dialog';
const unlisten = await getCurrent().onCloseRequested(async (event) => {
const confirmed = await confirm('Are you sure?');
if (!confirmed) {
// user did not confirm closing the window; let's prevent it
event.preventDefault();
}
});
// you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
unlisten();
Parameters
ParameterType
handler(event) => void | Promise< void >
Returns

Promise< UnlistenFn >

A promise resolving to a function to unlisten to the event. Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.

Source: window.ts:1700


onDragDropEvent()
onDragDropEvent(handler): Promise< UnlistenFn >

Listen to a file drop event. The listener is triggered when the user hovers the selected files on the webview, drops the files or cancels the operation.

Example
import { getCurrent } from '@tauri-apps/api/webview';
const unlisten = await getCurrent().onDragDropEvent((event) => {
if (event.payload.type === 'hover') {
console.log('User hovering', event.payload.paths);
} else if (event.payload.type === 'drop') {
console.log('User dropped', event.payload.paths);
} else {
console.log('File drop cancelled');
}
});
// you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
unlisten();
Parameters
ParameterType
handlerEventCallback< DragDropEvent >
Returns

Promise< UnlistenFn >

A promise resolving to a function to unlisten to the event. Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.

Source: window.ts:1739


onFocusChanged()
onFocusChanged(handler): Promise< UnlistenFn >

Listen to window focus change.

Example
import { getCurrent } from '@tauri-apps/api/window';
const unlisten = await getCurrent().onFocusChanged(({ payload: focused }) => {
console.log('Focus changed, window is focused? ' + focused);
});
// you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
unlisten();
Parameters
ParameterType
handlerEventCallback< boolean >
Returns

Promise< UnlistenFn >

A promise resolving to a function to unlisten to the event. Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.

Source: window.ts:1815


onMoved()
onMoved(handler): Promise< UnlistenFn >

Listen to window move.

Example
import { getCurrent } from '@tauri-apps/api/window';
const unlisten = await getCurrent().onMoved(({ payload: position }) => {
console.log('Window moved', position);
});
// you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
unlisten();
Parameters
ParameterType
handlerEventCallback< PhysicalPosition >
Returns

Promise< UnlistenFn >

A promise resolving to a function to unlisten to the event. Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.

Source: window.ts:1670


onResized()
onResized(handler): Promise< UnlistenFn >

Listen to window resize.

Example
import { getCurrent } from '@tauri-apps/api/window';
const unlisten = await getCurrent().onResized(({ payload: size }) => {
console.log('Window resized', size);
});
// you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
unlisten();
Parameters
ParameterType
handlerEventCallback< PhysicalSize >
Returns

Promise< UnlistenFn >

A promise resolving to a function to unlisten to the event. Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.

Source: window.ts:1646


onScaleChanged()
onScaleChanged(handler): Promise< UnlistenFn >

Listen to window 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.
Example
import { getCurrent } from '@tauri-apps/api/window';
const unlisten = await getCurrent().onScaleChanged(({ payload }) => {
console.log('Scale changed', payload.scaleFactor, payload.size);
});
// you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
unlisten();
Parameters
ParameterType
handlerEventCallback< ScaleFactorChanged >
Returns

Promise< UnlistenFn >

A promise resolving to a function to unlisten to the event. Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.

Source: window.ts:1855


onThemeChanged()
onThemeChanged(handler): Promise< UnlistenFn >

Listen to the system theme change.

Example
import { getCurrent } from '@tauri-apps/api/window';
const unlisten = await getCurrent().onThemeChanged(({ payload: theme }) => {
console.log('New theme: ' + theme);
});
// you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
unlisten();
Parameters
ParameterType
handlerEventCallback< Theme >
Returns

Promise< UnlistenFn >

A promise resolving to a function to unlisten to the event. Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.

Source: window.ts:1881


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

Listen to an emitted event on this window only once.

Example
import { getCurrent } from '@tauri-apps/api/window';
const unlisten = await getCurrent().once<null>('initialized', (event) => {
console.log(`Window initialized!`);
});
// you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
unlisten();
Type parameters
Parameter
T
Parameters
ParameterTypeDescription
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. Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.

Source: window.ts:407


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 { getCurrent } from '@tauri-apps/api/window';
const position = await getCurrent().outerPosition();
Returns

Promise< PhysicalPosition >

The window’s outer position.

Source: window.ts:535


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 { getCurrent } from '@tauri-apps/api/window';
const size = await getCurrent().outerSize();
Returns

Promise< PhysicalSize >

The window’s outer size.

Source: window.ts:572


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 { getCurrent } from '@tauri-apps/api/window';
await getCurrent().requestUserAttention();
Parameters
ParameterType
requestTypenull | UserAttentionType
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Source: window.ts:827


scaleFactor()
scaleFactor(): Promise< number >

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

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

Promise< number >

The window’s monitor scale factor.

Source: window.ts:503


setAlwaysOnBottom()
setAlwaysOnBottom(alwaysOnBottom): Promise< void >

Whether the window should always be below other windows.

Example
import { getCurrent } from '@tauri-apps/api/window';
await getCurrent().setAlwaysOnBottom(true);
Parameters
ParameterTypeDescription
alwaysOnBottombooleanWhether the window should always be below other windows or not.
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Source: window.ts:1188


setAlwaysOnTop()
setAlwaysOnTop(alwaysOnTop): Promise< void >

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

Example
import { getCurrent } from '@tauri-apps/api/window';
await getCurrent().setAlwaysOnTop(true);
Parameters
ParameterTypeDescription
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.

Source: window.ts:1170


setClosable()
setClosable(closable): Promise< void >

Sets whether the window’s native close button is enabled or not.

Platform-specific

  • Linux: GTK+ will do its best to convince the window manager not to show a close button. Depending on the system, this function may not have any effect when called on a window that is already visible
  • iOS / Android: Unsupported.
Example
import { getCurrent } from '@tauri-apps/api/window';
await getCurrent().setClosable(false);
Parameters
ParameterType
closableboolean
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Source: window.ts:924


setContentProtected()
setContentProtected(protected_): Promise< void >

Prevents the window contents from being captured by other apps.

Example
import { getCurrent } from '@tauri-apps/api/window';
await getCurrent().setContentProtected(true);
Parameters
ParameterType
protected_boolean
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Source: window.ts:1205


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 { getCurrent } from '@tauri-apps/api/window';
await getCurrent().setCursorGrab(true);
Parameters
ParameterTypeDescription
grabbooleantrue to grab the cursor icon, false to release it.
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Source: window.ts:1449


setCursorIcon()
setCursorIcon(icon): Promise< void >

Modifies the cursor icon of the window.

Example
import { getCurrent } from '@tauri-apps/api/window';
await getCurrent().setCursorIcon('help');
Parameters
ParameterTypeDescription
iconCursorIconThe new cursor icon.
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Source: window.ts:1491


setCursorPosition()
setCursorPosition(position): Promise< void >

Changes the position of the cursor in window coordinates.

Example
import { getCurrent, LogicalPosition } from '@tauri-apps/api/window';
await getCurrent().setCursorPosition(new LogicalPosition(600, 300));
Parameters
ParameterTypeDescription
positionLogicalPosition | PhysicalPositionThe new cursor position.
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Source: window.ts:1509


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 { getCurrent } from '@tauri-apps/api/window';
await getCurrent().setCursorVisible(false);
Parameters
ParameterTypeDescription
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.

Source: window.ts:1473


setDecorations()
setDecorations(decorations): Promise< void >

Whether the window should have borders and bars.

Example
import { getCurrent } from '@tauri-apps/api/window';
await getCurrent().setDecorations(false);
Parameters
ParameterTypeDescription
decorationsbooleanWhether the window should have borders and bars.
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Source: window.ts:1106


setEffects()
setEffects(effects): Promise< void >

Set window effects.

Parameters
ParameterType
effectsEffects
Returns

Promise< void >

Source: window.ts:1142


setFocus()
setFocus(): Promise< void >

Bring the window to front and focus.

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

Promise< void >

A promise indicating the success or failure of the operation.

Source: window.ts:1375


setFullscreen()
setFullscreen(fullscreen): Promise< void >

Sets the window fullscreen state.

Example
import { getCurrent } from '@tauri-apps/api/window';
await getCurrent().setFullscreen(true);
Parameters
ParameterTypeDescription
fullscreenbooleanWhether the window should go to fullscreen or not.
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Source: window.ts:1358


setIcon()
setIcon(icon): Promise< void >

Sets the window icon.

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

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

[dependencies]
tauri = { version = "...", features = ["...", "image-png"] }
Parameters
ParameterTypeDescription
iconstring | number[] | ArrayBuffer | Uint8Array | ImageIcon bytes or path to the icon file.
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Source: window.ts:1399


setIgnoreCursorEvents()
setIgnoreCursorEvents(ignore): Promise< void >

Changes the cursor events behavior.

Example
import { getCurrent } from '@tauri-apps/api/window';
await getCurrent().setIgnoreCursorEvents(true);
Parameters
ParameterTypeDescription
ignorebooleantrue to ignore the cursor events; false to process them as usual.
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Source: window.ts:1545


setMaxSize()
setMaxSize(size): Promise< void >

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

Example
import { getCurrent, LogicalSize } from '@tauri-apps/api/window';
await getCurrent().setMaxSize(new LogicalSize(600, 500));
Parameters
ParameterTypeDescription
sizeundefined | null | LogicalSize | PhysicalSizeThe logical or physical inner size, or null to unset the constraint.
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Source: window.ts:1288


setMaximizable()
setMaximizable(maximizable): Promise< void >

Sets whether the window’s native maximize button is enabled or not. If resizable is set to false, this setting is ignored.

Platform-specific

  • macOS: Disables the “zoom” button in the window titlebar, which is also used to enter fullscreen mode.
  • Linux / iOS / Android: Unsupported.
Example
import { getCurrent } from '@tauri-apps/api/window';
await getCurrent().setMaximizable(false);
Parameters
ParameterType
maximizableboolean
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Source: window.ts:879


setMinSize()
setMinSize(size): Promise< void >

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

Example
import { getCurrent, PhysicalSize } from '@tauri-apps/api/window';
await getCurrent().setMinSize(new PhysicalSize(600, 500));
Parameters
ParameterTypeDescription
sizeundefined | null | LogicalSize | PhysicalSizeThe logical or physical inner size, or null to unset the constraint.
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Source: window.ts:1253


setMinimizable()
setMinimizable(minimizable): Promise< void >

Sets whether the window’s native minimize button is enabled or not.

Platform-specific

  • Linux / iOS / Android: Unsupported.
Example
import { getCurrent } from '@tauri-apps/api/window';
await getCurrent().setMinimizable(false);
Parameters
ParameterType
minimizableboolean
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Source: window.ts:901


setPosition()
setPosition(position): Promise< void >

Sets the window outer position.

Example
import { getCurrent, LogicalPosition } from '@tauri-apps/api/window';
await getCurrent().setPosition(new LogicalPosition(600, 500));
Parameters
ParameterTypeDescription
positionLogicalPosition | PhysicalPositionThe new position, in logical or physical pixels.
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Source: window.ts:1323


setProgressBar()
setProgressBar(state): Promise< void >

Sets the taskbar progress state.

Platform-specific

  • Linux / macOS: Progress bar is app-wide and not specific to this window.
  • Linux: Only supported desktop environments with libunity (e.g. GNOME).
Example
import { getCurrent, ProgressBarStatus } from '@tauri-apps/api/window';
await getCurrent().setProgressBar({
status: ProgressBarStatus.Normal,
progress: 50,
});
Parameters
ParameterType
stateProgressBarState
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Source: window.ts:1604


setResizable()
setResizable(resizable): Promise< void >

Updates the window resizable flag.

Example
import { getCurrent } from '@tauri-apps/api/window';
await getCurrent().setResizable(false);
Parameters
ParameterType
resizableboolean
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Source: window.ts:855


setShadow()
setShadow(enable): Promise< void >

Whether or not the window should have shadow.

Platform-specific

  • Windows:
    • false has no effect on decorated window, shadows are always ON.
    • true will make ndecorated window have a 1px white border, and on Windows 11, it will have a rounded corners.
  • Linux: Unsupported.
Example
import { getCurrent } from '@tauri-apps/api/window';
await getCurrent().setShadow(false);
Parameters
ParameterType
enableboolean
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Source: window.ts:1132


setSize()
setSize(size): Promise< void >

Resizes the window with a new inner size.

Example
import { getCurrent, LogicalSize } from '@tauri-apps/api/window';
await getCurrent().setSize(new LogicalSize(600, 500));
Parameters
ParameterTypeDescription
sizeLogicalSize | PhysicalSizeThe logical or physical inner size.
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Source: window.ts:1223


setSkipTaskbar()
setSkipTaskbar(skip): Promise< void >

Whether the window icon should be hidden from the taskbar or not.

Platform-specific

  • macOS: Unsupported.
Example
import { getCurrent } from '@tauri-apps/api/window';
await getCurrent().setSkipTaskbar(true);
Parameters
ParameterTypeDescription
skipbooleantrue to hide window icon, false to show it.
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Source: window.ts:1423


setTitle()
setTitle(title): Promise< void >

Sets the window title.

Example
import { getCurrent } from '@tauri-apps/api/window';
await getCurrent().setTitle('Tauri');
Parameters
ParameterTypeDescription
titlestringThe new title
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Source: window.ts:942


setVisibleOnAllWorkspaces()
setVisibleOnAllWorkspaces(visible): Promise< void >

Sets whether the window should be visible on all workspaces or virtual desktops.

Platform-specific

  • Windows / iOS / Android: Unsupported.
Since

2.0.0

Parameters
ParameterType
visibleboolean
Returns

Promise< void >

Source: window.ts:1620


show()
show(): Promise< void >

Sets the window visibility to true.

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

Promise< void >

A promise indicating the success or failure of the operation.

Source: window.ts:1039


startDragging()
startDragging(): Promise< void >

Starts dragging the window.

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

Promise< void >

A promise indicating the success or failure of the operation.

Source: window.ts:1562


startResizeDragging()
startResizeDragging(direction): Promise< void >

Starts resize-dragging the window.

Example
import { getCurrent } from '@tauri-apps/api/window';
await getCurrent().startResizeDragging();
Parameters
ParameterType
directionResizeDirection
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Source: window.ts:1578


theme()
theme(): Promise< null | Theme >

Gets the window’s current theme.

Platform-specific

  • macOS: Theme was introduced on macOS 10.14. Returns light on macOS 10.13 and below.
Example
import { getCurrent } from '@tauri-apps/api/window';
const theme = await getCurrent().theme();
Returns

Promise< null | Theme >

The window theme.

Source: window.ts:783


title()
title(): Promise< string >

Gets the window’s current title.

Example
import { getCurrent } from '@tauri-apps/api/window';
const title = await getCurrent().title();
Returns

Promise< string >

Source: window.ts:762


toggleMaximize()
toggleMaximize(): Promise< void >

Toggles the window maximized state.

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

Promise< void >

A promise indicating the success or failure of the operation.

Source: window.ts:991


unmaximize()
unmaximize(): Promise< void >

Unmaximizes the window.

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

Promise< void >

A promise indicating the success or failure of the operation.

Source: window.ts:975


unminimize()
unminimize(): Promise< void >

Unminimizes the window.

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

Promise< void >

A promise indicating the success or failure of the operation.

Source: window.ts:1023


getAll()
static getAll(): Window[]

Gets a list of instances of Window for all available windows.

Returns

Window[]

Source: window.ts:330


getByLabel()
static getByLabel(label): null | Window

Gets the Window associated with the given label.

Example
import { Window } from '@tauri-apps/api/window';
const mainWindow = Window.getByLabel('main');
Parameters
ParameterTypeDescription
labelstringThe window label.
Returns

null | Window

The Window instance to communicate with the window or null if the window doesn’t exist.

Source: window.ts:316


getCurrent()
static getCurrent(): Window

Get an instance of Window for the current window.

Returns

Window

Source: window.ts:323


getFocusedWindow()
static getFocusedWindow(): Promise< null | Window >

Gets the focused window.

Example
import { Window } from '@tauri-apps/api/window';
const focusedWindow = Window.getFocusedWindow();
Returns

Promise< null | Window >

The Window instance or undefined if there is not any focused window.

Source: window.ts:344

Interfaces

DragDropPayload

Properties

PropertyType
pathsstring[]
positionPhysicalPosition

Effects

The window effects configuration object

Since

2.0.0

Properties

PropertyTypeDescription
color?ColorWindow effect color. Affects Effect.Blur and Effect.Acrylic only
on Windows 10 v1903+. Doesn’t have any effect on Windows 7 or Windows 11.
effectsEffect[]List of Window effects to apply to the Window.
Conflicting effects will apply the first one and ignore the rest.
radius?numberWindow effect corner radius macOS Only
state?EffectStateWindow effect state macOS Only

Monitor

Allows you to retrieve information about a given monitor.

Since

1.0.0

Properties

PropertyTypeDescription
namenull | stringHuman-readable name of the monitor
positionPhysicalPositionthe Top-left corner position of the monitor relative to the larger full screen area.
scaleFactornumberThe scale factor that can be used to map physical pixels to logical pixels.
sizePhysicalSizeThe monitor’s resolution.

ProgressBarState

Properties

PropertyTypeDescription
progress?numberThe progress bar progress. This can be a value ranging from 0 to 100
status?ProgressBarStatusThe progress bar status.

ScaleFactorChanged

The payload for the scaleChange event.

Since

1.0.2

Properties

PropertyTypeDescription
scaleFactornumberThe new window scale factor.
sizePhysicalSizeThe new window size

WindowOptions

Configuration for the window to create.

Since

1.0.0

Properties

PropertyTypeDescription
alwaysOnBottom?booleanWhether the window should always be below other windows.
alwaysOnTop?booleanWhether the window should always be on top of other windows or not.
center?booleanShow window in the center of the screen..
closable?booleanWhether the window’s native close button is enabled or not. Defaults to true.
contentProtected?booleanPrevents the window contents from being captured by other apps.
decorations?booleanWhether the window should have borders and bars or not.
focus?booleanWhether the window will be initially focused or not.
fullscreen?booleanWhether the window is in fullscreen mode or not.
height?numberThe initial height.
hiddenTitle?booleanIf true, sets the window title to be hidden on macOS.
maxHeight?numberThe maximum height. Only applies if maxWidth is also set.
maxWidth?numberThe maximum width. Only applies if maxHeight is also set.
maximizable?booleanWhether the window’s native maximize button is enabled or not. Defaults to true.
maximized?booleanWhether the window should be maximized upon creation or not.
minHeight?numberThe minimum height. Only applies if minWidth is also set.
minWidth?numberThe minimum width. Only applies if minHeight is also set.
minimizable?booleanWhether the window’s native minimize button is enabled or not. Defaults to true.
parent?string | Window | WebviewWindowSets a parent to the window to be created. Can be either a Window or a label of the window.

#### Platform-specific

- Windows: This sets the passed parent as an owner window to the window to be created.
From MSDN owned windows docs:
- An owned window is always above its owner in the z-order.
- The system automatically destroys an owned window when its owner is destroyed.
- An owned window is hidden when its owner is minimized.
- Linux: This makes the new window transient for parent, see <https://docs.gtk.org/gtk3/method.Window.set_transient_for.html\>
- macOS: This adds the window as a child of parent, see <https://developer.apple.com/documentation/appkit/nswindow/1419152-addchildwindow?language=objc\>
resizable?booleanWhether the window is resizable or not.
shadow?booleanWhether or not the window has shadow.

#### Platform-specific

- Windows:
- false has no effect on decorated window, shadows are always ON.
- true will make ndecorated window have a 1px white border,
and on Windows 11, it will have a rounded corners.
- Linux: Unsupported.

Since

2.0.0
skipTaskbar?booleanWhether or not the window icon should be added to the taskbar.
tabbingIdentifier?stringDefines the window tabbing identifier on macOS.

Windows with the same tabbing identifier will be grouped together.
If the tabbing identifier is not set, automatic tabbing will be disabled.
theme?ThemeThe initial window theme. Defaults to the system theme.

Only implemented on Windows and macOS 10.14+.
title?stringWindow title.
titleBarStyle?TitleBarStyleThe style of the macOS title bar.
transparent?booleanWhether the window is transparent or not.
Note that on macOS this requires the macos-private-api feature flag, enabled under tauri.conf.json > app > macOSPrivateApi.
WARNING: Using private APIs on macOS prevents your application from being accepted to the App Store.
visible?booleanWhether the window should be immediately visible upon creation or not.
visibleOnAllWorkspaces?booleanWhether the window should be visible on all workspaces or virtual desktops.

## Platform-specific

- Windows / iOS / Android: Unsupported.

Since

2.0.0
width?numberThe initial width.
x?numberThe initial vertical position. Only applies if y is also set.
y?numberThe initial horizontal position. Only applies if x is also set.

Type Aliases

Color

Color: [number, number, number, number];

an array RGBA colors. Each value has minimum of 0 and maximum of 255.

Since

2.0.0

Source: window.ts:1891


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';

Source: window.ts:123


DragDropEvent

DragDropEvent: {type: "dragged";} & DragDropPayload | {type: "dragOver";} & DragOverPayload | {type: "dropped";} & DragDropPayload | {type: "cancelled";}

The drag and drop event types.

Source: webview.ts:46


Theme

Theme: 'light' | 'dark';

Source: window.ts:57


TitleBarStyle

TitleBarStyle: 'visible' | 'transparent' | 'overlay';

Source: window.ts:58

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();

Since

1.0.0

Returns

Promise< Monitor[] >

Source: window.ts:2253


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();

Since

1.0.0

Returns

Promise< Monitor | null >

Source: window.ts:2220


getAll()

getAll(): Window[]

Gets a list of instances of Window for all available windows.

Since

1.0.0

Returns

Window[]

Source: window.ts:215


getCurrent()

getCurrent(): Window

Get an instance of Window for the current window.

Since

1.0.0

Returns

Window

Source: window.ts:203


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();

Since

1.0.0

Returns

Promise< Monitor | null >

Source: window.ts:2237


© 2024 Tauri Contributors. CC-BY / MIT