2023-07-14 08:01:40 +00:00
|
|
|
use std::os::raw::c_void;
|
2019-05-01 17:03:30 -06:00
|
|
|
|
2023-01-31 01:35:49 -08:00
|
|
|
use objc2::rc::Id;
|
|
|
|
|
|
2019-06-21 11:33:15 -04:00
|
|
|
use crate::{
|
2022-02-16 22:09:03 +01:00
|
|
|
event_loop::{EventLoopBuilder, EventLoopWindowTarget},
|
2019-06-21 11:33:15 -04:00
|
|
|
monitor::MonitorHandle,
|
|
|
|
|
window::{Window, WindowBuilder},
|
|
|
|
|
};
|
2016-01-16 15:12:21 -08:00
|
|
|
|
2022-06-11 18:57:19 +02:00
|
|
|
/// Additional methods on [`Window`] that are specific to MacOS.
|
2019-02-05 10:30:33 -05:00
|
|
|
pub trait WindowExtMacOS {
|
2019-04-26 03:09:32 +10:00
|
|
|
/// Returns whether or not the window is in simple fullscreen mode.
|
2019-05-29 21:29:54 -04:00
|
|
|
fn simple_fullscreen(&self) -> bool;
|
2019-04-26 03:09:32 +10:00
|
|
|
|
2018-12-19 15:07:33 +11:00
|
|
|
/// Toggles a fullscreen mode that doesn't require a new macOS space.
|
|
|
|
|
/// Returns a boolean indicating whether the transition was successful (this
|
|
|
|
|
/// won't work if the window was already in the native fullscreen).
|
|
|
|
|
///
|
|
|
|
|
/// This is how fullscreen used to work on macOS in versions before Lion.
|
|
|
|
|
/// And allows the user to have a fullscreen window without using another
|
|
|
|
|
/// space or taking control over the entire monitor.
|
|
|
|
|
fn set_simple_fullscreen(&self, fullscreen: bool) -> bool;
|
2020-08-14 02:10:34 +08:00
|
|
|
|
|
|
|
|
/// 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);
|
2022-11-23 17:07:41 +02:00
|
|
|
|
2023-07-13 06:52:34 +00:00
|
|
|
/// 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.
|
2023-07-14 08:01:40 +00:00
|
|
|
fn select_tab_at_index(&self, index: usize);
|
|
|
|
|
|
|
|
|
|
/// Get the number of tabs in the window tab group.
|
|
|
|
|
fn num_tabs(&self) -> usize;
|
2023-07-13 06:52:34 +00:00
|
|
|
|
2022-11-23 17:07:41 +02:00
|
|
|
/// Get the window's edit state.
|
|
|
|
|
///
|
|
|
|
|
/// # Examples
|
|
|
|
|
///
|
|
|
|
|
/// ```ignore
|
|
|
|
|
/// WindowEvent::CloseRequested => {
|
|
|
|
|
/// if window.is_document_edited() {
|
|
|
|
|
/// // Show the user a save pop-up or similar
|
|
|
|
|
/// } else {
|
|
|
|
|
/// // Close the window
|
|
|
|
|
/// drop(window);
|
|
|
|
|
/// }
|
|
|
|
|
/// }
|
|
|
|
|
/// ```
|
|
|
|
|
fn is_document_edited(&self) -> bool;
|
|
|
|
|
|
|
|
|
|
/// Put the window in a state which indicates a file save is required.
|
|
|
|
|
fn set_document_edited(&self, edited: bool);
|
2023-06-20 19:07:49 +00:00
|
|
|
|
|
|
|
|
/// Set option as alt behavior as described in [`OptionAsAlt`].
|
|
|
|
|
///
|
|
|
|
|
/// This will ignore diacritical marks and accent characters from
|
|
|
|
|
/// being processed as received characters. Instead, the input
|
|
|
|
|
/// device's raw character will be placed in event queues with the
|
|
|
|
|
/// Alt modifier set.
|
|
|
|
|
fn set_option_as_alt(&self, option_as_alt: OptionAsAlt);
|
|
|
|
|
|
|
|
|
|
/// Getter for the [`WindowExtMacOS::set_option_as_alt`].
|
|
|
|
|
fn option_as_alt(&self) -> OptionAsAlt;
|
2016-01-16 15:12:21 -08:00
|
|
|
}
|
2016-04-28 19:30:44 -04:00
|
|
|
|
2019-02-05 10:30:33 -05:00
|
|
|
impl WindowExtMacOS for Window {
|
2019-04-26 03:09:32 +10:00
|
|
|
#[inline]
|
2019-05-29 21:29:54 -04:00
|
|
|
fn simple_fullscreen(&self) -> bool {
|
2023-08-14 21:19:57 +02:00
|
|
|
self.window.maybe_wait_on_main(|w| w.simple_fullscreen())
|
2019-04-26 03:09:32 +10:00
|
|
|
}
|
|
|
|
|
|
2018-12-19 15:07:33 +11:00
|
|
|
#[inline]
|
|
|
|
|
fn set_simple_fullscreen(&self, fullscreen: bool) -> bool {
|
2023-08-14 21:19:57 +02:00
|
|
|
self.window
|
|
|
|
|
.maybe_wait_on_main(move |w| w.set_simple_fullscreen(fullscreen))
|
2018-12-19 15:07:33 +11:00
|
|
|
}
|
2020-08-14 02:10:34 +08:00
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
fn has_shadow(&self) -> bool {
|
2023-08-14 21:19:57 +02:00
|
|
|
self.window.maybe_wait_on_main(|w| w.has_shadow())
|
2020-08-14 02:10:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
fn set_has_shadow(&self, has_shadow: bool) {
|
2023-08-14 21:19:57 +02:00
|
|
|
self.window
|
|
|
|
|
.maybe_queue_on_main(move |w| w.set_has_shadow(has_shadow))
|
2020-08-14 02:10:34 +08:00
|
|
|
}
|
2022-11-23 17:07:41 +02:00
|
|
|
|
2023-07-13 06:52:34 +00:00
|
|
|
#[inline]
|
|
|
|
|
fn set_tabbing_identifier(&self, identifier: &str) {
|
2023-08-14 21:19:57 +02:00
|
|
|
self.window
|
|
|
|
|
.maybe_wait_on_main(|w| w.set_tabbing_identifier(identifier))
|
2023-07-13 06:52:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
fn tabbing_identifier(&self) -> String {
|
2023-08-14 21:19:57 +02:00
|
|
|
self.window.maybe_wait_on_main(|w| w.tabbing_identifier())
|
2023-07-13 06:52:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
fn select_next_tab(&self) {
|
2023-08-14 21:19:57 +02:00
|
|
|
self.window.maybe_queue_on_main(|w| w.select_next_tab())
|
2023-07-13 06:52:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
fn select_previous_tab(&self) {
|
2023-08-14 21:19:57 +02:00
|
|
|
self.window.maybe_queue_on_main(|w| w.select_previous_tab())
|
2023-07-13 06:52:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline]
|
2023-07-14 08:01:40 +00:00
|
|
|
fn select_tab_at_index(&self, index: usize) {
|
2023-08-14 21:19:57 +02:00
|
|
|
self.window
|
|
|
|
|
.maybe_queue_on_main(move |w| w.select_tab_at_index(index))
|
2023-07-13 06:52:34 +00:00
|
|
|
}
|
|
|
|
|
|
2023-07-14 08:01:40 +00:00
|
|
|
#[inline]
|
|
|
|
|
fn num_tabs(&self) -> usize {
|
2023-08-14 21:19:57 +02:00
|
|
|
self.window.maybe_wait_on_main(|w| w.num_tabs())
|
2023-07-14 08:01:40 +00:00
|
|
|
}
|
|
|
|
|
|
2022-11-23 17:07:41 +02:00
|
|
|
#[inline]
|
|
|
|
|
fn is_document_edited(&self) -> bool {
|
2023-08-14 21:19:57 +02:00
|
|
|
self.window.maybe_wait_on_main(|w| w.is_document_edited())
|
2022-11-23 17:07:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
fn set_document_edited(&self, edited: bool) {
|
2023-08-14 21:19:57 +02:00
|
|
|
self.window
|
|
|
|
|
.maybe_queue_on_main(move |w| w.set_document_edited(edited))
|
2022-11-23 17:07:41 +02:00
|
|
|
}
|
2023-06-20 19:07:49 +00:00
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
fn set_option_as_alt(&self, option_as_alt: OptionAsAlt) {
|
2023-08-14 21:19:57 +02:00
|
|
|
self.window
|
|
|
|
|
.maybe_queue_on_main(move |w| w.set_option_as_alt(option_as_alt))
|
2023-06-20 19:07:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
fn option_as_alt(&self) -> OptionAsAlt {
|
2023-08-14 21:19:57 +02:00
|
|
|
self.window.maybe_wait_on_main(|w| w.option_as_alt())
|
2023-06-20 19:07:49 +00:00
|
|
|
}
|
2016-10-08 09:18:00 +02:00
|
|
|
}
|
|
|
|
|
|
2016-04-28 19:30:44 -04:00
|
|
|
/// Corresponds to `NSApplicationActivationPolicy`.
|
2023-03-12 18:02:49 +01:00
|
|
|
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
|
2016-04-28 19:30:44 -04:00
|
|
|
pub enum ActivationPolicy {
|
|
|
|
|
/// Corresponds to `NSApplicationActivationPolicyRegular`.
|
2023-03-12 18:02:49 +01:00
|
|
|
#[default]
|
2016-04-28 19:30:44 -04:00
|
|
|
Regular,
|
2023-03-12 18:02:49 +01:00
|
|
|
|
2016-04-28 19:30:44 -04:00
|
|
|
/// Corresponds to `NSApplicationActivationPolicyAccessory`.
|
|
|
|
|
Accessory,
|
2023-03-12 18:02:49 +01:00
|
|
|
|
2016-04-28 19:30:44 -04:00
|
|
|
/// Corresponds to `NSApplicationActivationPolicyProhibited`.
|
|
|
|
|
Prohibited,
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-11 18:57:19 +02:00
|
|
|
/// Additional methods on [`WindowBuilder`] that are specific to MacOS.
|
2018-03-22 09:57:35 -07:00
|
|
|
///
|
2022-06-11 18:57:19 +02:00
|
|
|
/// **Note:** Properties dealing with the titlebar will be overwritten by the [`WindowBuilder::with_decorations`] method:
|
|
|
|
|
/// - `with_titlebar_transparent`
|
|
|
|
|
/// - `with_title_hidden`
|
|
|
|
|
/// - `with_titlebar_hidden`
|
|
|
|
|
/// - `with_titlebar_buttons_hidden`
|
|
|
|
|
/// - `with_fullsize_content_view`
|
2019-02-05 10:30:33 -05:00
|
|
|
pub trait WindowBuilderExtMacOS {
|
2018-05-16 10:16:36 -04:00
|
|
|
/// Enables click-and-drag behavior for the entire window, not just the titlebar.
|
2023-10-14 19:07:39 -07:00
|
|
|
fn with_movable_by_window_background(self, movable_by_window_background: bool) -> Self;
|
2018-05-16 10:16:36 -04:00
|
|
|
/// Makes the titlebar transparent and allows the content to appear behind it.
|
2023-10-14 19:07:39 -07:00
|
|
|
fn with_titlebar_transparent(self, titlebar_transparent: bool) -> Self;
|
2018-05-16 10:16:36 -04:00
|
|
|
/// Hides the window title.
|
2023-10-14 19:07:39 -07:00
|
|
|
fn with_title_hidden(self, title_hidden: bool) -> Self;
|
2018-05-16 10:16:36 -04:00
|
|
|
/// Hides the window titlebar.
|
2023-10-14 19:07:39 -07:00
|
|
|
fn with_titlebar_hidden(self, titlebar_hidden: bool) -> Self;
|
2018-05-16 10:16:36 -04:00
|
|
|
/// Hides the window titlebar buttons.
|
2023-10-14 19:07:39 -07:00
|
|
|
fn with_titlebar_buttons_hidden(self, titlebar_buttons_hidden: bool) -> Self;
|
2018-05-16 10:16:36 -04:00
|
|
|
/// Makes the window content appear behind the titlebar.
|
2023-10-14 19:07:39 -07:00
|
|
|
fn with_fullsize_content_view(self, fullsize_content_view: bool) -> Self;
|
|
|
|
|
fn with_disallow_hidpi(self, disallow_hidpi: bool) -> Self;
|
|
|
|
|
fn with_has_shadow(self, has_shadow: bool) -> Self;
|
2022-09-13 21:11:18 +02:00
|
|
|
/// Window accepts click-through mouse events.
|
2023-10-14 19:07:39 -07:00
|
|
|
fn with_accepts_first_mouse(self, accepts_first_mouse: bool) -> Self;
|
2023-07-13 06:52:34 +00:00
|
|
|
/// Defines the window tabbing identifier.
|
|
|
|
|
///
|
|
|
|
|
/// <https://developer.apple.com/documentation/appkit/nswindow/1644704-tabbingidentifier>
|
2023-10-14 19:07:39 -07:00
|
|
|
fn with_tabbing_identifier(self, identifier: &str) -> Self;
|
2023-06-20 19:07:49 +00:00
|
|
|
/// Set how the <kbd>Option</kbd> keys are interpreted.
|
|
|
|
|
///
|
|
|
|
|
/// See [`WindowExtMacOS::set_option_as_alt`] for details on what this means if set.
|
2023-10-14 19:07:39 -07:00
|
|
|
fn with_option_as_alt(self, option_as_alt: OptionAsAlt) -> Self;
|
2016-04-28 19:30:44 -04:00
|
|
|
}
|
|
|
|
|
|
2019-02-05 10:30:33 -05:00
|
|
|
impl WindowBuilderExtMacOS for WindowBuilder {
|
2018-01-22 18:07:51 +00:00
|
|
|
#[inline]
|
2023-10-14 19:07:39 -07:00
|
|
|
fn with_movable_by_window_background(mut self, movable_by_window_background: bool) -> Self {
|
2018-01-22 18:07:51 +00:00
|
|
|
self.platform_specific.movable_by_window_background = movable_by_window_background;
|
|
|
|
|
self
|
|
|
|
|
}
|
2018-03-22 09:57:35 -07:00
|
|
|
|
|
|
|
|
#[inline]
|
2023-10-14 19:07:39 -07:00
|
|
|
fn with_titlebar_transparent(mut self, titlebar_transparent: bool) -> Self {
|
2018-03-22 09:57:35 -07:00
|
|
|
self.platform_specific.titlebar_transparent = titlebar_transparent;
|
|
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline]
|
2023-10-14 19:07:39 -07:00
|
|
|
fn with_titlebar_hidden(mut self, titlebar_hidden: bool) -> Self {
|
2018-03-22 09:57:35 -07:00
|
|
|
self.platform_specific.titlebar_hidden = titlebar_hidden;
|
|
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline]
|
2023-10-14 19:07:39 -07:00
|
|
|
fn with_titlebar_buttons_hidden(mut self, titlebar_buttons_hidden: bool) -> Self {
|
2018-03-22 09:57:35 -07:00
|
|
|
self.platform_specific.titlebar_buttons_hidden = titlebar_buttons_hidden;
|
|
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline]
|
2023-10-14 19:07:39 -07:00
|
|
|
fn with_title_hidden(mut self, title_hidden: bool) -> Self {
|
2018-03-22 09:57:35 -07:00
|
|
|
self.platform_specific.title_hidden = title_hidden;
|
|
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline]
|
2023-10-14 19:07:39 -07:00
|
|
|
fn with_fullsize_content_view(mut self, fullsize_content_view: bool) -> Self {
|
2018-03-22 09:57:35 -07:00
|
|
|
self.platform_specific.fullsize_content_view = fullsize_content_view;
|
|
|
|
|
self
|
|
|
|
|
}
|
2018-05-16 10:16:36 -04:00
|
|
|
|
2019-07-29 16:07:36 +08:00
|
|
|
#[inline]
|
2023-10-14 19:07:39 -07:00
|
|
|
fn with_disallow_hidpi(mut self, disallow_hidpi: bool) -> Self {
|
2019-07-29 16:07:36 +08:00
|
|
|
self.platform_specific.disallow_hidpi = disallow_hidpi;
|
|
|
|
|
self
|
|
|
|
|
}
|
2020-08-14 02:10:34 +08:00
|
|
|
|
|
|
|
|
#[inline]
|
2023-10-14 19:07:39 -07:00
|
|
|
fn with_has_shadow(mut self, has_shadow: bool) -> Self {
|
2020-08-14 02:10:34 +08:00
|
|
|
self.platform_specific.has_shadow = has_shadow;
|
|
|
|
|
self
|
|
|
|
|
}
|
2022-09-13 21:11:18 +02:00
|
|
|
|
|
|
|
|
#[inline]
|
2023-10-14 19:07:39 -07:00
|
|
|
fn with_accepts_first_mouse(mut self, accepts_first_mouse: bool) -> Self {
|
2022-09-13 21:11:18 +02:00
|
|
|
self.platform_specific.accepts_first_mouse = accepts_first_mouse;
|
|
|
|
|
self
|
|
|
|
|
}
|
2023-06-20 19:07:49 +00:00
|
|
|
|
2023-07-13 06:52:34 +00:00
|
|
|
#[inline]
|
2023-10-14 19:07:39 -07:00
|
|
|
fn with_tabbing_identifier(mut self, tabbing_identifier: &str) -> Self {
|
2023-07-13 06:52:34 +00:00
|
|
|
self.platform_specific
|
|
|
|
|
.tabbing_identifier
|
|
|
|
|
.replace(tabbing_identifier.to_string());
|
|
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-20 19:07:49 +00:00
|
|
|
#[inline]
|
2023-10-14 19:07:39 -07:00
|
|
|
fn with_option_as_alt(mut self, option_as_alt: OptionAsAlt) -> Self {
|
2023-06-20 19:07:49 +00:00
|
|
|
self.platform_specific.option_as_alt = option_as_alt;
|
|
|
|
|
self
|
|
|
|
|
}
|
2016-04-28 19:30:44 -04:00
|
|
|
}
|
2017-08-30 08:49:18 +02:00
|
|
|
|
2022-02-16 22:09:03 +01:00
|
|
|
pub trait EventLoopBuilderExtMacOS {
|
|
|
|
|
/// Sets the activation policy for the application.
|
2021-04-30 11:31:28 +02:00
|
|
|
///
|
2022-02-16 22:09:03 +01:00
|
|
|
/// It is set to [`ActivationPolicy::Regular`] by default.
|
|
|
|
|
///
|
|
|
|
|
/// # Example
|
|
|
|
|
///
|
|
|
|
|
/// Set the activation policy to "accessory".
|
|
|
|
|
///
|
|
|
|
|
/// ```
|
|
|
|
|
/// use winit::event_loop::EventLoopBuilder;
|
|
|
|
|
/// #[cfg(target_os = "macos")]
|
|
|
|
|
/// use winit::platform::macos::{EventLoopBuilderExtMacOS, ActivationPolicy};
|
|
|
|
|
///
|
|
|
|
|
/// let mut builder = EventLoopBuilder::new();
|
|
|
|
|
/// #[cfg(target_os = "macos")]
|
|
|
|
|
/// builder.with_activation_policy(ActivationPolicy::Accessory);
|
|
|
|
|
/// # if false { // We can't test this part
|
|
|
|
|
/// let event_loop = builder.build();
|
|
|
|
|
/// # }
|
|
|
|
|
/// ```
|
|
|
|
|
fn with_activation_policy(&mut self, activation_policy: ActivationPolicy) -> &mut Self;
|
|
|
|
|
|
|
|
|
|
/// Used to control whether a default menubar menu is created.
|
|
|
|
|
///
|
|
|
|
|
/// Menu creation is enabled by default.
|
2021-04-30 13:34:50 +02:00
|
|
|
///
|
2022-02-16 22:09:03 +01:00
|
|
|
/// # Example
|
2021-04-30 13:34:50 +02:00
|
|
|
///
|
2022-02-16 22:09:03 +01:00
|
|
|
/// Disable creating a default menubar.
|
|
|
|
|
///
|
|
|
|
|
/// ```
|
|
|
|
|
/// use winit::event_loop::EventLoopBuilder;
|
|
|
|
|
/// #[cfg(target_os = "macos")]
|
|
|
|
|
/// use winit::platform::macos::EventLoopBuilderExtMacOS;
|
|
|
|
|
///
|
|
|
|
|
/// let mut builder = EventLoopBuilder::new();
|
|
|
|
|
/// #[cfg(target_os = "macos")]
|
|
|
|
|
/// builder.with_default_menu(false);
|
|
|
|
|
/// # if false { // We can't test this part
|
|
|
|
|
/// let event_loop = builder.build();
|
|
|
|
|
/// # }
|
|
|
|
|
/// ```
|
|
|
|
|
fn with_default_menu(&mut self, enable: bool) -> &mut Self;
|
2022-11-23 14:42:46 +02:00
|
|
|
|
|
|
|
|
/// Used to prevent the application from automatically activating when launched if
|
|
|
|
|
/// another application is already active.
|
|
|
|
|
///
|
|
|
|
|
/// The default behavior is to ignore other applications and activate when launched.
|
|
|
|
|
fn with_activate_ignoring_other_apps(&mut self, ignore: bool) -> &mut Self;
|
2021-04-30 11:31:28 +02:00
|
|
|
}
|
2022-02-16 22:09:03 +01:00
|
|
|
|
|
|
|
|
impl<T> EventLoopBuilderExtMacOS for EventLoopBuilder<T> {
|
2021-04-30 11:31:28 +02:00
|
|
|
#[inline]
|
2022-02-16 22:09:03 +01:00
|
|
|
fn with_activation_policy(&mut self, activation_policy: ActivationPolicy) -> &mut Self {
|
|
|
|
|
self.platform_specific.activation_policy = activation_policy;
|
|
|
|
|
self
|
2021-04-30 11:31:28 +02:00
|
|
|
}
|
2021-04-30 13:34:50 +02:00
|
|
|
|
|
|
|
|
#[inline]
|
2022-02-16 22:09:03 +01:00
|
|
|
fn with_default_menu(&mut self, enable: bool) -> &mut Self {
|
|
|
|
|
self.platform_specific.default_menu = enable;
|
|
|
|
|
self
|
2021-04-30 13:34:50 +02:00
|
|
|
}
|
2022-11-23 14:42:46 +02:00
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
fn with_activate_ignoring_other_apps(&mut self, ignore: bool) -> &mut Self {
|
|
|
|
|
self.platform_specific.activate_ignoring_other_apps = ignore;
|
|
|
|
|
self
|
|
|
|
|
}
|
2021-04-30 11:31:28 +02:00
|
|
|
}
|
|
|
|
|
|
2022-06-11 18:57:19 +02:00
|
|
|
/// Additional methods on [`MonitorHandle`] that are specific to MacOS.
|
2019-02-05 10:30:33 -05:00
|
|
|
pub trait MonitorHandleExtMacOS {
|
2017-08-30 08:49:18 +02:00
|
|
|
/// Returns the identifier of the monitor for Cocoa.
|
|
|
|
|
fn native_id(&self) -> u32;
|
2018-03-06 09:35:04 +01:00
|
|
|
/// Returns a pointer to the NSScreen representing this monitor.
|
2019-06-11 01:09:38 +02:00
|
|
|
fn ns_screen(&self) -> Option<*mut c_void>;
|
2017-08-30 08:49:18 +02:00
|
|
|
}
|
|
|
|
|
|
2019-02-05 10:30:33 -05:00
|
|
|
impl MonitorHandleExtMacOS for MonitorHandle {
|
2017-08-30 08:49:18 +02:00
|
|
|
#[inline]
|
|
|
|
|
fn native_id(&self) -> u32 {
|
2019-05-29 21:29:54 -04:00
|
|
|
self.inner.native_identifier()
|
2017-08-30 08:49:18 +02:00
|
|
|
}
|
2018-03-06 09:35:04 +01:00
|
|
|
|
2019-06-11 01:09:38 +02:00
|
|
|
fn ns_screen(&self) -> Option<*mut c_void> {
|
2022-09-08 16:45:29 +02:00
|
|
|
self.inner.ns_screen().map(|s| Id::as_ptr(&s) as _)
|
2018-03-06 09:35:04 +01:00
|
|
|
}
|
2017-08-30 08:49:18 +02:00
|
|
|
}
|
2020-01-19 18:38:52 -05:00
|
|
|
|
2022-06-11 18:57:19 +02:00
|
|
|
/// Additional methods on [`EventLoopWindowTarget`] that are specific to macOS.
|
2020-01-19 18:38:52 -05:00
|
|
|
pub trait EventLoopWindowTargetExtMacOS {
|
|
|
|
|
/// Hide the entire application. In most applications this is typically triggered with Command-H.
|
|
|
|
|
fn hide_application(&self);
|
2020-05-24 17:26:29 +01:00
|
|
|
/// Hide the other applications. In most applications this is typically triggered with Command+Option-H.
|
|
|
|
|
fn hide_other_applications(&self);
|
2023-07-13 15:55:51 +00:00
|
|
|
/// Set 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;
|
2020-01-19 18:38:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T> EventLoopWindowTargetExtMacOS for EventLoopWindowTarget<T> {
|
|
|
|
|
fn hide_application(&self) {
|
2021-12-01 12:20:56 +01:00
|
|
|
self.p.hide_application()
|
2020-01-19 18:38:52 -05:00
|
|
|
}
|
2020-05-24 17:26:29 +01:00
|
|
|
|
|
|
|
|
fn hide_other_applications(&self) {
|
2021-12-01 12:20:56 +01:00
|
|
|
self.p.hide_other_applications()
|
2020-05-24 17:26:29 +01:00
|
|
|
}
|
2023-07-13 15:55:51 +00:00
|
|
|
|
|
|
|
|
fn set_allows_automatic_window_tabbing(&self, enabled: bool) {
|
|
|
|
|
self.p.set_allows_automatic_window_tabbing(enabled);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn allows_automatic_window_tabbing(&self) -> bool {
|
|
|
|
|
self.p.allows_automatic_window_tabbing()
|
|
|
|
|
}
|
2020-01-19 18:38:52 -05:00
|
|
|
}
|
2023-06-20 19:07:49 +00:00
|
|
|
|
|
|
|
|
/// Option as alt behavior.
|
|
|
|
|
///
|
|
|
|
|
/// The default is `None`.
|
|
|
|
|
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq)]
|
|
|
|
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
|
|
|
|
pub enum OptionAsAlt {
|
|
|
|
|
/// The left `Option` key is treated as `Alt`.
|
|
|
|
|
OnlyLeft,
|
|
|
|
|
|
|
|
|
|
/// The right `Option` key is treated as `Alt`.
|
|
|
|
|
OnlyRight,
|
|
|
|
|
|
|
|
|
|
/// Both `Option` keys are treated as `Alt`.
|
|
|
|
|
Both,
|
|
|
|
|
|
|
|
|
|
/// No special handling is applied for `Option` key.
|
|
|
|
|
#[default]
|
|
|
|
|
None,
|
|
|
|
|
}
|