Skip to content

Commit

Permalink
feat(macos): add setters to set title bar style on macOS (#926)
Browse files Browse the repository at this point in the history
* feat(macos): add setters to set title bar style on macOS

* fix: bool to BOOL
  • Loading branch information
pewsheen authored May 15, 2024
1 parent 422f29c commit 7e8f75e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changes/feat-set-title-bar-style.md
Original file line number Diff line number Diff line change
@@ -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.
20 changes: 20 additions & 0 deletions src/platform/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
/// <https://developer.apple.com/documentation/appkit/nsfullsizecontentviewwindowmask>
fn set_fullsize_content_view(&self, fullsize: bool);

/// A Boolean value that indicates whether the title bar draws its background.
///
/// <https://developer.apple.com/documentation/appkit/nswindow/1419167-titlebarappearstransparent>
fn set_titlebar_transparent(&self, transparent: bool);
}

impl WindowExtMacOS for Window {
Expand Down Expand Up @@ -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`.
Expand Down
20 changes: 20 additions & 0 deletions src/platform_impl/macos/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1613,6 +1613,26 @@ 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 as BOOL);
}
}
}

impl Drop for UnownedWindow {
Expand Down

0 comments on commit 7e8f75e

Please sign in to comment.