Skip to content

Commit

Permalink
feat(api/window): add visible-on-all-workspaces, closes #8652 (#8657)
Browse files Browse the repository at this point in the history
* feat(api/window): add visible-on-all-worksapces, closes #8652

* fix build and generate schema

* Update .changes/api-set-visible-on-all-workspaces.md

* revert permissions

* fix alias

* revert set_icon change

* add missing permission

---------

Co-authored-by: Lucas Fernandes Nogueira <[email protected]>
  • Loading branch information
amrbashir and lucasfernog authored Jan 31, 2024
1 parent e1eb911 commit a2fc3a6
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .changes/api-set-visible-on-all-workspaces.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@tauri-apps/api': 'patch:feat'
'tauri': 'patch:feat'
---

Add `visibleOnAllWorkspaces` option when creating the window in JS and `Window.setVisibleOnAllWorkspaces` method.
2 changes: 1 addition & 1 deletion core/tauri-config-schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@
"type": "boolean"
},
"visibleOnAllWorkspaces": {
"description": "Whether the window should be visible on all workspaces or virtual desktops.",
"description": "Whether the window should be visible on all workspaces or virtual desktops.\n\n## Platform-specific\n\n- **Windows / iOS / Android:** Unsupported.",
"default": false,
"type": "boolean"
},
Expand Down
6 changes: 5 additions & 1 deletion core/tauri-utils/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,11 @@ pub struct WindowConfig {
#[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")]
///
/// ## Platform-specific
///
/// - **Windows / iOS / Android:** Unsupported.
#[serde(default, alias = "visible-on-all-workspaces")]
pub visible_on_all_workspaces: bool,
/// Prevents the window contents from being captured by other apps.
#[serde(default, alias = "content-protected")]
Expand Down
1 change: 1 addition & 0 deletions core/tauri/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const PLUGINS: &[(&str, &[(&str, bool)])] = &[
("set_effects", false),
("set_always_on_top", false),
("set_always_on_bottom", false),
("set_visible_on_all_workspaces", false),
("set_content_protected", false),
("set_size", false),
("set_min_size", false),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2019-2023 Tauri Programme within The Commons Conservancy
# SPDX-License-Identifier: Apache-2.0
# SPDX-License-Identifier: MIT
# Automatically generated - DO NOT EDIT!

"$schema" = "../../../schemas/schema.json"

[[permission]]
identifier = "allow-set-visible-on-all-workspaces"
description = "Enables the set_visible_on_all_workspaces command without any pre-configured scope."
commands.allow = ["set_visible_on_all_workspaces"]

[[permission]]
identifier = "deny-set-visible-on-all-workspaces"
description = "Denies the set_visible_on_all_workspaces command without any pre-configured scope."
commands.deny = ["set_visible_on_all_workspaces"]
14 changes: 14 additions & 0 deletions core/tauri/permissions/window/schemas/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,20 @@
"deny-set-title"
]
},
{
"description": "allow-set-visible-on-all-workspaces -> Enables the set_visible_on_all_workspaces command without any pre-configured scope.",
"type": "string",
"enum": [
"allow-set-visible-on-all-workspaces"
]
},
{
"description": "deny-set-visible-on-all-workspaces -> Denies the set_visible_on_all_workspaces command without any pre-configured scope.",
"type": "string",
"enum": [
"deny-set-visible-on-all-workspaces"
]
},
{
"description": "allow-show -> Enables the show command without any pre-configured scope.",
"type": "string",
Expand Down
2 changes: 1 addition & 1 deletion core/tauri/scripts/bundle.global.js

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions core/tauri/src/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,10 @@ impl<'a, R: Runtime, M: Manager<R>> WindowBuilder<'a, R, M> {
}

/// Whether the window will be visible on all workspaces or virtual desktops.
///
/// ## Platform-specific
///
/// - **Windows / iOS / Android:** Unsupported.
#[must_use]
pub fn visible_on_all_workspaces(mut self, visible_on_all_workspaces: bool) -> Self {
self.window_builder = self
Expand Down Expand Up @@ -1659,6 +1663,10 @@ tauri::Builder::default()
}

/// Sets whether the window should be visible on all workspaces or virtual desktops.
///
/// ## Platform-specific
///
/// - **Windows / iOS / Android:** Unsupported.
pub fn set_visible_on_all_workspaces(
&self,
visible_on_all_workspaces: bool,
Expand Down
2 changes: 2 additions & 0 deletions core/tauri/src/window/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ mod desktop_commands {
setter!(start_dragging);
setter!(start_resize_dragging, ResizeDirection);
setter!(set_progress_bar, ProgressBarState);
setter!(set_visible_on_all_workspaces, bool);

#[command(root = "crate")]
pub async fn set_icon<R: Runtime>(
Expand Down Expand Up @@ -415,6 +416,7 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
desktop_commands::start_resize_dragging,
desktop_commands::set_progress_bar,
desktop_commands::set_icon,
desktop_commands::set_visible_on_all_workspaces,
desktop_commands::toggle_maximize,
desktop_commands::internal_toggle_maximize,
desktop_commands::internal_on_mousemove,
Expand Down
26 changes: 26 additions & 0 deletions tooling/api/src/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1562,6 +1562,22 @@ class Window {
})
}

/**
* Sets whether the window should be visible on all workspaces or virtual desktops.
*
* ## Platform-specific
*
* - **Windows / iOS / Android:** Unsupported.
*
* @since 2.0.0
*/
async setVisibleOnAllWorkspaces(visible: boolean): Promise<void> {
return invoke('plugin:window|set_visible_on_all_workspaces', {
label: this.label,
value: visible
})
}

// Listeners

/**
Expand Down Expand Up @@ -2016,6 +2032,16 @@ interface WindowOptions {
* Whether the window's native close button is enabled or not. Defaults to `true`.
*/
closable?: boolean
/**
* Whether the window should be visible on all workspaces or virtual desktops.
*
* ## Platform-specific
*
* - **Windows / iOS / Android:** Unsupported.
*
* @since 2.0.0
*/
visibleOnAllWorkspaces?: boolean
}

function mapMonitor(m: Monitor | null): Monitor | null {
Expand Down
2 changes: 1 addition & 1 deletion tooling/cli/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@
"type": "boolean"
},
"visibleOnAllWorkspaces": {
"description": "Whether the window should be visible on all workspaces or virtual desktops.",
"description": "Whether the window should be visible on all workspaces or virtual desktops.\n\n## Platform-specific\n\n- **Windows / iOS / Android:** Unsupported.",
"default": false,
"type": "boolean"
},
Expand Down

0 comments on commit a2fc3a6

Please sign in to comment.