From eec4c0a8e7f9c08db5c589f4569167506db2bbbf Mon Sep 17 00:00:00 2001 From: Kasper Date: Fri, 22 Apr 2022 02:21:04 +0200 Subject: [PATCH 1/7] Add `titlebar_style_hidden` stuff --- examples/resizable.rs | 2 ++ src/platform/macos.rs | 16 ++++++++++ src/platform_impl/macos/window.rs | 50 +++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) diff --git a/examples/resizable.rs b/examples/resizable.rs index 3696e8d6c..aee301281 100644 --- a/examples/resizable.rs +++ b/examples/resizable.rs @@ -1,6 +1,7 @@ // Copyright 2019-2021 Tauri Programme within The Commons Conservancy // SPDX-License-Identifier: Apache-2.0 +use tao::platform::macos::WindowBuilderExtMacOS; use tao::{ dpi::LogicalSize, event::{ElementState, Event, KeyEvent, WindowEvent}, @@ -19,6 +20,7 @@ fn main() { let window = WindowBuilder::new() .with_title("Hit space to toggle resizability.") .with_inner_size(LogicalSize::new(400.0, 200.0)) + .with_titlebar_style_hidden(true) .with_resizable(resizable) .build(&event_loop) .unwrap(); diff --git a/src/platform/macos.rs b/src/platform/macos.rs index 77d756d13..ba5fd7357 100644 --- a/src/platform/macos.rs +++ b/src/platform/macos.rs @@ -54,6 +54,9 @@ pub trait WindowExtMacOS { /// Sets whether or not the window has shadow. fn set_has_shadow(&self, has_shadow: bool); + + /// Hides the window titlebar, but not the traffic light buttons. + fn set_titlebar_style_hidden(&self, transparent: bool); } impl WindowExtMacOS for Window { @@ -86,6 +89,11 @@ impl WindowExtMacOS for Window { fn set_has_shadow(&self, has_shadow: bool) { self.window.set_has_shadow(has_shadow) } + + #[inline] + fn set_titlebar_style_hidden(&self, transparent: bool) { + self.window.set_titlebar_style_hidden(transparent) + } } /// Corresponds to `NSApplicationActivationPolicy`. @@ -330,6 +338,8 @@ pub trait WindowBuilderExtMacOS { fn with_title_hidden(self, title_hidden: bool) -> WindowBuilder; /// Hides the window titlebar. fn with_titlebar_hidden(self, titlebar_hidden: bool) -> WindowBuilder; + /// Hides the window titlebar, but not the traffic light buttons. + fn with_titlebar_style_hidden(self, titlebar_hidden: bool) -> WindowBuilder; /// Hides the window titlebar buttons. fn with_titlebar_buttons_hidden(self, titlebar_buttons_hidden: bool) -> WindowBuilder; /// Makes the window content appear behind the titlebar. @@ -368,6 +378,12 @@ impl WindowBuilderExtMacOS for WindowBuilder { self } + #[inline] + fn with_titlebar_style_hidden(mut self, titlebar_hidden: bool) -> WindowBuilder { + self.platform_specific.titlebar_style_hidden = titlebar_hidden; + self + } + #[inline] fn with_titlebar_buttons_hidden(mut self, titlebar_buttons_hidden: bool) -> WindowBuilder { self.platform_specific.titlebar_buttons_hidden = titlebar_buttons_hidden; diff --git a/src/platform_impl/macos/window.rs b/src/platform_impl/macos/window.rs index c9f3c0c97..f106b08d7 100644 --- a/src/platform_impl/macos/window.rs +++ b/src/platform_impl/macos/window.rs @@ -78,6 +78,7 @@ pub struct PlatformSpecificWindowBuilderAttributes { pub titlebar_transparent: bool, pub title_hidden: bool, pub titlebar_hidden: bool, + pub titlebar_style_hidden: bool, pub titlebar_buttons_hidden: bool, pub fullsize_content_view: bool, pub resize_increments: Option>, @@ -94,6 +95,7 @@ impl Default for PlatformSpecificWindowBuilderAttributes { titlebar_transparent: false, title_hidden: false, titlebar_hidden: false, + titlebar_style_hidden: false, titlebar_buttons_hidden: false, fullsize_content_view: false, resize_increments: None, @@ -247,6 +249,29 @@ fn create_window( if !pl_attrs.has_shadow { ns_window.setHasShadow_(NO); } + + // titlebar_style_hidden + { + use cocoa::appkit::NSWindowTitleVisibility; + let mut style_mask = ns_window.styleMask(); + style_mask.set( + NSWindowStyleMask::NSFullSizeContentViewWindowMask, + pl_attrs.titlebar_style_hidden, + ); + ns_window.setStyleMask_(style_mask); + + ns_window.setTitleVisibility_(if pl_attrs.titlebar_style_hidden { + NSWindowTitleVisibility::NSWindowTitleHidden + } else { + NSWindowTitleVisibility::NSWindowTitleVisible + }); + ns_window.setTitlebarAppearsTransparent_(if pl_attrs.titlebar_style_hidden { + cocoa::base::YES + } else { + cocoa::base::NO + }); + } + if attrs.position.is_none() { ns_window.center(); } @@ -1233,6 +1258,31 @@ impl WindowExtMacOS for UnownedWindow { .setHasShadow_(if has_shadow { YES } else { NO }) } } + + #[inline] + fn set_titlebar_style_hidden(&self, transparent: bool) { + unsafe { + use cocoa::appkit::NSWindowTitleVisibility; + let id = self.ns_window() as cocoa::base::id; + let mut style_mask = id.styleMask(); + style_mask.set( + NSWindowStyleMask::NSFullSizeContentViewWindowMask, + transparent, + ); + self.ns_window.setStyleMask_(style_mask); + + id.setTitleVisibility_(if transparent { + NSWindowTitleVisibility::NSWindowTitleHidden + } else { + NSWindowTitleVisibility::NSWindowTitleVisible + }); + id.setTitlebarAppearsTransparent_(if transparent { + cocoa::base::YES + } else { + cocoa::base::NO + }); + } + } } impl Drop for UnownedWindow { From 05f3684deda5435efca8ad4947c1484e94f07e61 Mon Sep 17 00:00:00 2001 From: Kasper Date: Fri, 22 Apr 2022 04:38:25 +0200 Subject: [PATCH 2/7] Revert resizable example --- examples/resizable.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/examples/resizable.rs b/examples/resizable.rs index aee301281..3696e8d6c 100644 --- a/examples/resizable.rs +++ b/examples/resizable.rs @@ -1,7 +1,6 @@ // Copyright 2019-2021 Tauri Programme within The Commons Conservancy // SPDX-License-Identifier: Apache-2.0 -use tao::platform::macos::WindowBuilderExtMacOS; use tao::{ dpi::LogicalSize, event::{ElementState, Event, KeyEvent, WindowEvent}, @@ -20,7 +19,6 @@ fn main() { let window = WindowBuilder::new() .with_title("Hit space to toggle resizability.") .with_inner_size(LogicalSize::new(400.0, 200.0)) - .with_titlebar_style_hidden(true) .with_resizable(resizable) .build(&event_loop) .unwrap(); From 1cad1206da26063cce9a4a7a5912429f4f6e3c65 Mon Sep 17 00:00:00 2001 From: Kasper Date: Mon, 25 Apr 2022 11:28:49 +0200 Subject: [PATCH 3/7] Use `with_titlebar_transparent` instead --- src/platform/macos.rs | 8 ------ src/platform_impl/macos/window.rs | 41 ++++++++----------------------- 2 files changed, 10 insertions(+), 39 deletions(-) diff --git a/src/platform/macos.rs b/src/platform/macos.rs index ba5fd7357..4b54ab0b2 100644 --- a/src/platform/macos.rs +++ b/src/platform/macos.rs @@ -338,8 +338,6 @@ pub trait WindowBuilderExtMacOS { fn with_title_hidden(self, title_hidden: bool) -> WindowBuilder; /// Hides the window titlebar. fn with_titlebar_hidden(self, titlebar_hidden: bool) -> WindowBuilder; - /// Hides the window titlebar, but not the traffic light buttons. - fn with_titlebar_style_hidden(self, titlebar_hidden: bool) -> WindowBuilder; /// Hides the window titlebar buttons. fn with_titlebar_buttons_hidden(self, titlebar_buttons_hidden: bool) -> WindowBuilder; /// Makes the window content appear behind the titlebar. @@ -378,12 +376,6 @@ impl WindowBuilderExtMacOS for WindowBuilder { self } - #[inline] - fn with_titlebar_style_hidden(mut self, titlebar_hidden: bool) -> WindowBuilder { - self.platform_specific.titlebar_style_hidden = titlebar_hidden; - self - } - #[inline] fn with_titlebar_buttons_hidden(mut self, titlebar_buttons_hidden: bool) -> WindowBuilder { self.platform_specific.titlebar_buttons_hidden = titlebar_buttons_hidden; diff --git a/src/platform_impl/macos/window.rs b/src/platform_impl/macos/window.rs index f106b08d7..5cd6a6309 100644 --- a/src/platform_impl/macos/window.rs +++ b/src/platform_impl/macos/window.rs @@ -36,7 +36,7 @@ use cocoa::{ appkit::{ self, CGFloat, NSApp, NSApplication, NSApplicationPresentationOptions, NSColor, NSRequestUserAttentionType, NSScreen, NSView, NSWindow, NSWindowButton, NSWindowOrderingMode, - NSWindowStyleMask, + NSWindowStyleMask, NSWindowTitleVisibility, }, base::{id, nil}, foundation::{NSAutoreleasePool, NSDictionary, NSPoint, NSRect, NSSize, NSUInteger}, @@ -78,7 +78,6 @@ pub struct PlatformSpecificWindowBuilderAttributes { pub titlebar_transparent: bool, pub title_hidden: bool, pub titlebar_hidden: bool, - pub titlebar_style_hidden: bool, pub titlebar_buttons_hidden: bool, pub fullsize_content_view: bool, pub resize_increments: Option>, @@ -95,7 +94,6 @@ impl Default for PlatformSpecificWindowBuilderAttributes { titlebar_transparent: false, title_hidden: false, titlebar_hidden: false, - titlebar_style_hidden: false, titlebar_buttons_hidden: false, fullsize_content_view: false, resize_increments: None, @@ -207,6 +205,14 @@ fn create_window( ns_window.setAcceptsMouseMovedEvents_(YES); if pl_attrs.titlebar_transparent { + let mut style_mask = ns_window.styleMask(); + style_mask.set( + NSWindowStyleMask::NSFullSizeContentViewWindowMask, + true, + ); + ns_window.setStyleMask_(style_mask); + + ns_window.setTitleVisibility_(NSWindowTitleVisibility::NSWindowTitleHidden); ns_window.setTitlebarAppearsTransparent_(YES); } if pl_attrs.title_hidden { @@ -250,28 +256,6 @@ fn create_window( ns_window.setHasShadow_(NO); } - // titlebar_style_hidden - { - use cocoa::appkit::NSWindowTitleVisibility; - let mut style_mask = ns_window.styleMask(); - style_mask.set( - NSWindowStyleMask::NSFullSizeContentViewWindowMask, - pl_attrs.titlebar_style_hidden, - ); - ns_window.setStyleMask_(style_mask); - - ns_window.setTitleVisibility_(if pl_attrs.titlebar_style_hidden { - NSWindowTitleVisibility::NSWindowTitleHidden - } else { - NSWindowTitleVisibility::NSWindowTitleVisible - }); - ns_window.setTitlebarAppearsTransparent_(if pl_attrs.titlebar_style_hidden { - cocoa::base::YES - } else { - cocoa::base::NO - }); - } - if attrs.position.is_none() { ns_window.center(); } @@ -1262,7 +1246,6 @@ impl WindowExtMacOS for UnownedWindow { #[inline] fn set_titlebar_style_hidden(&self, transparent: bool) { unsafe { - use cocoa::appkit::NSWindowTitleVisibility; let id = self.ns_window() as cocoa::base::id; let mut style_mask = id.styleMask(); style_mask.set( @@ -1276,11 +1259,7 @@ impl WindowExtMacOS for UnownedWindow { } else { NSWindowTitleVisibility::NSWindowTitleVisible }); - id.setTitlebarAppearsTransparent_(if transparent { - cocoa::base::YES - } else { - cocoa::base::NO - }); + id.setTitlebarAppearsTransparent_(if transparent { YES } else { NO }); } } } From afa40fa6282bc2f722d527dbbfe388e95a2cfcc2 Mon Sep 17 00:00:00 2001 From: Kasper Date: Mon, 25 Apr 2022 11:34:21 +0200 Subject: [PATCH 4/7] Don't hide the title --- src/platform/macos.rs | 8 ++++---- src/platform_impl/macos/window.rs | 8 +------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/platform/macos.rs b/src/platform/macos.rs index 4b54ab0b2..5c6e2e614 100644 --- a/src/platform/macos.rs +++ b/src/platform/macos.rs @@ -55,8 +55,8 @@ pub trait WindowExtMacOS { /// Sets whether or not the window has shadow. fn set_has_shadow(&self, has_shadow: bool); - /// Hides the window titlebar, but not the traffic light buttons. - fn set_titlebar_style_hidden(&self, transparent: bool); + /// Makes the titlebar transparent and allows the content to appear behind it. + fn set_titlebar_transparent(&self, transparent: bool); } impl WindowExtMacOS for Window { @@ -91,8 +91,8 @@ impl WindowExtMacOS for Window { } #[inline] - fn set_titlebar_style_hidden(&self, transparent: bool) { - self.window.set_titlebar_style_hidden(transparent) + fn set_titlebar_transparent(&self, transparent: bool) { + self.window.set_titlebar_transparent(transparent) } } diff --git a/src/platform_impl/macos/window.rs b/src/platform_impl/macos/window.rs index 5cd6a6309..2f5e60355 100644 --- a/src/platform_impl/macos/window.rs +++ b/src/platform_impl/macos/window.rs @@ -212,7 +212,6 @@ fn create_window( ); ns_window.setStyleMask_(style_mask); - ns_window.setTitleVisibility_(NSWindowTitleVisibility::NSWindowTitleHidden); ns_window.setTitlebarAppearsTransparent_(YES); } if pl_attrs.title_hidden { @@ -1244,7 +1243,7 @@ impl WindowExtMacOS for UnownedWindow { } #[inline] - fn set_titlebar_style_hidden(&self, transparent: bool) { + fn set_titlebar_transparent(&self, transparent: bool) { unsafe { let id = self.ns_window() as cocoa::base::id; let mut style_mask = id.styleMask(); @@ -1254,11 +1253,6 @@ impl WindowExtMacOS for UnownedWindow { ); self.ns_window.setStyleMask_(style_mask); - id.setTitleVisibility_(if transparent { - NSWindowTitleVisibility::NSWindowTitleHidden - } else { - NSWindowTitleVisibility::NSWindowTitleVisible - }); id.setTitlebarAppearsTransparent_(if transparent { YES } else { NO }); } } From 8293685c9b771bf2d1dc7aa1e8cb4c64b41ac7f5 Mon Sep 17 00:00:00 2001 From: Kasper Date: Mon, 25 Apr 2022 11:46:44 +0200 Subject: [PATCH 5/7] Change files --- .changes/fix-titlebar-transparent copy.md | 5 +++++ .changes/fix-titlebar-transparent.md | 5 +++++ examples/resizable.rs | 4 ++++ 3 files changed, 14 insertions(+) create mode 100644 .changes/fix-titlebar-transparent copy.md create mode 100644 .changes/fix-titlebar-transparent.md diff --git a/.changes/fix-titlebar-transparent copy.md b/.changes/fix-titlebar-transparent copy.md new file mode 100644 index 000000000..9de696dda --- /dev/null +++ b/.changes/fix-titlebar-transparent copy.md @@ -0,0 +1,5 @@ +--- +"tao": patch +--- + +Add macOS `WindowExtMacOS::set_titlebar_transparent` diff --git a/.changes/fix-titlebar-transparent.md b/.changes/fix-titlebar-transparent.md new file mode 100644 index 000000000..2a09e18f4 --- /dev/null +++ b/.changes/fix-titlebar-transparent.md @@ -0,0 +1,5 @@ +--- +"tao": patch +--- + +Fix macOS `WindowBuilderExtMacOS::with_titlebar_transparent` diff --git a/examples/resizable.rs b/examples/resizable.rs index 3696e8d6c..56b3ed13a 100644 --- a/examples/resizable.rs +++ b/examples/resizable.rs @@ -1,6 +1,7 @@ // Copyright 2019-2021 Tauri Programme within The Commons Conservancy // SPDX-License-Identifier: Apache-2.0 +use tao::platform::macos::{WindowBuilderExtMacOS, WindowExtMacOS}; use tao::{ dpi::LogicalSize, event::{ElementState, Event, KeyEvent, WindowEvent}, @@ -19,6 +20,8 @@ fn main() { let window = WindowBuilder::new() .with_title("Hit space to toggle resizability.") .with_inner_size(LogicalSize::new(400.0, 200.0)) + // .with_titlebar_hidden(true) + .with_titlebar_transparent(true) .with_resizable(resizable) .build(&event_loop) .unwrap(); @@ -40,6 +43,7 @@ fn main() { } => { resizable = !resizable; println!("Resizable: {}", resizable); + window.set_titlebar_transparent(resizable); window.set_resizable(resizable); } _ => (), From 633cae24aafa8d26abe14bc72e5e71b7bc6c9bac Mon Sep 17 00:00:00 2001 From: Kasper Date: Mon, 25 Apr 2022 11:51:04 +0200 Subject: [PATCH 6/7] Reorder --- src/platform/macos.rs | 16 ++++++++-------- src/platform_impl/macos/window.rs | 3 +-- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/platform/macos.rs b/src/platform/macos.rs index 5c6e2e614..9360e768e 100644 --- a/src/platform/macos.rs +++ b/src/platform/macos.rs @@ -49,14 +49,14 @@ pub trait WindowExtMacOS { /// space or taking control over the entire monitor. fn set_simple_fullscreen(&self, fullscreen: bool) -> bool; + /// Makes the titlebar transparent and allows the content to appear behind it. + fn set_titlebar_transparent(&self, transparent: bool); + /// Returns whether or not the window has shadow. fn has_shadow(&self) -> bool; /// Sets whether or not the window has shadow. fn set_has_shadow(&self, has_shadow: bool); - - /// Makes the titlebar transparent and allows the content to appear behind it. - fn set_titlebar_transparent(&self, transparent: bool); } impl WindowExtMacOS for Window { @@ -80,6 +80,11 @@ impl WindowExtMacOS for Window { self.window.set_simple_fullscreen(fullscreen) } + #[inline] + fn set_titlebar_transparent(&self, transparent: bool) { + self.window.set_titlebar_transparent(transparent) + } + #[inline] fn has_shadow(&self) -> bool { self.window.has_shadow() @@ -89,11 +94,6 @@ impl WindowExtMacOS for Window { fn set_has_shadow(&self, has_shadow: bool) { self.window.set_has_shadow(has_shadow) } - - #[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 2f5e60355..7c0984a18 100644 --- a/src/platform_impl/macos/window.rs +++ b/src/platform_impl/macos/window.rs @@ -36,7 +36,7 @@ use cocoa::{ appkit::{ self, CGFloat, NSApp, NSApplication, NSApplicationPresentationOptions, NSColor, NSRequestUserAttentionType, NSScreen, NSView, NSWindow, NSWindowButton, NSWindowOrderingMode, - NSWindowStyleMask, NSWindowTitleVisibility, + NSWindowStyleMask, }, base::{id, nil}, foundation::{NSAutoreleasePool, NSDictionary, NSPoint, NSRect, NSSize, NSUInteger}, @@ -254,7 +254,6 @@ fn create_window( if !pl_attrs.has_shadow { ns_window.setHasShadow_(NO); } - if attrs.position.is_none() { ns_window.center(); } From 48c832cd5dd3dddea08e1dec6a366eb968ec1dd0 Mon Sep 17 00:00:00 2001 From: Kasper Date: Mon, 25 Apr 2022 11:51:55 +0200 Subject: [PATCH 7/7] Revert example --- examples/resizable.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/examples/resizable.rs b/examples/resizable.rs index 56b3ed13a..3696e8d6c 100644 --- a/examples/resizable.rs +++ b/examples/resizable.rs @@ -1,7 +1,6 @@ // Copyright 2019-2021 Tauri Programme within The Commons Conservancy // SPDX-License-Identifier: Apache-2.0 -use tao::platform::macos::{WindowBuilderExtMacOS, WindowExtMacOS}; use tao::{ dpi::LogicalSize, event::{ElementState, Event, KeyEvent, WindowEvent}, @@ -20,8 +19,6 @@ fn main() { let window = WindowBuilder::new() .with_title("Hit space to toggle resizability.") .with_inner_size(LogicalSize::new(400.0, 200.0)) - // .with_titlebar_hidden(true) - .with_titlebar_transparent(true) .with_resizable(resizable) .build(&event_loop) .unwrap(); @@ -43,7 +40,6 @@ fn main() { } => { resizable = !resizable; println!("Resizable: {}", resizable); - window.set_titlebar_transparent(resizable); window.set_resizable(resizable); } _ => (),