Skip to content

Commit e0f0dce

Browse files
feat: add window effects api (#6442)
Co-authored-by: Lucas Nogueira <lucas@tauri.studio> Co-authored-by: Lucas Nogueira <lucas@tauri.app>
1 parent 7e5905a commit e0f0dce

File tree

17 files changed

+1497
-20
lines changed

17 files changed

+1497
-20
lines changed

.changes/window-effects-api.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'api': minor
3+
---
4+
5+
Added the `windowEffects` option when creating a window and `setWindowEffects` method to change it at runtime.

.changes/window-effects-config.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'tauri-utils': minor
3+
---
4+
5+
Added the `window_effects` option to the window configuration.

.changes/window-effects.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'tauri': minor
3+
'tauri-runtime-wry': minor
4+
'tauri-runtime': minor
5+
---
6+
7+
Added the `window_effects` option when creating a window and `Window::set_effects` to change it at runtime.

core/tauri-config-schema/schema.json

+276
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,17 @@
488488
"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.",
489489
"default": true,
490490
"type": "boolean"
491+
},
492+
"windowEffects": {
493+
"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",
494+
"anyOf": [
495+
{
496+
"$ref": "#/definitions/WindowEffectsConfig"
497+
},
498+
{
499+
"type": "null"
500+
}
501+
]
491502
}
492503
},
493504
"additionalProperties": false
@@ -551,6 +562,271 @@
551562
}
552563
]
553564
},
565+
"WindowEffectsConfig": {
566+
"description": "The window effects configuration object",
567+
"type": "object",
568+
"required": [
569+
"effects"
570+
],
571+
"properties": {
572+
"effects": {
573+
"description": "List of Window effects to apply to the Window. Conflicting effects will apply the first one and ignore the rest.",
574+
"type": "array",
575+
"items": {
576+
"$ref": "#/definitions/WindowEffect"
577+
}
578+
},
579+
"state": {
580+
"description": "Window effect state **macOS Only**",
581+
"anyOf": [
582+
{
583+
"$ref": "#/definitions/WindowEffectState"
584+
},
585+
{
586+
"type": "null"
587+
}
588+
]
589+
},
590+
"radius": {
591+
"description": "Window effect corner radius **macOS Only**",
592+
"type": [
593+
"number",
594+
"null"
595+
],
596+
"format": "double"
597+
},
598+
"color": {
599+
"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.",
600+
"anyOf": [
601+
{
602+
"$ref": "#/definitions/Color"
603+
},
604+
{
605+
"type": "null"
606+
}
607+
]
608+
}
609+
},
610+
"additionalProperties": false
611+
},
612+
"WindowEffect": {
613+
"description": "Platform-specific window effects",
614+
"oneOf": [
615+
{
616+
"description": "A default material appropriate for the view's effectiveAppearance. **macOS 10.14-**",
617+
"deprecated": true,
618+
"type": "string",
619+
"enum": [
620+
"appearanceBased"
621+
]
622+
},
623+
{
624+
"description": "*macOS 10.14-**",
625+
"deprecated": true,
626+
"type": "string",
627+
"enum": [
628+
"light"
629+
]
630+
},
631+
{
632+
"description": "*macOS 10.14-**",
633+
"deprecated": true,
634+
"type": "string",
635+
"enum": [
636+
"dark"
637+
]
638+
},
639+
{
640+
"description": "*macOS 10.14-**",
641+
"deprecated": true,
642+
"type": "string",
643+
"enum": [
644+
"mediumLight"
645+
]
646+
},
647+
{
648+
"description": "*macOS 10.14-**",
649+
"deprecated": true,
650+
"type": "string",
651+
"enum": [
652+
"ultraDark"
653+
]
654+
},
655+
{
656+
"description": "*macOS 10.10+**",
657+
"type": "string",
658+
"enum": [
659+
"titlebar"
660+
]
661+
},
662+
{
663+
"description": "*macOS 10.10+**",
664+
"type": "string",
665+
"enum": [
666+
"selection"
667+
]
668+
},
669+
{
670+
"description": "*macOS 10.11+**",
671+
"type": "string",
672+
"enum": [
673+
"menu"
674+
]
675+
},
676+
{
677+
"description": "*macOS 10.11+**",
678+
"type": "string",
679+
"enum": [
680+
"popover"
681+
]
682+
},
683+
{
684+
"description": "*macOS 10.11+**",
685+
"type": "string",
686+
"enum": [
687+
"sidebar"
688+
]
689+
},
690+
{
691+
"description": "*macOS 10.14+**",
692+
"type": "string",
693+
"enum": [
694+
"headerView"
695+
]
696+
},
697+
{
698+
"description": "*macOS 10.14+**",
699+
"type": "string",
700+
"enum": [
701+
"sheet"
702+
]
703+
},
704+
{
705+
"description": "*macOS 10.14+**",
706+
"type": "string",
707+
"enum": [
708+
"windowBackground"
709+
]
710+
},
711+
{
712+
"description": "*macOS 10.14+**",
713+
"type": "string",
714+
"enum": [
715+
"hudWindow"
716+
]
717+
},
718+
{
719+
"description": "*macOS 10.14+**",
720+
"type": "string",
721+
"enum": [
722+
"fullScreenUI"
723+
]
724+
},
725+
{
726+
"description": "*macOS 10.14+**",
727+
"type": "string",
728+
"enum": [
729+
"tooltip"
730+
]
731+
},
732+
{
733+
"description": "*macOS 10.14+**",
734+
"type": "string",
735+
"enum": [
736+
"contentBackground"
737+
]
738+
},
739+
{
740+
"description": "*macOS 10.14+**",
741+
"type": "string",
742+
"enum": [
743+
"underWindowBackground"
744+
]
745+
},
746+
{
747+
"description": "*macOS 10.14+**",
748+
"type": "string",
749+
"enum": [
750+
"underPageBackground"
751+
]
752+
},
753+
{
754+
"description": "*Windows 11 Only**",
755+
"type": "string",
756+
"enum": [
757+
"mica"
758+
]
759+
},
760+
{
761+
"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.",
762+
"type": "string",
763+
"enum": [
764+
"blur"
765+
]
766+
},
767+
{
768+
"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.",
769+
"type": "string",
770+
"enum": [
771+
"acrylic"
772+
]
773+
}
774+
]
775+
},
776+
"WindowEffectState": {
777+
"description": "Window effect state **macOS only**\n\n<https://developer.apple.com/documentation/appkit/nsvisualeffectview/state>",
778+
"oneOf": [
779+
{
780+
"description": "Make window effect state follow the window's active state",
781+
"type": "string",
782+
"enum": [
783+
"followsWindowActiveState"
784+
]
785+
},
786+
{
787+
"description": "Make window effect state always active",
788+
"type": "string",
789+
"enum": [
790+
"active"
791+
]
792+
},
793+
{
794+
"description": "Make window effect state always inactive",
795+
"type": "string",
796+
"enum": [
797+
"inactive"
798+
]
799+
}
800+
]
801+
},
802+
"Color": {
803+
"description": "a tuple struct of RGBA colors. Each value has minimum of 0 and maximum of 255.",
804+
"type": "array",
805+
"items": [
806+
{
807+
"type": "integer",
808+
"format": "uint8",
809+
"minimum": 0.0
810+
},
811+
{
812+
"type": "integer",
813+
"format": "uint8",
814+
"minimum": 0.0
815+
},
816+
{
817+
"type": "integer",
818+
"format": "uint8",
819+
"minimum": 0.0
820+
},
821+
{
822+
"type": "integer",
823+
"format": "uint8",
824+
"minimum": 0.0
825+
}
826+
],
827+
"maxItems": 4,
828+
"minItems": 4
829+
},
554830
"BundleConfig": {
555831
"description": "Configuration for tauri-bundler.\n\nSee more: https://tauri.app/v1/api/config#bundleconfig",
556832
"type": "object",

core/tauri-runtime/src/webview.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::{menu::Menu, window::DetachedWindow, Icon};
99
#[cfg(target_os = "macos")]
1010
use tauri_utils::TitleBarStyle;
1111
use tauri_utils::{
12-
config::{WindowConfig, WindowUrl},
12+
config::{WindowConfig, WindowEffectsConfig, WindowUrl},
1313
Theme,
1414
};
1515

@@ -29,6 +29,7 @@ pub struct WebviewAttributes {
2929
pub clipboard: bool,
3030
pub accept_first_mouse: bool,
3131
pub additional_browser_args: Option<String>,
32+
pub window_effects: Option<WindowEffectsConfig>,
3233
}
3334

3435
impl WebviewAttributes {
@@ -43,6 +44,7 @@ impl WebviewAttributes {
4344
clipboard: false,
4445
accept_first_mouse: false,
4546
additional_browser_args: None,
47+
window_effects: None,
4648
}
4749
}
4850

@@ -97,6 +99,13 @@ impl WebviewAttributes {
9799
self.additional_browser_args = Some(additional_args.to_string());
98100
self
99101
}
102+
103+
/// Sets window effects
104+
#[must_use]
105+
pub fn window_effects(mut self, effects: WindowEffectsConfig) -> Self {
106+
self.window_effects = Some(effects);
107+
self
108+
}
100109
}
101110

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

0 commit comments

Comments
 (0)