Skip to content

Commit a81750d

Browse files
feat(core): add shadow APIs (#6206)
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
1 parent 17f2676 commit a81750d

File tree

28 files changed

+950
-739
lines changed

28 files changed

+950
-739
lines changed

.changes/shadow-api.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'api': minor
3+
---
4+
5+
Added the `shadow` option when creating a window and `setShadow` function.

.changes/shadow-config.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'tauri-utils': minor
3+
---
4+
5+
Added the `shadow` option to the window configuration and `set_shadow` option to the `window` allow list.

.changes/shadow.md

Lines changed: 7 additions & 0 deletions
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 `shadow` option when creating a window and `Window::set_shadow`.

core/config-schema/schema.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
"setMinSize": false,
119119
"setPosition": false,
120120
"setResizable": false,
121+
"setShadow": false,
121122
"setSize": false,
122123
"setSkipTaskbar": false,
123124
"setTitle": false,
@@ -393,6 +394,7 @@
393394
"setMinSize": false,
394395
"setPosition": false,
395396
"setResizable": false,
397+
"setShadow": false,
396398
"setSize": false,
397399
"setSkipTaskbar": false,
398400
"setTitle": false,
@@ -684,6 +686,11 @@
684686
"string",
685687
"null"
686688
]
689+
},
690+
"shadow": {
691+
"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.",
692+
"default": false,
693+
"type": "boolean"
687694
}
688695
},
689696
"additionalProperties": false
@@ -1699,6 +1706,7 @@
16991706
"setMinSize": false,
17001707
"setPosition": false,
17011708
"setResizable": false,
1709+
"setShadow": false,
17021710
"setSize": false,
17031711
"setSkipTaskbar": false,
17041712
"setTitle": false,
@@ -2031,6 +2039,11 @@
20312039
"default": false,
20322040
"type": "boolean"
20332041
},
2042+
"setShadow": {
2043+
"description": "Allows setting the shadow flag of the window.",
2044+
"default": false,
2045+
"type": "boolean"
2046+
},
20342047
"setAlwaysOnTop": {
20352048
"description": "Allows setting the always_on_top flag of the window.",
20362049
"default": false,

core/tauri-runtime-wry/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ rand = "0.8"
2121
raw-window-handle = "0.5"
2222

2323
[target."cfg(windows)".dependencies]
24-
webview2-com = "0.19.1"
24+
webview2-com = "0.22"
2525

26-
[target."cfg(windows)".dependencies.windows]
27-
version = "0.39.0"
28-
features = [ "Win32_Foundation" ]
26+
[target."cfg(windows)".dependencies.windows]
27+
version = "0.44"
28+
features = [ "Win32_Foundation" ]
2929

3030
[target."cfg(any(target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\"))".dependencies]
3131
gtk = { version = "0.16", features = [ "v3_24" ] }

core/tauri-runtime-wry/src/lib.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,8 @@ impl WindowBuilder for WindowBuilderWrapper {
741741
.maximized(config.maximized)
742742
.always_on_top(config.always_on_top)
743743
.skip_taskbar(config.skip_taskbar)
744-
.theme(config.theme);
744+
.theme(config.theme)
745+
.shadow(config.shadow);
745746

746747
if let (Some(min_width), Some(min_height)) = (config.min_width, config.min_height) {
747748
window = window.min_inner_size(min_width, min_height);
@@ -849,6 +850,18 @@ impl WindowBuilder for WindowBuilderWrapper {
849850
self
850851
}
851852

853+
fn shadow(#[allow(unused_mut)] mut self, _enable: bool) -> Self {
854+
#[cfg(windows)]
855+
{
856+
self.inner = self.inner.with_undecorated_shadow(_enable);
857+
}
858+
#[cfg(target_os = "macos")]
859+
{
860+
self.inner = self.inner.with_has_shadow(_enable);
861+
}
862+
self
863+
}
864+
852865
#[cfg(windows)]
853866
fn parent_window(mut self, parent: HWND) -> Self {
854867
self.inner = self.inner.with_parent_window(parent);
@@ -1066,6 +1079,7 @@ pub enum WindowMessage {
10661079
Hide,
10671080
Close,
10681081
SetDecorations(bool),
1082+
SetShadow(bool),
10691083
SetAlwaysOnTop(bool),
10701084
SetSize(Size),
10711085
SetMinSize(Option<Size>),
@@ -1430,6 +1444,13 @@ impl<T: UserEvent> Dispatch<T> for WryDispatcher<T> {
14301444
)
14311445
}
14321446

1447+
fn set_shadow(&self, enable: bool) -> Result<()> {
1448+
send_user_message(
1449+
&self.context,
1450+
Message::Window(self.window_id, WindowMessage::SetShadow(enable)),
1451+
)
1452+
}
1453+
14331454
fn set_always_on_top(&self, always_on_top: bool) -> Result<()> {
14341455
send_user_message(
14351456
&self.context,
@@ -2420,6 +2441,12 @@ fn handle_user_message<T: UserEvent>(
24202441
panic!("cannot handle `WindowMessage::Close` on the main thread")
24212442
}
24222443
WindowMessage::SetDecorations(decorations) => window.set_decorations(decorations),
2444+
WindowMessage::SetShadow(_enable) => {
2445+
#[cfg(windows)]
2446+
window.set_undecorated_shadow(_enable);
2447+
#[cfg(target_os = "macos")]
2448+
window.set_has_shadow(_enable);
2449+
}
24232450
WindowMessage::SetAlwaysOnTop(always_on_top) => window.set_always_on_top(always_on_top),
24242451
WindowMessage::SetSize(size) => {
24252452
window.set_inner_size(SizeWrapper::from(size).0);

core/tauri-runtime/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ raw-window-handle = "0.5"
3434
rand = "0.8"
3535

3636
[target."cfg(windows)".dependencies]
37-
webview2-com = "0.19.1"
37+
webview2-com = "0.22"
3838

39-
[target."cfg(windows)".dependencies.windows]
40-
version = "0.39.0"
41-
features = [ "Win32_Foundation" ]
39+
[target."cfg(windows)".dependencies.windows]
40+
version = "0.44"
41+
features = [ "Win32_Foundation" ]
4242

4343
[target."cfg(any(target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\"))".dependencies]
4444
gtk = { version = "0.16", features = [ "v3_24" ] }

core/tauri-runtime/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,9 +639,12 @@ pub trait Dispatch<T: UserEvent>: Debug + Clone + Send + Sync + Sized + 'static
639639
/// Closes the window.
640640
fn close(&self) -> Result<()>;
641641

642-
/// Updates the hasDecorations flag.
642+
/// Updates the decorations flag.
643643
fn set_decorations(&self, decorations: bool) -> Result<()>;
644644

645+
/// Updates the shadow flag.
646+
fn set_shadow(&self, enable: bool) -> Result<()>;
647+
645648
/// Updates the window alwaysOnTop flag.
646649
fn set_always_on_top(&self, always_on_top: bool) -> Result<()>;
647650

core/tauri-runtime/src/webview.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,18 @@ pub trait WindowBuilder: WindowBuilderBase {
179179
#[must_use]
180180
fn skip_taskbar(self, skip: bool) -> Self;
181181

182+
/// Sets whether or not the window has shadow.
183+
///
184+
/// ## Platform-specific
185+
///
186+
/// - **Windows:**
187+
/// - `false` has no effect on decorated window, shadows are always ON.
188+
/// - `true` will make ndecorated window have a 1px white border,
189+
/// and on Windows 11, it will have a rounded corners.
190+
/// - **Linux:** Unsupported.
191+
#[must_use]
192+
fn shadow(self, enable: bool) -> Self;
193+
182194
/// Sets a parent to the window to be created.
183195
///
184196
/// A child window has the WS_CHILD style and is confined to the client area of its parent window.

core/tauri-utils/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ infer = "0.7"
4141
heck = "0.4"
4242

4343
[target."cfg(windows)".dependencies.windows]
44-
version = "0.39.0"
44+
version = "0.44.0"
4545
features = [
4646
"implement",
4747
"Win32_Foundation",

0 commit comments

Comments
 (0)