Skip to content

Commit 4db363a

Browse files
krzykro2amrbashir
andauthored
feat: add visible_on_all_workspaces, closes #6589 (#7437)
* feat: add visible_on_all_workspaces, closes #6589 * add changes file * Apply suggestions from code review * Update core/tauri-config-schema/schema.json * Update tooling/cli/schema.json --------- Co-authored-by: Amr Bashir <amr.bashir2015@gmail.com>
1 parent 3a2c3e7 commit 4db363a

File tree

10 files changed

+82
-1
lines changed

10 files changed

+82
-1
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"tauri": 'minor:feat'
3+
"tauri-runtime": 'minor'
4+
"tauri-utils": 'minor:feat'
5+
---
6+
7+
Added `visible_on_all_workspaces` configuration option to `WindowBuilder`, `Window`, and `WindowConfig`.

core/tauri-config-schema/schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,11 @@
445445
"default": false,
446446
"type": "boolean"
447447
},
448+
"visibleOnAllWorkspaces": {
449+
"description": "Whether the window should be visible on all workspaces or virtual desktops.",
450+
"default": false,
451+
"type": "boolean"
452+
},
448453
"contentProtected": {
449454
"description": "Prevents the window contents from being captured by other apps.",
450455
"default": false,

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,7 @@ impl WindowBuilder for WindowBuilderWrapper {
749749
.decorations(config.decorations)
750750
.maximized(config.maximized)
751751
.always_on_top(config.always_on_top)
752+
.visible_on_all_workspaces(config.visible_on_all_workspaces)
752753
.content_protected(config.content_protected)
753754
.skip_taskbar(config.skip_taskbar)
754755
.theme(config.theme)
@@ -875,6 +876,13 @@ impl WindowBuilder for WindowBuilderWrapper {
875876
self
876877
}
877878

879+
fn visible_on_all_workspaces(mut self, visible_on_all_workspaces: bool) -> Self {
880+
self.inner = self
881+
.inner
882+
.with_visible_on_all_workspaces(visible_on_all_workspaces);
883+
self
884+
}
885+
878886
fn content_protected(mut self, protected: bool) -> Self {
879887
self.inner = self.inner.with_content_protection(protected);
880888
self
@@ -1121,6 +1129,7 @@ pub enum WindowMessage {
11211129
SetDecorations(bool),
11221130
SetShadow(bool),
11231131
SetAlwaysOnTop(bool),
1132+
SetVisibleOnAllWorkspaces(bool),
11241133
SetContentProtected(bool),
11251134
SetSize(Size),
11261135
SetMinSize(Option<Size>),
@@ -1550,6 +1559,16 @@ impl<T: UserEvent> Dispatch<T> for WryDispatcher<T> {
15501559
)
15511560
}
15521561

1562+
fn set_visible_on_all_workspaces(&self, visible_on_all_workspaces: bool) -> Result<()> {
1563+
send_user_message(
1564+
&self.context,
1565+
Message::Window(
1566+
self.window_id,
1567+
WindowMessage::SetVisibleOnAllWorkspaces(visible_on_all_workspaces),
1568+
),
1569+
)
1570+
}
1571+
15531572
fn set_content_protected(&self, protected: bool) -> Result<()> {
15541573
send_user_message(
15551574
&self.context,
@@ -2499,6 +2518,9 @@ fn handle_user_message<T: UserEvent>(
24992518
window.set_has_shadow(_enable);
25002519
}
25012520
WindowMessage::SetAlwaysOnTop(always_on_top) => window.set_always_on_top(always_on_top),
2521+
WindowMessage::SetVisibleOnAllWorkspaces(visible_on_all_workspaces) => {
2522+
window.set_visible_on_all_workspaces(visible_on_all_workspaces)
2523+
}
25022524
WindowMessage::SetContentProtected(protected) => {
25032525
window.set_content_protection(protected)
25042526
}

core/tauri-runtime/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,9 @@ pub trait Dispatch<T: UserEvent>: Debug + Clone + Send + Sync + Sized + 'static
725725
/// Updates the window alwaysOnTop flag.
726726
fn set_always_on_top(&self, always_on_top: bool) -> Result<()>;
727727

728+
/// Updates the window visibleOnAllWorkspaces flag.
729+
fn set_visible_on_all_workspaces(&self, visible_on_all_workspaces: bool) -> Result<()>;
730+
728731
/// Prevents the window contents from being captured by other apps.
729732
fn set_content_protected(&self, protected: bool) -> Result<()>;
730733

core/tauri-runtime/src/webview.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,10 @@ pub trait WindowBuilder: WindowBuilderBase {
248248
#[must_use]
249249
fn always_on_top(self, always_on_top: bool) -> Self;
250250

251+
/// Whether the window should be visible on all workspaces or virtual desktops.
252+
#[must_use]
253+
fn visible_on_all_workspaces(self, visible_on_all_workspaces: bool) -> Self;
254+
251255
/// Prevents the window contents from being captured by other apps.
252256
#[must_use]
253257
fn content_protected(self, protected: bool) -> Self;

core/tauri-utils/src/config.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,9 @@ pub struct WindowConfig {
962962
/// Whether the window should always be on top of other windows.
963963
#[serde(default, alias = "always-on-top")]
964964
pub always_on_top: bool,
965+
/// Whether the window should be visible on all workspaces or virtual desktops.
966+
#[serde(default, alias = "all-workspaces")]
967+
pub visible_on_all_workspaces: bool,
965968
/// Prevents the window contents from being captured by other apps.
966969
#[serde(default, alias = "content-protected")]
967970
pub content_protected: bool,
@@ -1049,6 +1052,7 @@ impl Default for WindowConfig {
10491052
visible: true,
10501053
decorations: true,
10511054
always_on_top: false,
1055+
visible_on_all_workspaces: false,
10521056
content_protected: false,
10531057
skip_taskbar: false,
10541058
theme: None,
@@ -2233,6 +2237,7 @@ mod build {
22332237
let visible = self.visible;
22342238
let decorations = self.decorations;
22352239
let always_on_top = self.always_on_top;
2240+
let visible_on_all_workspaces = self.visible_on_all_workspaces;
22362241
let content_protected = self.content_protected;
22372242
let skip_taskbar = self.skip_taskbar;
22382243
let theme = opt_lit(self.theme.as_ref());
@@ -2273,6 +2278,7 @@ mod build {
22732278
visible,
22742279
decorations,
22752280
always_on_top,
2281+
visible_on_all_workspaces,
22762282
content_protected,
22772283
skip_taskbar,
22782284
theme,

core/tauri/src/test/mock_runtime.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,10 @@ impl WindowBuilder for MockWindowBuilder {
300300
self
301301
}
302302

303+
fn visible_on_all_workspaces(self, visible_on_all_workspaces: bool) -> Self {
304+
self
305+
}
306+
303307
fn content_protected(self, protected: bool) -> Self {
304308
self
305309
}
@@ -622,6 +626,10 @@ impl<T: UserEvent> Dispatch<T> for MockDispatcher {
622626
Ok(())
623627
}
624628

629+
fn set_visible_on_all_workspaces(&self, visible_on_all_workspaces: bool) -> Result<()> {
630+
Ok(())
631+
}
632+
625633
fn set_content_protected(&self, protected: bool) -> Result<()> {
626634
Ok(())
627635
}

core/tauri/src/window.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,15 @@ impl<'a, R: Runtime> WindowBuilder<'a, R> {
528528
self
529529
}
530530

531+
/// Whether the window will be visible on all workspaces or virtual desktops.
532+
#[must_use]
533+
pub fn visible_on_all_workspaces(mut self, visible_on_all_workspaces: bool) -> Self {
534+
self.window_builder = self
535+
.window_builder
536+
.visible_on_all_workspaces(visible_on_all_workspaces);
537+
self
538+
}
539+
531540
/// Prevents the window contents from being captured by other apps.
532541
#[must_use]
533542
pub fn content_protected(mut self, protected: bool) -> Self {
@@ -1479,6 +1488,18 @@ impl<R: Runtime> Window<R> {
14791488
.map_err(Into::into)
14801489
}
14811490

1491+
/// Sets whether the window should be visible on all workspaces or virtual desktops.
1492+
pub fn set_visible_on_all_workspaces(
1493+
&self,
1494+
visible_on_all_workspaces: bool,
1495+
) -> crate::Result<()> {
1496+
self
1497+
.window
1498+
.dispatcher
1499+
.set_visible_on_all_workspaces(visible_on_all_workspaces)
1500+
.map_err(Into::into)
1501+
}
1502+
14821503
/// Prevents the window contents from being captured by other apps.
14831504
pub fn set_content_protected(&self, protected: bool) -> crate::Result<()> {
14841505
self

tooling/api/docs/js-api.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

tooling/cli/schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,11 @@
445445
"default": false,
446446
"type": "boolean"
447447
},
448+
"visibleOnAllWorkspaces": {
449+
"description": "Whether the window should be visible on all workspaces or virtual desktops.",
450+
"default": false,
451+
"type": "boolean"
452+
},
448453
"contentProtected": {
449454
"description": "Prevents the window contents from being captured by other apps.",
450455
"default": false,

0 commit comments

Comments
 (0)