Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(macos): Fix with_titlebar_transparent, add WindowExtMacOS::set_titlebar_transparent #372

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/fix-titlebar-transparent copy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tao": patch
---

Add macOS `WindowExtMacOS::set_titlebar_transparent`
5 changes: 5 additions & 0 deletions .changes/fix-titlebar-transparent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tao": patch
---

Fix macOS `WindowBuilderExtMacOS::with_titlebar_transparent`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it was broken in the first place, because it seems like users needed to just pair it with WindowBuilderExtMacOS::with_fullsize_content_view in wry/tauri apps.

8 changes: 8 additions & 0 deletions src/platform/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ 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;

Expand Down Expand Up @@ -77,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()
Expand Down
22 changes: 22 additions & 0 deletions src/platform_impl/macos/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,13 @@ 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);

Comment on lines +208 to +214
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is WindowBuilderExtMacOS::with_fullsize_content_view for exactly doing this. Users should just use it.

Suggested change
let mut style_mask = ns_window.styleMask();
style_mask.set(
NSWindowStyleMask::NSFullSizeContentViewWindowMask,
true,
);
ns_window.setStyleMask_(style_mask);

ns_window.setTitlebarAppearsTransparent_(YES);
}
if pl_attrs.title_hidden {
Expand Down Expand Up @@ -1233,6 +1240,21 @@ impl WindowExtMacOS for UnownedWindow {
.setHasShadow_(if has_shadow { YES } else { NO })
}
}

#[inline]
fn set_titlebar_transparent(&self, transparent: bool) {
unsafe {
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);
Comment on lines +1247 to +1253
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be the responsibility of this method, it should probably be split into another method WindowExtMacOS::set_fullsize_content_view


id.setTitlebarAppearsTransparent_(if transparent { YES } else { NO });
}
}
}

impl Drop for UnownedWindow {
Expand Down