Skip to content

Commit 7bc6a2a

Browse files
authored
feat(macos): support changing title bar style dynamically, close #9763 (#9788)
1 parent a7354f9 commit 7bc6a2a

11 files changed

Lines changed: 98 additions & 1 deletion

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'tauri': 'patch:feat'
3+
'@tauri-apps/api': 'patch:feat'
4+
---
5+
6+
Add a new method to set title bar style dynamically on macOS.

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,6 +1155,7 @@ pub enum WindowMessage {
11551155
SetCursorPosition(Position),
11561156
SetIgnoreCursorEvents(bool),
11571157
SetProgressBar(ProgressBarState),
1158+
SetTitleBarStyle(tauri_utils::TitleBarStyle),
11581159
DragWindow,
11591160
ResizeDragWindow(tauri_runtime::ResizeDirection),
11601161
RequestRedraw,
@@ -1948,6 +1949,13 @@ impl<T: UserEvent> WindowDispatch<T> for WryWindowDispatcher<T> {
19481949
),
19491950
)
19501951
}
1952+
1953+
fn set_title_bar_style(&self, style: tauri_utils::TitleBarStyle) -> Result<()> {
1954+
send_user_message(
1955+
&self.context,
1956+
Message::Window(self.window_id, WindowMessage::SetTitleBarStyle(style)),
1957+
)
1958+
}
19511959
}
19521960

19531961
#[derive(Clone)]
@@ -2872,6 +2880,23 @@ fn handle_user_message<T: UserEvent>(
28722880
WindowMessage::SetProgressBar(progress_state) => {
28732881
window.set_progress_bar(ProgressBarStateWrapper::from(progress_state).0);
28742882
}
2883+
WindowMessage::SetTitleBarStyle(_style) => {
2884+
#[cfg(target_os = "macos")]
2885+
match _style {
2886+
TitleBarStyle::Visible => {
2887+
window.set_titlebar_transparent(false);
2888+
window.set_fullsize_content_view(true);
2889+
}
2890+
TitleBarStyle::Transparent => {
2891+
window.set_titlebar_transparent(true);
2892+
window.set_fullsize_content_view(false);
2893+
}
2894+
TitleBarStyle::Overlay => {
2895+
window.set_titlebar_transparent(true);
2896+
window.set_fullsize_content_view(true);
2897+
}
2898+
};
2899+
}
28752900
}
28762901
}
28772902
}

core/tauri-runtime/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,4 +783,11 @@ pub trait WindowDispatch<T: UserEvent>: Debug + Clone + Send + Sync + Sized + 's
783783
/// - **Linux / macOS**: Progress bar is app-wide and not specific to this window. Only supported desktop environments with `libunity` (e.g. GNOME).
784784
/// - **iOS / Android:** Unsupported.
785785
fn set_progress_bar(&self, progress_state: ProgressBarState) -> Result<()>;
786+
787+
/// Sets the title bar style. Available on macOS only.
788+
///
789+
/// ## Platform-specific
790+
///
791+
/// - **Linux / Windows / iOS / Android:** Unsupported.
792+
fn set_title_bar_style(&self, style: tauri_utils::TitleBarStyle) -> Result<()>;
786793
}

core/tauri/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ const PLUGINS: &[(&str, &[(&str, bool)])] = &[
106106
("start_resize_dragging", false),
107107
("set_progress_bar", false),
108108
("set_icon", false),
109+
("set_title_bar_style", false),
109110
("toggle_maximize", false),
110111
// internal
111112
("internal_toggle_maximize", true),

core/tauri/permissions/window/autogenerated/reference.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,6 +1442,32 @@ Denies the set_title command without any pre-configured scope.
14421442
<tr>
14431443
<td>
14441444

1445+
`window:allow-set-title-bar-style`
1446+
1447+
</td>
1448+
<td>
1449+
1450+
Enables the set_title_bar_style command without any pre-configured scope.
1451+
1452+
</td>
1453+
</tr>
1454+
1455+
<tr>
1456+
<td>
1457+
1458+
`window:deny-set-title-bar-style`
1459+
1460+
</td>
1461+
<td>
1462+
1463+
Denies the set_title_bar_style command without any pre-configured scope.
1464+
1465+
</td>
1466+
</tr>
1467+
1468+
<tr>
1469+
<td>
1470+
14451471
`window:allow-set-visible-on-all-workspaces`
14461472

14471473
</td>

core/tauri/scripts/bundle.global.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/tauri/src/test/mock_runtime.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,10 @@ impl<T: UserEvent> WindowDispatch<T> for MockWindowDispatcher {
933933
fn set_progress_bar(&self, progress_state: ProgressBarState) -> Result<()> {
934934
Ok(())
935935
}
936+
937+
fn set_title_bar_style(&self, style: tauri_utils::TitleBarStyle) -> Result<()> {
938+
Ok(())
939+
}
936940
}
937941

938942
#[derive(Debug, Clone)]

core/tauri/src/webview/webview_window.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,6 +1584,11 @@ impl<R: Runtime> WebviewWindow<R> {
15841584
) -> crate::Result<()> {
15851585
self.webview.window().set_progress_bar(progress_state)
15861586
}
1587+
1588+
/// Sets the title bar style. **macOS only**.
1589+
pub fn set_title_bar_style(&self, style: tauri_utils::TitleBarStyle) -> crate::Result<()> {
1590+
self.webview.window().set_title_bar_style(style)
1591+
}
15871592
}
15881593

15891594
/// Desktop webview setters and actions.

core/tauri/src/window/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1995,6 +1995,14 @@ tauri::Builder::default()
19951995
})
19961996
.map_err(Into::into)
19971997
}
1998+
/// Sets the title bar style. **macOS only**.
1999+
pub fn set_title_bar_style(&self, style: tauri_utils::TitleBarStyle) -> crate::Result<()> {
2000+
self
2001+
.window
2002+
.dispatcher
2003+
.set_title_bar_style(style)
2004+
.map_err(Into::into)
2005+
}
19982006
}
19992007

20002008
/// Progress bar state.

core/tauri/src/window/plugin.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use crate::{
1212
#[cfg(desktop)]
1313
mod desktop_commands {
1414
use tauri_runtime::ResizeDirection;
15+
use tauri_utils::TitleBarStyle;
1516

1617
use super::*;
1718
use crate::{
@@ -130,6 +131,7 @@ mod desktop_commands {
130131
setter!(start_resize_dragging, ResizeDirection);
131132
setter!(set_progress_bar, ProgressBarState);
132133
setter!(set_visible_on_all_workspaces, bool);
134+
setter!(set_title_bar_style, TitleBarStyle);
133135

134136
#[command(root = "crate")]
135137
pub async fn set_icon<R: Runtime>(
@@ -276,6 +278,7 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
276278
desktop_commands::set_progress_bar,
277279
desktop_commands::set_icon,
278280
desktop_commands::set_visible_on_all_workspaces,
281+
desktop_commands::set_title_bar_style,
279282
desktop_commands::toggle_maximize,
280283
desktop_commands::internal_toggle_maximize,
281284
]);

0 commit comments

Comments
 (0)