Skip to content

Commit

Permalink
feat: add window effects api (#6442)
Browse files Browse the repository at this point in the history
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
Co-authored-by: Lucas Nogueira <lucas@tauri.app>
  • Loading branch information
3 people committed May 23, 2023
1 parent 7e5905a commit e0f0dce
Show file tree
Hide file tree
Showing 17 changed files with 1,497 additions and 20 deletions.
5 changes: 5 additions & 0 deletions .changes/window-effects-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'api': minor
---

Added the `windowEffects` option when creating a window and `setWindowEffects` method to change it at runtime.
5 changes: 5 additions & 0 deletions .changes/window-effects-config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'tauri-utils': minor
---

Added the `window_effects` option to the window configuration.
7 changes: 7 additions & 0 deletions .changes/window-effects.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'tauri': minor
'tauri-runtime-wry': minor
'tauri-runtime': minor
---

Added the `window_effects` option when creating a window and `Window::set_effects` to change it at runtime.
276 changes: 276 additions & 0 deletions core/tauri-config-schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,17 @@
"description": "Whether or not the window has shadow.\n\n## Platform-specific\n\n- **Windows:** - `false` has no effect on decorated window, shadow 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.",
"default": true,
"type": "boolean"
},
"windowEffects": {
"description": "Window effects.\n\nRequires the window to be transparent.\n\n## Platform-specific:\n\n- **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",
"anyOf": [
{
"$ref": "#/definitions/WindowEffectsConfig"
},
{
"type": "null"
}
]
}
},
"additionalProperties": false
Expand Down Expand Up @@ -551,6 +562,271 @@
}
]
},
"WindowEffectsConfig": {
"description": "The window effects configuration object",
"type": "object",
"required": [
"effects"
],
"properties": {
"effects": {
"description": "List of Window effects to apply to the Window. Conflicting effects will apply the first one and ignore the rest.",
"type": "array",
"items": {
"$ref": "#/definitions/WindowEffect"
}
},
"state": {
"description": "Window effect state **macOS Only**",
"anyOf": [
{
"$ref": "#/definitions/WindowEffectState"
},
{
"type": "null"
}
]
},
"radius": {
"description": "Window effect corner radius **macOS Only**",
"type": [
"number",
"null"
],
"format": "double"
},
"color": {
"description": "Window effect color. Affects [`WindowEffects::Blur`] and [`WindowEffects::Acrylic`] only on Windows 10 v1903+. Doesn't have any effect on Windows 7 or Windows 11.",
"anyOf": [
{
"$ref": "#/definitions/Color"
},
{
"type": "null"
}
]
}
},
"additionalProperties": false
},
"WindowEffect": {
"description": "Platform-specific window effects",
"oneOf": [
{
"description": "A default material appropriate for the view's effectiveAppearance. **macOS 10.14-**",
"deprecated": true,
"type": "string",
"enum": [
"appearanceBased"
]
},
{
"description": "*macOS 10.14-**",
"deprecated": true,
"type": "string",
"enum": [
"light"
]
},
{
"description": "*macOS 10.14-**",
"deprecated": true,
"type": "string",
"enum": [
"dark"
]
},
{
"description": "*macOS 10.14-**",
"deprecated": true,
"type": "string",
"enum": [
"mediumLight"
]
},
{
"description": "*macOS 10.14-**",
"deprecated": true,
"type": "string",
"enum": [
"ultraDark"
]
},
{
"description": "*macOS 10.10+**",
"type": "string",
"enum": [
"titlebar"
]
},
{
"description": "*macOS 10.10+**",
"type": "string",
"enum": [
"selection"
]
},
{
"description": "*macOS 10.11+**",
"type": "string",
"enum": [
"menu"
]
},
{
"description": "*macOS 10.11+**",
"type": "string",
"enum": [
"popover"
]
},
{
"description": "*macOS 10.11+**",
"type": "string",
"enum": [
"sidebar"
]
},
{
"description": "*macOS 10.14+**",
"type": "string",
"enum": [
"headerView"
]
},
{
"description": "*macOS 10.14+**",
"type": "string",
"enum": [
"sheet"
]
},
{
"description": "*macOS 10.14+**",
"type": "string",
"enum": [
"windowBackground"
]
},
{
"description": "*macOS 10.14+**",
"type": "string",
"enum": [
"hudWindow"
]
},
{
"description": "*macOS 10.14+**",
"type": "string",
"enum": [
"fullScreenUI"
]
},
{
"description": "*macOS 10.14+**",
"type": "string",
"enum": [
"tooltip"
]
},
{
"description": "*macOS 10.14+**",
"type": "string",
"enum": [
"contentBackground"
]
},
{
"description": "*macOS 10.14+**",
"type": "string",
"enum": [
"underWindowBackground"
]
},
{
"description": "*macOS 10.14+**",
"type": "string",
"enum": [
"underPageBackground"
]
},
{
"description": "*Windows 11 Only**",
"type": "string",
"enum": [
"mica"
]
},
{
"description": "**Windows 7/10/11(22H1) Only**\n\n## Notes\n\nThis effect has bad performance when resizing/dragging the window on Windows 11 build 22621.",
"type": "string",
"enum": [
"blur"
]
},
{
"description": "**Windows 10/11 Only**\n\n## Notes\n\nThis effect has bad performance when resizing/dragging the window on Windows 10 v1903+ and Windows 11 build 22000.",
"type": "string",
"enum": [
"acrylic"
]
}
]
},
"WindowEffectState": {
"description": "Window effect state **macOS only**\n\n<https://developer.apple.com/documentation/appkit/nsvisualeffectview/state>",
"oneOf": [
{
"description": "Make window effect state follow the window's active state",
"type": "string",
"enum": [
"followsWindowActiveState"
]
},
{
"description": "Make window effect state always active",
"type": "string",
"enum": [
"active"
]
},
{
"description": "Make window effect state always inactive",
"type": "string",
"enum": [
"inactive"
]
}
]
},
"Color": {
"description": "a tuple struct of RGBA colors. Each value has minimum of 0 and maximum of 255.",
"type": "array",
"items": [
{
"type": "integer",
"format": "uint8",
"minimum": 0.0
},
{
"type": "integer",
"format": "uint8",
"minimum": 0.0
},
{
"type": "integer",
"format": "uint8",
"minimum": 0.0
},
{
"type": "integer",
"format": "uint8",
"minimum": 0.0
}
],
"maxItems": 4,
"minItems": 4
},
"BundleConfig": {
"description": "Configuration for tauri-bundler.\n\nSee more: https://tauri.app/v1/api/config#bundleconfig",
"type": "object",
Expand Down
11 changes: 10 additions & 1 deletion core/tauri-runtime/src/webview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{menu::Menu, window::DetachedWindow, Icon};
#[cfg(target_os = "macos")]
use tauri_utils::TitleBarStyle;
use tauri_utils::{
config::{WindowConfig, WindowUrl},
config::{WindowConfig, WindowEffectsConfig, WindowUrl},
Theme,
};

Expand All @@ -29,6 +29,7 @@ pub struct WebviewAttributes {
pub clipboard: bool,
pub accept_first_mouse: bool,
pub additional_browser_args: Option<String>,
pub window_effects: Option<WindowEffectsConfig>,
}

impl WebviewAttributes {
Expand All @@ -43,6 +44,7 @@ impl WebviewAttributes {
clipboard: false,
accept_first_mouse: false,
additional_browser_args: None,
window_effects: None,
}
}

Expand Down Expand Up @@ -97,6 +99,13 @@ impl WebviewAttributes {
self.additional_browser_args = Some(additional_args.to_string());
self
}

/// Sets window effects
#[must_use]
pub fn window_effects(mut self, effects: WindowEffectsConfig) -> Self {
self.window_effects = Some(effects);
self
}
}

/// Do **NOT** implement this trait except for use in a custom [`Runtime`](crate::Runtime).
Expand Down

0 comments on commit e0f0dce

Please sign in to comment.