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>
This commit is contained in:
Kris Krolak 2023-07-26 13:38:09 +02:00 committed by GitHub
parent 3a2c3e7471
commit 4db363a03c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 82 additions and 1 deletions

View File

@ -0,0 +1,7 @@
---
"tauri": 'minor:feat'
"tauri-runtime": 'minor'
"tauri-utils": 'minor:feat'
---
Added `visible_on_all_workspaces` configuration option to `WindowBuilder`, `Window`, and `WindowConfig`.

View File

@ -445,6 +445,11 @@
"default": false, "default": false,
"type": "boolean" "type": "boolean"
}, },
"visibleOnAllWorkspaces": {
"description": "Whether the window should be visible on all workspaces or virtual desktops.",
"default": false,
"type": "boolean"
},
"contentProtected": { "contentProtected": {
"description": "Prevents the window contents from being captured by other apps.", "description": "Prevents the window contents from being captured by other apps.",
"default": false, "default": false,

View File

@ -749,6 +749,7 @@ impl WindowBuilder for WindowBuilderWrapper {
.decorations(config.decorations) .decorations(config.decorations)
.maximized(config.maximized) .maximized(config.maximized)
.always_on_top(config.always_on_top) .always_on_top(config.always_on_top)
.visible_on_all_workspaces(config.visible_on_all_workspaces)
.content_protected(config.content_protected) .content_protected(config.content_protected)
.skip_taskbar(config.skip_taskbar) .skip_taskbar(config.skip_taskbar)
.theme(config.theme) .theme(config.theme)
@ -875,6 +876,13 @@ impl WindowBuilder for WindowBuilderWrapper {
self self
} }
fn visible_on_all_workspaces(mut self, visible_on_all_workspaces: bool) -> Self {
self.inner = self
.inner
.with_visible_on_all_workspaces(visible_on_all_workspaces);
self
}
fn content_protected(mut self, protected: bool) -> Self { fn content_protected(mut self, protected: bool) -> Self {
self.inner = self.inner.with_content_protection(protected); self.inner = self.inner.with_content_protection(protected);
self self
@ -1121,6 +1129,7 @@ pub enum WindowMessage {
SetDecorations(bool), SetDecorations(bool),
SetShadow(bool), SetShadow(bool),
SetAlwaysOnTop(bool), SetAlwaysOnTop(bool),
SetVisibleOnAllWorkspaces(bool),
SetContentProtected(bool), SetContentProtected(bool),
SetSize(Size), SetSize(Size),
SetMinSize(Option<Size>), SetMinSize(Option<Size>),
@ -1550,6 +1559,16 @@ impl<T: UserEvent> Dispatch<T> for WryDispatcher<T> {
) )
} }
fn set_visible_on_all_workspaces(&self, visible_on_all_workspaces: bool) -> Result<()> {
send_user_message(
&self.context,
Message::Window(
self.window_id,
WindowMessage::SetVisibleOnAllWorkspaces(visible_on_all_workspaces),
),
)
}
fn set_content_protected(&self, protected: bool) -> Result<()> { fn set_content_protected(&self, protected: bool) -> Result<()> {
send_user_message( send_user_message(
&self.context, &self.context,
@ -2499,6 +2518,9 @@ fn handle_user_message<T: UserEvent>(
window.set_has_shadow(_enable); window.set_has_shadow(_enable);
} }
WindowMessage::SetAlwaysOnTop(always_on_top) => window.set_always_on_top(always_on_top), WindowMessage::SetAlwaysOnTop(always_on_top) => window.set_always_on_top(always_on_top),
WindowMessage::SetVisibleOnAllWorkspaces(visible_on_all_workspaces) => {
window.set_visible_on_all_workspaces(visible_on_all_workspaces)
}
WindowMessage::SetContentProtected(protected) => { WindowMessage::SetContentProtected(protected) => {
window.set_content_protection(protected) window.set_content_protection(protected)
} }

View File

@ -725,6 +725,9 @@ pub trait Dispatch<T: UserEvent>: Debug + Clone + Send + Sync + Sized + 'static
/// Updates the window alwaysOnTop flag. /// Updates the window alwaysOnTop flag.
fn set_always_on_top(&self, always_on_top: bool) -> Result<()>; fn set_always_on_top(&self, always_on_top: bool) -> Result<()>;
/// Updates the window visibleOnAllWorkspaces flag.
fn set_visible_on_all_workspaces(&self, visible_on_all_workspaces: bool) -> Result<()>;
/// Prevents the window contents from being captured by other apps. /// Prevents the window contents from being captured by other apps.
fn set_content_protected(&self, protected: bool) -> Result<()>; fn set_content_protected(&self, protected: bool) -> Result<()>;

View File

@ -248,6 +248,10 @@ pub trait WindowBuilder: WindowBuilderBase {
#[must_use] #[must_use]
fn always_on_top(self, always_on_top: bool) -> Self; fn always_on_top(self, always_on_top: bool) -> Self;
/// Whether the window should be visible on all workspaces or virtual desktops.
#[must_use]
fn visible_on_all_workspaces(self, visible_on_all_workspaces: bool) -> Self;
/// Prevents the window contents from being captured by other apps. /// Prevents the window contents from being captured by other apps.
#[must_use] #[must_use]
fn content_protected(self, protected: bool) -> Self; fn content_protected(self, protected: bool) -> Self;

View File

@ -962,6 +962,9 @@ pub struct WindowConfig {
/// Whether the window should always be on top of other windows. /// Whether the window should always be on top of other windows.
#[serde(default, alias = "always-on-top")] #[serde(default, alias = "always-on-top")]
pub always_on_top: bool, pub always_on_top: bool,
/// Whether the window should be visible on all workspaces or virtual desktops.
#[serde(default, alias = "all-workspaces")]
pub visible_on_all_workspaces: bool,
/// Prevents the window contents from being captured by other apps. /// Prevents the window contents from being captured by other apps.
#[serde(default, alias = "content-protected")] #[serde(default, alias = "content-protected")]
pub content_protected: bool, pub content_protected: bool,
@ -1049,6 +1052,7 @@ impl Default for WindowConfig {
visible: true, visible: true,
decorations: true, decorations: true,
always_on_top: false, always_on_top: false,
visible_on_all_workspaces: false,
content_protected: false, content_protected: false,
skip_taskbar: false, skip_taskbar: false,
theme: None, theme: None,
@ -2233,6 +2237,7 @@ mod build {
let visible = self.visible; let visible = self.visible;
let decorations = self.decorations; let decorations = self.decorations;
let always_on_top = self.always_on_top; let always_on_top = self.always_on_top;
let visible_on_all_workspaces = self.visible_on_all_workspaces;
let content_protected = self.content_protected; let content_protected = self.content_protected;
let skip_taskbar = self.skip_taskbar; let skip_taskbar = self.skip_taskbar;
let theme = opt_lit(self.theme.as_ref()); let theme = opt_lit(self.theme.as_ref());
@ -2273,6 +2278,7 @@ mod build {
visible, visible,
decorations, decorations,
always_on_top, always_on_top,
visible_on_all_workspaces,
content_protected, content_protected,
skip_taskbar, skip_taskbar,
theme, theme,

View File

@ -300,6 +300,10 @@ impl WindowBuilder for MockWindowBuilder {
self self
} }
fn visible_on_all_workspaces(self, visible_on_all_workspaces: bool) -> Self {
self
}
fn content_protected(self, protected: bool) -> Self { fn content_protected(self, protected: bool) -> Self {
self self
} }
@ -622,6 +626,10 @@ impl<T: UserEvent> Dispatch<T> for MockDispatcher {
Ok(()) Ok(())
} }
fn set_visible_on_all_workspaces(&self, visible_on_all_workspaces: bool) -> Result<()> {
Ok(())
}
fn set_content_protected(&self, protected: bool) -> Result<()> { fn set_content_protected(&self, protected: bool) -> Result<()> {
Ok(()) Ok(())
} }

View File

@ -528,6 +528,15 @@ impl<'a, R: Runtime> WindowBuilder<'a, R> {
self self
} }
/// Whether the window will be visible on all workspaces or virtual desktops.
#[must_use]
pub fn visible_on_all_workspaces(mut self, visible_on_all_workspaces: bool) -> Self {
self.window_builder = self
.window_builder
.visible_on_all_workspaces(visible_on_all_workspaces);
self
}
/// Prevents the window contents from being captured by other apps. /// Prevents the window contents from being captured by other apps.
#[must_use] #[must_use]
pub fn content_protected(mut self, protected: bool) -> Self { pub fn content_protected(mut self, protected: bool) -> Self {
@ -1479,6 +1488,18 @@ impl<R: Runtime> Window<R> {
.map_err(Into::into) .map_err(Into::into)
} }
/// Sets whether the window should be visible on all workspaces or virtual desktops.
pub fn set_visible_on_all_workspaces(
&self,
visible_on_all_workspaces: bool,
) -> crate::Result<()> {
self
.window
.dispatcher
.set_visible_on_all_workspaces(visible_on_all_workspaces)
.map_err(Into::into)
}
/// Prevents the window contents from being captured by other apps. /// Prevents the window contents from being captured by other apps.
pub fn set_content_protected(&self, protected: bool) -> crate::Result<()> { pub fn set_content_protected(&self, protected: bool) -> crate::Result<()> {
self self

File diff suppressed because one or more lines are too long

View File

@ -445,6 +445,11 @@
"default": false, "default": false,
"type": "boolean" "type": "boolean"
}, },
"visibleOnAllWorkspaces": {
"description": "Whether the window should be visible on all workspaces or virtual desktops.",
"default": false,
"type": "boolean"
},
"contentProtected": { "contentProtected": {
"description": "Prevents the window contents from being captured by other apps.", "description": "Prevents the window contents from being captured by other apps.",
"default": false, "default": false,