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): add tabbing identifier APIs #592

Merged
merged 2 commits into from
Oct 18, 2022
Merged
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/tabbing-identifier.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tao": minor
---

Added tabbing identifier APIs on macOS.
33 changes: 33 additions & 0 deletions src/platform/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ pub trait WindowExtMacOS {

/// Returns whether the system can automatically organize windows into tabs.
fn allows_automatic_window_tabbing(&self) -> bool;

/// Group windows together by using the same tabbing identifier.
///
/// <https://developer.apple.com/documentation/appkit/nswindow/1644704-tabbingidentifier>
fn set_tabbing_identifier(&self, identifier: &str);

/// Returns the window's tabbing identifier.
fn tabbing_identifier(&self) -> String;
}

impl WindowExtMacOS for Window {
Expand Down Expand Up @@ -123,6 +131,16 @@ impl WindowExtMacOS for Window {
fn allows_automatic_window_tabbing(&self) -> bool {
self.window.allows_automatic_window_tabbing()
}

#[inline]
fn set_tabbing_identifier(&self, identifier: &str) {
self.window.set_tabbing_identifier(identifier)
}

#[inline]
fn tabbing_identifier(&self) -> String {
self.window.tabbing_identifier()
}
}

/// Corresponds to `NSApplicationActivationPolicy`.
Expand Down Expand Up @@ -374,8 +392,14 @@ pub trait WindowBuilderExtMacOS {
/// Build window with `resizeIncrements` property. Values must not be 0.
fn with_resize_increments(self, increments: LogicalSize<f64>) -> WindowBuilder;
fn with_disallow_hidpi(self, disallow_hidpi: bool) -> WindowBuilder;
/// Sets whether or not the window has shadow.
fn with_has_shadow(self, has_shadow: bool) -> WindowBuilder;
/// Sets whether the system can automatically organize windows into tabs.
fn with_automatic_window_tabbing(self, automatic_tabbing: bool) -> WindowBuilder;
/// Defines the window [tabbing identifier].
///
/// [tabbing identifier]: <https://developer.apple.com/documentation/appkit/nswindow/1644704-tabbingidentifier>
fn with_tabbing_identifier(self, identifier: &str) -> WindowBuilder;
}

impl WindowBuilderExtMacOS for WindowBuilder {
Expand Down Expand Up @@ -447,6 +471,15 @@ impl WindowBuilderExtMacOS for WindowBuilder {
self.platform_specific.automatic_tabbing = automatic_tabbing;
self
}

#[inline]
fn with_tabbing_identifier(mut self, tabbing_identifier: &str) -> WindowBuilder {
self
.platform_specific
.tabbing_identifier
.replace(tabbing_identifier.into());
self
}
}

pub trait EventLoopExtMacOS {
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 @@ -92,6 +92,7 @@ pub struct PlatformSpecificWindowBuilderAttributes {
pub disallow_hidpi: bool,
pub has_shadow: bool,
pub automatic_tabbing: bool,
pub tabbing_identifier: Option<String>,
}

impl Default for PlatformSpecificWindowBuilderAttributes {
Expand All @@ -109,6 +110,7 @@ impl Default for PlatformSpecificWindowBuilderAttributes {
disallow_hidpi: false,
has_shadow: true,
automatic_tabbing: true,
tabbing_identifier: None,
}
}
}
Expand Down Expand Up @@ -278,6 +280,10 @@ fn create_window(
NSWindow::setAllowsAutomaticWindowTabbing_(*ns_window, NO);
}

if let Some(tabbing_identifier) = &pl_attrs.tabbing_identifier {
let _: () = msg_send![*ns_window, setTabbingIdentifier: NSString::alloc(nil).init_str(tabbing_identifier)];
}

if !pl_attrs.has_shadow {
ns_window.setHasShadow_(NO);
}
Expand Down Expand Up @@ -1493,6 +1499,22 @@ impl WindowExtMacOS for UnownedWindow {
allows_tabbing == YES
}
}

#[inline]
fn set_tabbing_identifier(&self, identifier: &str) {
unsafe {
let _: () =
msg_send![*self.ns_window, setTabbingIdentifier: NSString::alloc(nil).init_str(identifier)];
}
}

#[inline]
fn tabbing_identifier(&self) -> String {
unsafe {
let tabbing_identifier = NSWindow::tabbingIdentifier(*self.ns_window);
ns_string_to_rust(tabbing_identifier)
}
}
}

impl Drop for UnownedWindow {
Expand Down