On macOS, add tabbing APIs

This should let the users control macOS tabbing and allow to create
windows in tab.

Co-authored-by: Amr Bashir <amr.bashir2015@gmail.com>
This commit is contained in:
Kirill Chibisov 2023-07-13 06:52:34 +00:00 committed by GitHub
parent b63164645b
commit c5941d105f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 295 additions and 2 deletions

View file

@ -1,4 +1,4 @@
use std::os::raw::c_void;
use std::{num::NonZeroUsize, os::raw::c_void};
use objc2::rc::Id;
@ -38,6 +38,33 @@ pub trait WindowExtMacOS {
/// Sets whether or not the window has shadow.
fn set_has_shadow(&self, has_shadow: bool);
/// Sets whether the system can automatically organize windows into tabs.
///
/// <https://developer.apple.com/documentation/appkit/nswindow/1646657-allowsautomaticwindowtabbing>
fn set_allows_automatic_window_tabbing(&self, enabled: bool);
/// 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;
/// Select next tab.
fn select_next_tab(&self);
/// Select previous tab.
fn select_previous_tab(&self);
/// Select the tab with the given index.
///
/// Will no-op when the index is out of bounds.
fn select_tab_at_index(&self, index: NonZeroUsize);
/// Get the window's edit state.
///
/// # Examples
@ -100,6 +127,41 @@ impl WindowExtMacOS for Window {
self.window.set_has_shadow(has_shadow)
}
#[inline]
fn set_allows_automatic_window_tabbing(&self, enabled: bool) {
self.window.set_allows_automatic_window_tabbing(enabled)
}
#[inline]
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()
}
#[inline]
fn select_next_tab(&self) {
self.window.select_next_tab();
}
#[inline]
fn select_previous_tab(&self) {
self.window.select_previous_tab();
}
#[inline]
fn select_tab_at_index(&self, index: NonZeroUsize) {
self.window.select_tab_at_index(index);
}
#[inline]
fn is_document_edited(&self) -> bool {
self.window.is_document_edited()
@ -161,6 +223,14 @@ pub trait WindowBuilderExtMacOS {
fn with_has_shadow(self, has_shadow: bool) -> WindowBuilder;
/// Window accepts click-through mouse events.
fn with_accepts_first_mouse(self, accepts_first_mouse: bool) -> WindowBuilder;
/// Whether the window could do automatic window tabbing.
///
/// The default is `true`.
fn with_automatic_window_tabbing(self, automatic_tabbing: bool) -> WindowBuilder;
/// Defines the window tabbing identifier.
///
/// <https://developer.apple.com/documentation/appkit/nswindow/1644704-tabbingidentifier>
fn with_tabbing_identifier(self, identifier: &str) -> WindowBuilder;
/// Set how the <kbd>Option</kbd> keys are interpreted.
///
/// See [`WindowExtMacOS::set_option_as_alt`] for details on what this means if set.
@ -225,6 +295,20 @@ impl WindowBuilderExtMacOS for WindowBuilder {
self
}
#[inline]
fn with_automatic_window_tabbing(mut self, automatic_tabbing: bool) -> WindowBuilder {
self.platform_specific.allows_automatic_window_tabbing = automatic_tabbing;
self
}
#[inline]
fn with_tabbing_identifier(mut self, tabbing_identifier: &str) -> WindowBuilder {
self.platform_specific
.tabbing_identifier
.replace(tabbing_identifier.to_string());
self
}
#[inline]
fn with_option_as_alt(mut self, option_as_alt: OptionAsAlt) -> WindowBuilder {
self.platform_specific.option_as_alt = option_as_alt;