Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add visible_on_all_workspaces, closes #6589 #7437

Merged
merged 5 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changes/add-visible-on-all-workspaces.md
Original file line number Diff line number Diff line change
@@ -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`.
5 changes: 5 additions & 0 deletions core/tauri-config-schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,11 @@
"default": false,
"type": "boolean"
},
"visibleOnAllWorkspaces": {
"description": "Whether the window should be visible on all workspaces.",
amrbashir marked this conversation as resolved.
Show resolved Hide resolved
amrbashir marked this conversation as resolved.
Show resolved Hide resolved
"default": false,
"type": "boolean"
},
"contentProtected": {
"description": "Prevents the window contents from being captured by other apps.",
"default": false,
Expand Down
22 changes: 22 additions & 0 deletions core/tauri-runtime-wry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,7 @@ impl WindowBuilder for WindowBuilderWrapper {
.decorations(config.decorations)
.maximized(config.maximized)
.always_on_top(config.always_on_top)
.visible_on_all_workspaces(config.visible_on_all_workspaces)
.content_protected(config.content_protected)
.skip_taskbar(config.skip_taskbar)
.theme(config.theme)
Expand Down Expand Up @@ -875,6 +876,13 @@ impl WindowBuilder for WindowBuilderWrapper {
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 {
self.inner = self.inner.with_content_protection(protected);
self
Expand Down Expand Up @@ -1121,6 +1129,7 @@ pub enum WindowMessage {
SetDecorations(bool),
SetShadow(bool),
SetAlwaysOnTop(bool),
SetVisibleOnAllWorkspaces(bool),
SetContentProtected(bool),
SetSize(Size),
SetMinSize(Option<Size>),
Expand Down Expand Up @@ -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<()> {
send_user_message(
&self.context,
Expand Down Expand Up @@ -2499,6 +2518,9 @@ fn handle_user_message<T: UserEvent>(
window.set_has_shadow(_enable);
}
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) => {
window.set_content_protection(protected)
}
Expand Down
3 changes: 3 additions & 0 deletions core/tauri-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,9 @@ pub trait Dispatch<T: UserEvent>: Debug + Clone + Send + Sync + Sized + 'static
/// Updates the window alwaysOnTop flag.
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.
fn set_content_protected(&self, protected: bool) -> Result<()>;

Expand Down
4 changes: 4 additions & 0 deletions core/tauri-runtime/src/webview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@ pub trait WindowBuilder: WindowBuilderBase {
#[must_use]
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.
#[must_use]
fn content_protected(self, protected: bool) -> Self;
Expand Down
6 changes: 6 additions & 0 deletions core/tauri-utils/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,9 @@ pub struct WindowConfig {
/// Whether the window should always be on top of other windows.
#[serde(default, alias = "always-on-top")]
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.
#[serde(default, alias = "content-protected")]
pub content_protected: bool,
Expand Down Expand Up @@ -1049,6 +1052,7 @@ impl Default for WindowConfig {
visible: true,
decorations: true,
always_on_top: false,
visible_on_all_workspaces: false,
content_protected: false,
skip_taskbar: false,
theme: None,
Expand Down Expand Up @@ -2233,6 +2237,7 @@ mod build {
let visible = self.visible;
let decorations = self.decorations;
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 skip_taskbar = self.skip_taskbar;
let theme = opt_lit(self.theme.as_ref());
Expand Down Expand Up @@ -2273,6 +2278,7 @@ mod build {
visible,
decorations,
always_on_top,
visible_on_all_workspaces,
content_protected,
skip_taskbar,
theme,
Expand Down
8 changes: 8 additions & 0 deletions core/tauri/src/test/mock_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,10 @@ impl WindowBuilder for MockWindowBuilder {
self
}

fn visible_on_all_workspaces(self, visible_on_all_workspaces: bool) -> Self {
self
}

fn content_protected(self, protected: bool) -> Self {
self
}
Expand Down Expand Up @@ -622,6 +626,10 @@ impl<T: UserEvent> Dispatch<T> for MockDispatcher {
Ok(())
}

fn set_visible_on_all_workspaces(&self, visible_on_all_workspaces: bool) -> Result<()> {
Ok(())
}

fn set_content_protected(&self, protected: bool) -> Result<()> {
Ok(())
}
Expand Down
21 changes: 21 additions & 0 deletions core/tauri/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,15 @@ impl<'a, R: Runtime> WindowBuilder<'a, R> {
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.
#[must_use]
pub fn content_protected(mut self, protected: bool) -> Self {
Expand Down Expand Up @@ -1479,6 +1488,18 @@ impl<R: Runtime> Window<R> {
.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.
pub fn set_content_protected(&self, protected: bool) -> crate::Result<()> {
self
Expand Down
2 changes: 1 addition & 1 deletion tooling/api/docs/js-api.json

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions tooling/cli/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,11 @@
"default": false,
"type": "boolean"
},
"visibleOnAllWorkspaces": {
"description": "Whether the window should be visible on all workspaces.",
amrbashir marked this conversation as resolved.
Show resolved Hide resolved
amrbashir marked this conversation as resolved.
Show resolved Hide resolved
"default": false,
"type": "boolean"
},
"contentProtected": {
"description": "Prevents the window contents from being captured by other apps.",
"default": false,
Expand Down
Loading