From 9bdbab753a414c9153df4fc808951b4b93bfe45a Mon Sep 17 00:00:00 2001 From: Jason Tsai Date: Wed, 15 May 2024 17:58:45 +0800 Subject: [PATCH 1/2] feat(macos): add setters to set title bar style on macOS --- .changes/feat-set-title-bar-style.md | 5 +++++ src/platform/macos.rs | 20 ++++++++++++++++++++ src/platform_impl/macos/window.rs | 18 ++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 .changes/feat-set-title-bar-style.md diff --git a/.changes/feat-set-title-bar-style.md b/.changes/feat-set-title-bar-style.md new file mode 100644 index 000000000..b9f5e146d --- /dev/null +++ b/.changes/feat-set-title-bar-style.md @@ -0,0 +1,5 @@ +--- +'tao': patch +--- + +On macOS, add `set_fullsize_content_view` and `set_titlebar_transparent` to `Window` to set the title bar style. diff --git a/src/platform/macos.rs b/src/platform/macos.rs index 568287149..f288895b6 100644 --- a/src/platform/macos.rs +++ b/src/platform/macos.rs @@ -74,6 +74,16 @@ pub trait WindowExtMacOS { /// Returns the window's tabbing identifier. fn tabbing_identifier(&self) -> String; + + /// The content view consumes the full size of the window. + /// + /// + fn set_fullsize_content_view(&self, fullsize: bool); + + /// A Boolean value that indicates whether the title bar draws its background. + /// + /// + fn set_titlebar_transparent(&self, transparent: bool); } impl WindowExtMacOS for Window { @@ -141,6 +151,16 @@ impl WindowExtMacOS for Window { fn tabbing_identifier(&self) -> String { self.window.tabbing_identifier() } + + #[inline] + fn set_fullsize_content_view(&self, fullsize: bool) { + self.window.set_fullsize_content_view(fullsize); + } + + #[inline] + fn set_titlebar_transparent(&self, transparent: bool) { + self.window.set_titlebar_transparent(transparent); + } } /// Corresponds to `NSApplicationActivationPolicy`. diff --git a/src/platform_impl/macos/window.rs b/src/platform_impl/macos/window.rs index 7a5aba1d5..e15fa08e1 100644 --- a/src/platform_impl/macos/window.rs +++ b/src/platform_impl/macos/window.rs @@ -1613,6 +1613,24 @@ impl WindowExtMacOS for UnownedWindow { ns_string_to_rust(tabbing_identifier) } } + + #[inline] + fn set_fullsize_content_view(&self, fullsize: bool) { + let mut mask = unsafe { self.ns_window.styleMask() }; + if fullsize { + mask |= NSWindowStyleMask::NSFullSizeContentViewWindowMask; + } else { + mask &= !NSWindowStyleMask::NSFullSizeContentViewWindowMask; + } + self.set_style_mask_sync(mask); + } + + #[inline] + fn set_titlebar_transparent(&self, transparent: bool) { + unsafe { + self.ns_window.setTitlebarAppearsTransparent_(transparent); + } + } } impl Drop for UnownedWindow { From fed1027ec8d910b5f8c59868cf62f4f32f363abd Mon Sep 17 00:00:00 2001 From: Jason Tsai Date: Wed, 15 May 2024 18:15:25 +0800 Subject: [PATCH 2/2] fix: bool to BOOL --- src/platform_impl/macos/window.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/platform_impl/macos/window.rs b/src/platform_impl/macos/window.rs index e15fa08e1..c59f71808 100644 --- a/src/platform_impl/macos/window.rs +++ b/src/platform_impl/macos/window.rs @@ -1628,7 +1628,9 @@ impl WindowExtMacOS for UnownedWindow { #[inline] fn set_titlebar_transparent(&self, transparent: bool) { unsafe { - self.ns_window.setTitlebarAppearsTransparent_(transparent); + self + .ns_window + .setTitlebarAppearsTransparent_(transparent as BOOL); } } }