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:
References
Color
Re-exports Color
DragDropEvent
Re-exports DragDropEvent
LogicalPosition
Re-exports LogicalPosition
LogicalSize
Re-exports LogicalSize
PhysicalPosition
Re-exports PhysicalPosition
PhysicalSize
Re-exports PhysicalSize
Enumerations
Effect
Platform-specific window effects
Since
2.0.0
Enumeration Members
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: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2062
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: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1962
Blur
Windows 7/10/11(22H1) Only
Notes
This effect has bad performance when resizing/dragging the window on Windows 11 build 22621.
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2054
ContentBackground
macOS 10.14+
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2034
Dark
macOS 10.14-
Deprecated
since macOS 10.14. Use a semantic material instead.
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1974
FullScreenUI
macOS 10.14+
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2026
HeaderView
macOS 10.14+
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2010
HudWindow
macOS 10.14+
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2022
Light
macOS 10.14-
Deprecated
since macOS 10.14. Use a semantic material instead.
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1968
MediumLight
macOS 10.14-
Deprecated
since macOS 10.14. Use a semantic material instead.
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1980
Menu
macOS 10.11+
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1998
Mica
Windows 11 Only
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2046
Popover
macOS 10.11+
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2002
Selection
macOS 10.10+
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1994
Sheet
macOS 10.14+
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2014
Sidebar
macOS 10.11+
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2006
Tabbed
Tabbed effect that matches the system dark perefence Windows 11 Only
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2066
TabbedDark
Tabbed effect with dark mode but only if dark mode is enabled on the system Windows 11 Only
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2070
TabbedLight
Tabbed effect with light mode Windows 11 Only
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2074
Titlebar
macOS 10.10+
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1990
Tooltip
macOS 10.14+
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2030
UltraDark
macOS 10.14-
Deprecated
since macOS 10.14. Use a semantic material instead.
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1986
UnderPageBackground
macOS 10.14+
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2042
UnderWindowBackground
macOS 10.14+
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2038
WindowBackground
macOS 10.14+
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2018
EffectState
Window effect state macOS only
See
https://developer.apple.com/documentation/appkit/nsvisualeffectview/state
Since
2.0.0
Enumeration Members
Active
Make window effect state always active macOS only
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2092
FollowsWindowActiveState
Make window effect state follow the window’s active state macOS only
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2088
Inactive
Make window effect state always inactive macOS only
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2096
ProgressBarStatus
Enumeration Members
Error
Error state. Treated as Normal on linux
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L185
Indeterminate
Indeterminate state. Treated as Normal on Linux and macOS
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L177
None
Hide progress bar.
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L169
Normal
Normal state.
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L173
Paused
Paused state. Treated as Normal on Linux
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L181
UserAttentionType
Attention type to request on a window.
Since
1.0.0
Enumeration Members
Critical
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: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L94
Informational
Platform-specific
- macOS: Bounces the dock icon once.
- Windows: Flashes the taskbar button until the application is in focus.
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L100
Classes
CloseRequestedEvent
Constructors
new CloseRequestedEvent()
Parameters
Parameter | Type |
---|---|
event | Event <unknown > |
Returns
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L110
Properties
Property | Type | Description | Defined in |
---|---|---|---|
event | EventName | Event name | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L105 |
id | number | Event identifier used to unlisten | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L107 |
Methods
isPreventDefault()
Returns
boolean
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L119
preventDefault()
Returns
void
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L115
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
Since
2.0.0
Extended by
Constructors
new Window()
Creates a new Window.
Parameters
Parameter | Type | Description |
---|---|---|
label | string | The unique window label. Must be alphanumeric: a-zA-Z-/:_ . |
options | WindowOptions | - |
Returns
The Window instance to communicate with the window.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L293
Properties
Property | Type | Description | Defined in |
---|---|---|---|
label | string | The window label. It is a unique identifier for the window, can be used to reference it later. | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L271 |
listeners | Record <string , EventCallback <any >[]> | Local event listeners. | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L274 |
Methods
center()
Centers the window.
Returns
Promise
<void
>
A promise indicating the success or failure of the operation.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L814
clearEffects()
Clear any applied effects if possible.
Returns
Promise
<void
>
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1202
close()
Closes the window.
Note this emits a closeRequested event so you can intercept it. To force window close, use Window.destroy.
Returns
Promise
<void
>
A promise indicating the success or failure of the operation.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1123
destroy()
Destroys the window. Behaves like Window.close but forces the window close instead of emitting a closeRequested event.
Returns
Promise
<void
>
A promise indicating the success or failure of the operation.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1139
emit()
Emits an event to all targets.
Parameters
Parameter | Type | Description |
---|---|---|
event | string | Event name. Must include only alphanumeric characters, - , / , : and _ . |
payload ? | unknown | Event payload. |
Returns
Promise
<void
>
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L444
emitTo()
Emits an event to all targets matching the given target.
Parameters
Parameter | Type | Description |
---|---|---|
target | string | EventTarget | Label of the target Window/Webview/WebviewWindow or raw EventTarget object. |
event | string | Event name. Must include only alphanumeric characters, - , / , : and _ . |
payload ? | unknown | Event payload. |
Returns
Promise
<void
>
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L471
hide()
Sets the window visibility to false.
Returns
Promise
<void
>
A promise indicating the success or failure of the operation.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1105
innerPosition()
The position of the top-left hand corner of the window’s client area relative to the top-left hand corner of the desktop.
Returns
The window’s inner position.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L532
innerSize()
The physical size of the window’s client area. The client area is the content of the window, excluding the title bar and borders.
Returns
The window’s inner size.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L565
isClosable()
Gets the window’s native close button state.
Platform-specific
- iOS / Android: Unsupported.
Returns
Promise
<boolean
>
Whether the window’s native close button is enabled or not.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L745
isDecorated()
Gets the window’s current decorated state.
Returns
Promise
<boolean
>
Whether the window is decorated or not.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L666
isEnabled()
Whether the window is enabled or disabled.
Returns
Promise
<boolean
>
A promise indicating the success or failure of the operation.
Example
Since
2.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L906
isFocused()
Gets the window’s current focus state.
Returns
Promise
<boolean
>
Whether the window is focused or not.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L650
isFullscreen()
Gets the window’s current fullscreen state.
Returns
Promise
<boolean
>
Whether the window is in fullscreen mode or not.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L604
isMaximizable()
Gets the window’s native maximize button state.
Platform-specific
- Linux / iOS / Android: Unsupported.
Returns
Promise
<boolean
>
Whether the window’s native maximize button is enabled or not.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L703
isMaximized()
Gets the window’s current maximized state.
Returns
Promise
<boolean
>
Whether the window is maximized or not.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L634
isMinimizable()
Gets the window’s native minimize button state.
Platform-specific
- Linux / iOS / Android: Unsupported.
Returns
Promise
<boolean
>
Whether the window’s native minimize button is enabled or not.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L724
isMinimized()
Gets the window’s current minimized state.
Returns
Promise
<boolean
>
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L618
isResizable()
Gets the window’s current resizable state.
Returns
Promise
<boolean
>
Whether the window is resizable or not.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L682
isVisible()
Gets the window’s current visible state.
Returns
Promise
<boolean
>
Whether the window is visible or not.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L761
listen()
Listen to an emitted event on this window.
Type Parameters
Type Parameter |
---|
T |
Parameters
Parameter | Type | Description |
---|---|---|
event | EventName | Event name. Must include only alphanumeric characters, - , / , : and _ . |
handler | EventCallback <T > | Event handler. |
Returns
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.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L382
maximize()
Maximizes the window.
Returns
Promise
<void
>
A promise indicating the success or failure of the operation.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1009
minimize()
Minimizes the window.
Returns
Promise
<void
>
A promise indicating the success or failure of the operation.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1057
once()
Listen to an emitted event on this window only once.
Type Parameters
Type Parameter |
---|
T |
Parameters
Parameter | Type | Description |
---|---|---|
event | EventName | Event name. Must include only alphanumeric characters, - , / , : and _ . |
handler | EventCallback <T > | Event handler. |
Returns
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.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L417
onCloseRequested()
Listen to window close requested. Emitted when the user requests to closes the window.
Parameters
Parameter | Type |
---|---|
handler | (event ) => void | Promise <void > |
Returns
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.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1751
onDragDropEvent()
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.
Parameters
Parameter | Type |
---|---|
handler | EventCallback <DragDropEvent > |
Returns
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.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1789
onFocusChanged()
Listen to window focus change.
Parameters
Parameter | Type |
---|---|
handler | EventCallback <boolean > |
Returns
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.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1867
onMoved()
Listen to window move.
Parameters
Parameter | Type |
---|---|
handler | EventCallback <PhysicalPosition > |
Returns
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.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1722
onResized()
Listen to window resize.
Parameters
Parameter | Type |
---|---|
handler | EventCallback <PhysicalSize > |
Returns
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.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1698
onScaleChanged()
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.
Parameters
Parameter | Type |
---|---|
handler | EventCallback <ScaleFactorChanged > |
Returns
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.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1907
onThemeChanged()
Listen to the system theme change.
Parameters
Parameter | Type |
---|---|
handler | EventCallback <Theme > |
Returns
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.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1933
outerPosition()
The position of the top-left hand corner of the window relative to the top-left hand corner of the desktop.
Returns
The window’s outer position.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L548
outerSize()
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.
Returns
The window’s outer size.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L585
requestUserAttention()
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.
Parameters
Parameter | Type |
---|---|
requestType | null | UserAttentionType |
Returns
Promise
<void
>
A promise indicating the success or failure of the operation.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L840
scaleFactor()
The scale factor that can be used to map physical pixels to logical pixels.
Returns
Promise
<number
>
The window’s monitor scale factor.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L516
setAlwaysOnBottom()
Whether the window should always be below other windows.
Parameters
Parameter | Type | Description |
---|---|---|
alwaysOnBottom | boolean | Whether the window should always be below other windows or not. |
Returns
Promise
<void
>
A promise indicating the success or failure of the operation.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1238
setAlwaysOnTop()
Whether the window should always be on top of other windows.
Parameters
Parameter | Type | Description |
---|---|---|
alwaysOnTop | boolean | Whether 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.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1220
setBackgroundColor()
Sets the window background color.
Platform-specific:
- Windows: alpha channel is ignored.
- iOS / Android: Unsupported.
Parameters
Parameter | Type |
---|---|
color | Color |
Returns
Promise
<void
>
A promise indicating the success or failure of the operation.
Since
2.1.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1532
setClosable()
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.
Parameters
Parameter | Type |
---|---|
closable | boolean |
Returns
Promise
<void
>
A promise indicating the success or failure of the operation.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L974
setContentProtected()
Prevents the window contents from being captured by other apps.
Parameters
Parameter | Type |
---|---|
protected_ | boolean |
Returns
Promise
<void
>
A promise indicating the success or failure of the operation.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1255
setCursorGrab()
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.
Parameters
Parameter | Type | Description |
---|---|---|
grab | boolean | true to grab the cursor icon, false to release it. |
Returns
Promise
<void
>
A promise indicating the success or failure of the operation.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1471
setCursorIcon()
Modifies the cursor icon of the window.
Parameters
Parameter | Type | Description |
---|---|---|
icon | CursorIcon | The new cursor icon. |
Returns
Promise
<void
>
A promise indicating the success or failure of the operation.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1513
setCursorPosition()
Changes the position of the cursor in window coordinates.
Parameters
Parameter | Type | Description |
---|---|---|
position | LogicalPosition | PhysicalPosition | Position | The new cursor position. |
Returns
Promise
<void
>
A promise indicating the success or failure of the operation.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1547
setCursorVisible()
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.
Parameters
Parameter | Type | Description |
---|---|---|
visible | boolean | If 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.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1495
setDecorations()
Whether the window should have borders and bars.
Parameters
Parameter | Type | Description |
---|---|---|
decorations | boolean | Whether the window should have borders and bars. |
Returns
Promise
<void
>
A promise indicating the success or failure of the operation.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1156
setEffects()
Set window effects.
Parameters
Parameter | Type |
---|---|
effects | Effects |
Returns
Promise
<void
>
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1192
setEnabled()
Enable or disable the window.
Parameters
Parameter | Type |
---|---|
enabled | boolean |
Returns
Promise
<void
>
A promise indicating the success or failure of the operation.
Example
Since
2.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L887
setFocus()
Bring the window to front and focus.
Returns
Promise
<void
>
A promise indicating the success or failure of the operation.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1397
setFullscreen()
Sets the window fullscreen state.
Parameters
Parameter | Type | Description |
---|---|---|
fullscreen | boolean | Whether the window should go to fullscreen or not. |
Returns
Promise
<void
>
A promise indicating the success or failure of the operation.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1380
setIcon()
Sets the window icon.
Parameters
Parameter | Type | Description |
---|---|---|
icon | | string | Uint8Array | number [] | ArrayBuffer | Image | Icon bytes or path to the icon file. |
Returns
Promise
<void
>
A promise indicating the success or failure of the operation.
Example
Note that you may need the image-ico
or image-png
Cargo features to use this API.
To enable it, change your Cargo.toml file:
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1421
setIgnoreCursorEvents()
Changes the cursor events behavior.
Parameters
Parameter | Type | Description |
---|---|---|
ignore | boolean | true to ignore the cursor events; false to process them as usual. |
Returns
Promise
<void
>
A promise indicating the success or failure of the operation.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1568
setMaximizable()
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.
Parameters
Parameter | Type |
---|---|
maximizable | boolean |
Returns
Promise
<void
>
A promise indicating the success or failure of the operation.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L929
setMaxSize()
Sets the window maximum inner size. If the size
argument is undefined, the constraint is unset.
Parameters
Parameter | Type | Description |
---|---|---|
size | | undefined | null | LogicalSize | PhysicalSize | Size | The logical or physical inner size, or null to unset the constraint. |
Returns
Promise
<void
>
A promise indicating the success or failure of the operation.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1311
setMinimizable()
Sets whether the window’s native minimize button is enabled or not.
Platform-specific
- Linux / iOS / Android: Unsupported.
Parameters
Parameter | Type |
---|---|
minimizable | boolean |
Returns
Promise
<void
>
A promise indicating the success or failure of the operation.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L951
setMinSize()
Sets the window minimum inner size. If the size
argument is not provided, the constraint is unset.
Parameters
Parameter | Type | Description |
---|---|---|
size | | undefined | null | LogicalSize | PhysicalSize | Size | The logical or physical inner size, or null to unset the constraint. |
Returns
Promise
<void
>
A promise indicating the success or failure of the operation.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1291
setPosition()
Sets the window outer position.
Parameters
Parameter | Type | Description |
---|---|---|
position | LogicalPosition | PhysicalPosition | Position | The new position, in logical or physical pixels. |
Returns
Promise
<void
>
A promise indicating the success or failure of the operation.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1360
setProgressBar()
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).
Parameters
Parameter | Type |
---|---|
state | ProgressBarState |
Returns
Promise
<void
>
A promise indicating the success or failure of the operation.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1627
setResizable()
Updates the window resizable flag.
Parameters
Parameter | Type |
---|---|
resizable | boolean |
Returns
Promise
<void
>
A promise indicating the success or failure of the operation.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L868
setShadow()
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 undecorated window have a 1px white border, and on Windows 11, it will have a rounded corners.
- Linux: Unsupported.
Parameters
Parameter | Type |
---|---|
enable | boolean |
Returns
Promise
<void
>
A promise indicating the success or failure of the operation.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1182
setSize()
Resizes the window with a new inner size.
Parameters
Parameter | Type | Description |
---|---|---|
size | LogicalSize | PhysicalSize | Size | The logical or physical inner size. |
Returns
Promise
<void
>
A promise indicating the success or failure of the operation.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1273
setSizeConstraints()
Sets the window inner size constraints.
Parameters
Parameter | Type | Description |
---|---|---|
constraints | undefined | null | WindowSizeConstraints | The logical or physical inner size, or null to unset the constraint. |
Returns
Promise
<void
>
A promise indicating the success or failure of the operation.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1331
setSkipTaskbar()
Whether the window icon should be hidden from the taskbar or not.
Platform-specific
- macOS: Unsupported.
Parameters
Parameter | Type | Description |
---|---|---|
skip | boolean | true to hide window icon, false to show it. |
Returns
Promise
<void
>
A promise indicating the success or failure of the operation.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1445
setTheme()
Set window theme, pass in null
or undefined
to follow system theme
Platform-specific
- Linux / macOS: Theme is app-wide and not specific to this window.
- iOS / Android: Unsupported.
Parameters
Parameter | Type |
---|---|
theme ? | null | Theme |
Returns
Promise
<void
>
Since
2.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1672
setTitle()
Sets the window title.
Parameters
Parameter | Type | Description |
---|---|---|
title | string | The new title |
Returns
Promise
<void
>
A promise indicating the success or failure of the operation.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L992
setTitleBarStyle()
Sets the title bar style. macOS only.
Parameters
Parameter | Type |
---|---|
style | TitleBarStyle |
Returns
Promise
<void
>
Since
2.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1655
setVisibleOnAllWorkspaces()
Sets whether the window should be visible on all workspaces or virtual desktops.
Platform-specific
- Windows / iOS / Android: Unsupported.
Parameters
Parameter | Type |
---|---|
visible | boolean |
Returns
Promise
<void
>
Since
2.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1643
show()
Sets the window visibility to true.
Returns
Promise
<void
>
A promise indicating the success or failure of the operation.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1089
startDragging()
Starts dragging the window.
Returns
Promise
<void
>
A promise indicating the success or failure of the operation.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1585
startResizeDragging()
Starts resize-dragging the window.
Parameters
Parameter | Type |
---|---|
direction | ResizeDirection |
Returns
Promise
<void
>
A promise indicating the success or failure of the operation.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1601
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.
Returns
The window theme.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L796
title()
Gets the window’s current title.
Returns
Promise
<string
>
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L775
toggleMaximize()
Toggles the window maximized state.
Returns
Promise
<void
>
A promise indicating the success or failure of the operation.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1041
unmaximize()
Unmaximizes the window.
Returns
Promise
<void
>
A promise indicating the success or failure of the operation.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1025
unminimize()
Unminimizes the window.
Returns
Promise
<void
>
A promise indicating the success or failure of the operation.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1073
getAll()
Gets a list of instances of Window
for all available windows.
Returns
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L340
getByLabel()
Gets the Window associated with the given label.
Parameters
Parameter | Type | Description |
---|---|---|
label | string | The window label. |
Returns
The Window instance to communicate with the window or null if the window doesn’t exist.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L326
getCurrent()
Get an instance of Window
for the current window.
Returns
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L333
getFocusedWindow()
Gets the focused window.
Returns
The Window instance or undefined
if there is not any focused window.
Example
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L354
Interfaces
Effects
The window effects configuration object
Since
2.0.0
Properties
Property | Type | Description | Defined in |
---|---|---|---|
color? | Color | Window effect color. Affects Effect.Blur and Effect.Acrylic only on Windows 10 v1903+. Doesn’t have any effect on Windows 7 or Windows 11. | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2121 |
effects | Effect [] | List of Window effects to apply to the Window. Conflicting effects will apply the first one and ignore the rest. | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2108 |
radius? | number | Window effect corner radius macOS Only | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2116 |
state? | EffectState | Window effect state macOS Only | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2112 |
Monitor
Allows you to retrieve information about a given monitor.
Since
1.0.0
Properties
Property | Type | Description | Defined in |
---|---|---|---|
name | null | string | Human-readable name of the monitor | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L49 |
position | PhysicalPosition | the Top-left corner position of the monitor relative to the larger full screen area. | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L53 |
scaleFactor | number | The scale factor that can be used to map physical pixels to logical pixels. | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L55 |
size | PhysicalSize | The monitor’s resolution. | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L51 |
ProgressBarState
Properties
Property | Type | Description | Defined in |
---|---|---|---|
progress? | number | The progress bar progress. This can be a value ranging from 0 to 100 | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L203 |
status? | ProgressBarStatus | The progress bar status. | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L199 |
ScaleFactorChanged
The payload for the scaleChange
event.
Since
1.0.2
Properties
Property | Type | Description | Defined in |
---|---|---|---|
scaleFactor | number | The new window scale factor. | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L78 |
size | PhysicalSize | The new window size | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L80 |
WindowOptions
Configuration for the window to create.
Since
1.0.0
Properties
Property | Type | Description | Defined in |
---|---|---|---|
alwaysOnBottom? | boolean | Whether the window should always be below other windows. | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2171 |
alwaysOnTop? | boolean | Whether the window should always be on top of other windows or not. | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2169 |
backgroundColor? | Color | Set the window background color. #### Platform-specific: - Android / iOS: Unsupported. - Windows: alpha channel is ignored. Since 2.1.0 | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2267 |
center? | boolean | Show window in the center of the screen.. | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2131 |
closable? | boolean | Whether the window’s native close button is enabled or not. Defaults to true . | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2222 |
contentProtected? | boolean | Prevents the window contents from being captured by other apps. | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2173 |
decorations? | boolean | Whether the window should have borders and bars or not. | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2167 |
focus? | boolean | Whether the window will be initially focused or not. | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2155 |
fullscreen? | boolean | Whether the window is in fullscreen mode or not. | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2153 |
height? | number | The initial height. | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2139 |
hiddenTitle? | boolean | If true , sets the window title to be hidden on macOS. | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2203 |
maxHeight? | number | The maximum height. Only applies if maxWidth is also set. | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2147 |
maximizable? | boolean | Whether the window’s native maximize button is enabled or not. Defaults to true . | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2214 |
maximized? | boolean | Whether the window should be maximized upon creation or not. | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2163 |
maxWidth? | number | The maximum width. Only applies if maxHeight is also set. | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2145 |
minHeight? | number | The minimum height. Only applies if minWidth is also set. | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2143 |
minimizable? | boolean | Whether the window’s native minimize button is enabled or not. Defaults to true . | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2218 |
minWidth? | number | The minimum width. Only applies if minHeight is also set. | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2141 |
parent? | string | Window | WebviewWindow | Sets 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 | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2236 |
resizable? | boolean | Whether the window is resizable or not. | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2149 |
shadow? | boolean | Whether or not the window has shadow. #### Platform-specific - Windows: - false has no effect on decorated window, shadows are always ON. - true will make undecorated window have a 1px white border, and on Windows 11, it will have a rounded corners. - Linux: Unsupported. Since 2.0.0 | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2189 |
skipTaskbar? | boolean | Whether or not the window icon should be added to the taskbar. | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2175 |
tabbingIdentifier? | string | Defines 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. | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2210 |
theme? | Theme | The initial window theme. Defaults to the system theme. Only implemented on Windows and macOS 10.14+. | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2195 |
title? | string | Window title. | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2151 |
titleBarStyle? | TitleBarStyle | The style of the macOS title bar. | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2199 |
transparent? | boolean | Whether 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 . | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2161 |
visible? | boolean | Whether the window should be immediately visible upon creation or not. | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2165 |
visibleOnAllWorkspaces? | boolean | Whether the window should be visible on all workspaces or virtual desktops. #### Platform-specific - Windows / iOS / Android: Unsupported. Since 2.0.0 | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2245 |
width? | number | The initial width. | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2137 |
windowEffects? | Effects | Window effects. Requires the window to be transparent. #### Platform-specific: - Windows: If using decorations or shadows, you may want to try this workaround https://github.com/tauri-apps/tao/issues/72#issuecomment-975607891 - Linux: Unsupported | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2256 |
x? | number | The initial vertical position. Only applies if y is also set. | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2133 |
y? | number | The initial horizontal position. Only applies if x is also set. | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2135 |
WindowSizeConstraints
Properties
Property | Type | Defined in |
---|---|---|
maxHeight? | number | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L192 |
maxWidth? | number | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L191 |
minHeight? | number | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L190 |
minWidth? | number | Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L189 |
Type Aliases
CursorIcon
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L124
Theme
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L58
TitleBarStyle
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L59
Functions
availableMonitors()
Returns the list of all the monitors available on the system.
Returns
Example
Since
1.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2342
currentMonitor()
Returns the monitor on which the window currently resides.
Returns null
if current monitor can’t be detected.
Returns
Example
Since
1.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2292
cursorPosition()
Get the cursor position relative to the top-left hand corner of the desktop.
Note that the top-left hand corner of the desktop is not necessarily the same as the screen. If the user uses a desktop with multiple monitors, the top-left hand corner of the desktop is the top-left hand corner of the main monitor on Windows and macOS or the top-left of the leftmost monitor on X11.
The coordinates can be negative if the top-left hand corner of the window is outside of the visible screen region.
Returns
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2358
getAllWindows()
Gets a list of instances of Window
for all available windows.
Returns
Since
1.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L223
getCurrentWindow()
Get an instance of Window
for the current window.
Returns
Since
1.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L211
monitorFromPoint()
Returns the monitor that contains the given point. Returns null
if can’t find any.
Parameters
Parameter | Type |
---|---|
x | number |
y | number |
Returns
Example
Since
1.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2325
primaryMonitor()
Returns the primary monitor of the system.
Returns null
if it can’t identify any monitor as a primary one.
Returns
Example
Since
1.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2309
© 2024 Tauri Contributors. CC-BY / MIT