2016-01-17 10:12:21 +11:00
|
|
|
#![cfg(target_os = "macos")]
|
|
|
|
|
|
|
|
use std::os::raw::c_void;
|
2018-06-15 09:42:18 +10:00
|
|
|
use {LogicalSize, MonitorId, Window, WindowBuilder};
|
2016-01-17 10:12:21 +11:00
|
|
|
|
|
|
|
/// Additional methods on `Window` that are specific to MacOS.
|
|
|
|
pub trait WindowExt {
|
|
|
|
/// Returns a pointer to the cocoa `NSWindow` that is used by this window.
|
|
|
|
///
|
2016-10-07 03:58:15 +11:00
|
|
|
/// The pointer will become invalid when the `Window` is destroyed.
|
2016-01-17 10:12:21 +11:00
|
|
|
fn get_nswindow(&self) -> *mut c_void;
|
|
|
|
|
2016-10-07 03:58:15 +11:00
|
|
|
/// Returns a pointer to the cocoa `NSView` that is used by this window.
|
|
|
|
///
|
|
|
|
/// The pointer will become invalid when the `Window` is destroyed.
|
|
|
|
fn get_nsview(&self) -> *mut c_void;
|
2016-01-17 10:12:21 +11:00
|
|
|
}
|
2016-04-29 09:30:44 +10:00
|
|
|
|
2016-10-08 18:18:00 +11:00
|
|
|
impl WindowExt for Window {
|
|
|
|
#[inline]
|
|
|
|
fn get_nswindow(&self) -> *mut c_void {
|
|
|
|
self.window.get_nswindow()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn get_nsview(&self) -> *mut c_void {
|
|
|
|
self.window.get_nsview()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-29 09:30:44 +10:00
|
|
|
/// Corresponds to `NSApplicationActivationPolicy`.
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
|
|
|
pub enum ActivationPolicy {
|
|
|
|
/// Corresponds to `NSApplicationActivationPolicyRegular`.
|
|
|
|
Regular,
|
|
|
|
/// Corresponds to `NSApplicationActivationPolicyAccessory`.
|
|
|
|
Accessory,
|
|
|
|
/// Corresponds to `NSApplicationActivationPolicyProhibited`.
|
|
|
|
Prohibited,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for ActivationPolicy {
|
|
|
|
fn default() -> Self {
|
|
|
|
ActivationPolicy::Regular
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Additional methods on `WindowBuilder` that are specific to MacOS.
|
2018-03-23 03:57:35 +11:00
|
|
|
///
|
|
|
|
/// **Note:** Properties dealing with the titlebar will be overwritten by the `with_decorations` method
|
|
|
|
/// on the base `WindowBuilder`:
|
|
|
|
///
|
|
|
|
/// - `with_titlebar_transparent`
|
|
|
|
/// - `with_title_hidden`
|
|
|
|
/// - `with_titlebar_hidden`
|
|
|
|
/// - `with_titlebar_buttons_hidden`
|
|
|
|
/// - `with_fullsize_content_view`
|
2016-09-20 04:05:48 +10:00
|
|
|
pub trait WindowBuilderExt {
|
2018-05-17 00:16:36 +10:00
|
|
|
/// Sets the activation policy for the window being built.
|
2017-01-22 17:55:30 +11:00
|
|
|
fn with_activation_policy(self, activation_policy: ActivationPolicy) -> WindowBuilder;
|
2018-05-17 00:16:36 +10:00
|
|
|
/// Enables click-and-drag behavior for the entire window, not just the titlebar.
|
2018-01-23 05:07:51 +11:00
|
|
|
fn with_movable_by_window_background(self, movable_by_window_background: bool) -> WindowBuilder;
|
2018-05-17 00:16:36 +10:00
|
|
|
/// Makes the titlebar transparent and allows the content to appear behind it.
|
2018-03-23 03:57:35 +11:00
|
|
|
fn with_titlebar_transparent(self, titlebar_transparent: bool) -> WindowBuilder;
|
2018-05-17 00:16:36 +10:00
|
|
|
/// Hides the window title.
|
2018-03-23 03:57:35 +11:00
|
|
|
fn with_title_hidden(self, title_hidden: bool) -> WindowBuilder;
|
2018-05-17 00:16:36 +10:00
|
|
|
/// Hides the window titlebar.
|
2018-03-23 03:57:35 +11:00
|
|
|
fn with_titlebar_hidden(self, titlebar_hidden: bool) -> WindowBuilder;
|
2018-05-17 00:16:36 +10:00
|
|
|
/// Hides the window titlebar buttons.
|
2018-03-23 03:57:35 +11:00
|
|
|
fn with_titlebar_buttons_hidden(self, titlebar_buttons_hidden: bool) -> WindowBuilder;
|
2018-05-17 00:16:36 +10:00
|
|
|
/// Makes the window content appear behind the titlebar.
|
2018-03-23 03:57:35 +11:00
|
|
|
fn with_fullsize_content_view(self, fullsize_content_view: bool) -> WindowBuilder;
|
2018-05-17 00:16:36 +10:00
|
|
|
/// Build window with `resizeIncrements` property. Values must not be 0.
|
2018-06-15 09:42:18 +10:00
|
|
|
fn with_resize_increments(self, increments: LogicalSize) -> WindowBuilder;
|
2016-04-29 09:30:44 +10:00
|
|
|
}
|
|
|
|
|
2016-09-20 04:05:48 +10:00
|
|
|
impl WindowBuilderExt for WindowBuilder {
|
2016-04-29 09:30:44 +10:00
|
|
|
#[inline]
|
2016-09-20 04:05:48 +10:00
|
|
|
fn with_activation_policy(mut self, activation_policy: ActivationPolicy) -> WindowBuilder {
|
2016-04-29 09:30:44 +10:00
|
|
|
self.platform_specific.activation_policy = activation_policy;
|
|
|
|
self
|
|
|
|
}
|
2018-01-23 05:07:51 +11:00
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn with_movable_by_window_background(mut self, movable_by_window_background: bool) -> WindowBuilder {
|
|
|
|
self.platform_specific.movable_by_window_background = movable_by_window_background;
|
|
|
|
self
|
|
|
|
}
|
2018-03-23 03:57:35 +11:00
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn with_titlebar_transparent(mut self, titlebar_transparent: bool) -> WindowBuilder {
|
|
|
|
self.platform_specific.titlebar_transparent = titlebar_transparent;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn with_titlebar_hidden(mut self, titlebar_hidden: bool) -> WindowBuilder {
|
|
|
|
self.platform_specific.titlebar_hidden = titlebar_hidden;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn with_titlebar_buttons_hidden(mut self, titlebar_buttons_hidden: bool) -> WindowBuilder {
|
|
|
|
self.platform_specific.titlebar_buttons_hidden = titlebar_buttons_hidden;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn with_title_hidden(mut self, title_hidden: bool) -> WindowBuilder {
|
|
|
|
self.platform_specific.title_hidden = title_hidden;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn with_fullsize_content_view(mut self, fullsize_content_view: bool) -> WindowBuilder {
|
|
|
|
self.platform_specific.fullsize_content_view = fullsize_content_view;
|
|
|
|
self
|
|
|
|
}
|
2018-05-17 00:16:36 +10:00
|
|
|
|
|
|
|
#[inline]
|
2018-06-15 09:42:18 +10:00
|
|
|
fn with_resize_increments(mut self, increments: LogicalSize) -> WindowBuilder {
|
|
|
|
self.platform_specific.resize_increments = Some(increments.into());
|
2018-05-17 00:16:36 +10:00
|
|
|
self
|
|
|
|
}
|
2016-04-29 09:30:44 +10:00
|
|
|
}
|
2017-08-30 16:49:18 +10:00
|
|
|
|
|
|
|
/// Additional methods on `MonitorId` that are specific to MacOS.
|
|
|
|
pub trait MonitorIdExt {
|
|
|
|
/// Returns the identifier of the monitor for Cocoa.
|
|
|
|
fn native_id(&self) -> u32;
|
2018-03-06 19:35:04 +11:00
|
|
|
/// Returns a pointer to the NSScreen representing this monitor.
|
|
|
|
fn get_nsscreen(&self) -> Option<*mut c_void>;
|
2017-08-30 16:49:18 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
impl MonitorIdExt for MonitorId {
|
|
|
|
#[inline]
|
|
|
|
fn native_id(&self) -> u32 {
|
|
|
|
self.inner.get_native_identifier()
|
|
|
|
}
|
2018-03-06 19:35:04 +11:00
|
|
|
|
|
|
|
fn get_nsscreen(&self) -> Option<*mut c_void> {
|
|
|
|
self.inner.get_nsscreen().map(|s| s as *mut c_void)
|
|
|
|
}
|
2017-08-30 16:49:18 +10:00
|
|
|
}
|