Skip to content

Commit

Permalink
feat(macos): add automatic_tabbing option, closes tauri-apps#3912
Browse files Browse the repository at this point in the history
  • Loading branch information
caesar committed Oct 13, 2022
1 parent 4036e15 commit 76bb206
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changes/macos-automatic-tabbing.md
@@ -0,0 +1,6 @@
---
'tauri': minor
"tauri-runtime-wry": minor
---

Add `automatic_tabbing` option for macOS windows.
9 changes: 8 additions & 1 deletion core/tauri-runtime-wry/src/lib.rs
Expand Up @@ -710,7 +710,8 @@ impl WindowBuilder for WindowBuilderWrapper {
{
window = window
.hidden_title(config.hidden_title)
.title_bar_style(config.title_bar_style);
.title_bar_style(config.title_bar_style)
.automatic_tabbing(config.automatic_tabbing);
}

#[cfg(any(not(target_os = "macos"), feature = "macos-private-api"))]
Expand Down Expand Up @@ -878,6 +879,12 @@ impl WindowBuilder for WindowBuilderWrapper {
self
}

#[cfg(target_os = "macos")]
fn automatic_tabbing(mut self, enabled: bool) -> Self {
self.inner = self.inner.with_automatic_window_tabbing(enabled);
self
}

fn icon(mut self, icon: Icon) -> Result<Self> {
self.inner = self
.inner
Expand Down
5 changes: 5 additions & 0 deletions core/tauri-runtime/src/webview.rs
Expand Up @@ -210,6 +210,11 @@ pub trait WindowBuilder: WindowBuilderBase {
#[must_use]
fn hidden_title(self, hidden: bool) -> Self;

/// Sets whether the system can automatically organize windows into tabs.
#[cfg(target_os = "macos")]
#[must_use]
fn automatic_tabbing(self, enabled: bool) -> Self;

/// Forces a theme or uses the system settings if None was provided.
fn theme(self, theme: Option<Theme>) -> Self;

Expand Down
8 changes: 7 additions & 1 deletion core/tauri-utils/src/config.rs
Expand Up @@ -870,6 +870,9 @@ pub struct WindowConfig {
/// If `true`, sets the window title to be hidden on macOS.
#[serde(default, alias = "hidden-title")]
pub hidden_title: bool,
/// Sets whether macOS can automatically organize windows into tabs.
#[serde(default, alias = "automatic-tabbing")]
pub automatic_tabbing: bool,
}

impl Default for WindowConfig {
Expand Down Expand Up @@ -901,6 +904,7 @@ impl Default for WindowConfig {
theme: None,
title_bar_style: Default::default(),
hidden_title: false,
automatic_tabbing: true,
}
}
}
Expand Down Expand Up @@ -3032,6 +3036,7 @@ mod build {
let theme = opt_lit(self.theme.as_ref());
let title_bar_style = &self.title_bar_style;
let hidden_title = self.hidden_title;
let automatic_tabbing = self.automatic_tabbing;

literal_struct!(
tokens,
Expand Down Expand Up @@ -3061,7 +3066,8 @@ mod build {
skip_taskbar,
theme,
title_bar_style,
hidden_title
hidden_title,
automatic_tabbing
);
}
}
Expand Down
5 changes: 5 additions & 0 deletions core/tauri/src/test/mock_runtime.rs
Expand Up @@ -283,6 +283,11 @@ impl WindowBuilder for MockWindowBuilder {
self
}

#[cfg(target_os = "macos")]
fn automatic_tabbing(self, enabled: bool) -> Self {
self
}

fn theme(self, theme: Option<Theme>) -> Self {
self
}
Expand Down
8 changes: 8 additions & 0 deletions core/tauri/src/window.rs
Expand Up @@ -462,6 +462,14 @@ impl<'a, R: Runtime> WindowBuilder<'a, R> {
self
}

/// Sets whether macOS can automatically organize windows into tabs.
#[cfg(target_os = "macos")]
#[must_use]
pub fn automatic_tabbing(mut self, enabled: bool) -> Self {
self.window_builder = self.window_builder.automatic_tabbing(enabled);
self
}

// ------------------------------------------- Webview attributes -------------------------------------------

/// Adds the provided JavaScript to a list of scripts that should be run after the global object has been created,
Expand Down
1 change: 1 addition & 0 deletions examples/multiwindow/main.rs
Expand Up @@ -24,6 +24,7 @@ fn main() {
tauri::WindowUrl::App("index.html".into()),
)
.title("Tauri - Rust")
.automatic_tabbing(false)
.build()?;
Ok(())
})
Expand Down
2 changes: 2 additions & 0 deletions examples/multiwindow/tauri.conf.json
Expand Up @@ -35,12 +35,14 @@
{
"label": "Main",
"title": "Tauri - Main",
"automaticTabbing": false,
"width": 800,
"height": 600
},
{
"label": "Secondary",
"title": "Tauri - Secondary",
"automaticTabbing": false,
"width": 600,
"height": 400
}
Expand Down
4 changes: 4 additions & 0 deletions tooling/api/src/window.ts
Expand Up @@ -2042,6 +2042,10 @@ interface WindowOptions {
* If `true`, sets the window title to be hidden on macOS.
*/
hiddenTitle?: boolean
/**
* Sets whether macOS can automatically organize windows into tabs.
*/
automaticTabbing?: boolean
/**
* The user agent for the webview.
*/
Expand Down
7 changes: 6 additions & 1 deletion tooling/cli/schema.json
Expand Up @@ -670,6 +670,11 @@
"description": "If `true`, sets the window title to be hidden on macOS.",
"default": false,
"type": "boolean"
},
"automaticTabbing": {
"description": "Sets whether macOS can automatically organize windows into tabs.",
"default": true,
"type": "boolean"
}
},
"additionalProperties": false
Expand Down Expand Up @@ -2725,4 +2730,4 @@
"additionalProperties": true
}
}
}
}

0 comments on commit 76bb206

Please sign in to comment.