aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Cargo.toml2
-rw-r--r--src/api/cocoa/mod.rs14
-rw-r--r--src/lib.rs17
-rw-r--r--src/os/macos.rs48
-rw-r--r--src/window.rs16
5 files changed, 74 insertions, 23 deletions
diff --git a/Cargo.toml b/Cargo.toml
index c1a921a..37a2b38 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -39,7 +39,7 @@ objc = "0.2"
[target.x86_64-apple-darwin.dependencies]
objc = "0.2"
cgl = "0.1"
-cocoa = "0.3"
+cocoa = "0.3.2"
core-foundation = "0"
core-graphics = "0.3"
diff --git a/src/api/cocoa/mod.rs b/src/api/cocoa/mod.rs
index da7c1ec..3c4d802 100644
--- a/src/api/cocoa/mod.rs
+++ b/src/api/cocoa/mod.rs
@@ -15,6 +15,7 @@ use ReleaseBehavior;
use Robustness;
use WindowAttributes;
use native_monitor::NativeMonitorId;
+use os::macos::ActivationPolicy;
use objc::runtime::{Class, Object, Sel, BOOL, YES, NO};
use objc::declare::ClassDecl;
@@ -181,7 +182,9 @@ impl Drop for WindowDelegate {
}
#[derive(Default)]
-pub struct PlatformSpecificWindowBuilderAttributes;
+pub struct PlatformSpecificWindowBuilderAttributes {
+ pub activation_policy: ActivationPolicy,
+}
pub struct Window {
view: IdRef,
@@ -276,7 +279,8 @@ impl<'a> Iterator for WaitEventsIterator<'a> {
impl Window {
pub fn new(win_attribs: &WindowAttributes, pf_reqs: &PixelFormatRequirements,
- opengl: &GlAttributes<&Window>, _: &PlatformSpecificWindowBuilderAttributes)
+ opengl: &GlAttributes<&Window>,
+ pl_attribs: &PlatformSpecificWindowBuilderAttributes)
-> Result<Window, CreationError>
{
if opengl.sharing.is_some() {
@@ -294,7 +298,7 @@ impl Window {
_ => ()
}
- let app = match Window::create_app() {
+ let app = match Window::create_app(pl_attribs.activation_policy) {
Some(app) => app,
None => { return Err(OsError(format!("Couldn't create NSApplication"))); },
};
@@ -359,13 +363,13 @@ impl Window {
Ok(window)
}
- fn create_app() -> Option<id> {
+ fn create_app(activation_policy: ActivationPolicy) -> Option<id> {
unsafe {
let app = NSApp();
if app == nil {
None
} else {
- app.setActivationPolicy_(NSApplicationActivationPolicyRegular);
+ app.setActivationPolicy_(activation_policy.into());
app.finishLaunching();
Some(app)
}
diff --git a/src/lib.rs b/src/lib.rs
index fb03bed..ff5d52e 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -62,7 +62,7 @@ extern crate wayland_client;
pub use events::*;
pub use headless::{HeadlessRendererBuilder, HeadlessContext};
-pub use window::{WindowBuilder, WindowProxy, PollEventsIterator, WaitEventsIterator};
+pub use window::{WindowProxy, PollEventsIterator, WaitEventsIterator};
pub use window::{AvailableMonitorsIter, MonitorId, get_available_monitors, get_primary_monitor};
pub use native_monitor::NativeMonitorId;
@@ -105,6 +105,21 @@ pub struct Window {
window: platform::Window,
}
+/// Object that allows you to build windows.
+pub struct WindowBuilder<'a> {
+ /// The attributes to use to create the window.
+ pub window: WindowAttributes,
+
+ /// The attributes to use to create the context.
+ pub opengl: GlAttributes<&'a platform::Window>,
+
+ // Should be made public once it's stabilized.
+ pf_reqs: PixelFormatRequirements,
+
+ /// Platform-specific configuration.
+ platform_specific: platform::PlatformSpecificWindowBuilderAttributes,
+}
+
/// Trait that describes objects that have access to an OpenGL context.
pub trait GlContext {
/// Sets the context as the current context.
diff --git a/src/os/macos.rs b/src/os/macos.rs
index 16ffe33..06ea55c 100644
--- a/src/os/macos.rs
+++ b/src/os/macos.rs
@@ -1,7 +1,9 @@
#![cfg(target_os = "macos")]
+use std::convert::From;
use std::os::raw::c_void;
-use Window;
+use cocoa::appkit::NSApplicationActivationPolicy;
+use {Window, WindowBuilder};
/// Additional methods on `Window` that are specific to MacOS.
pub trait WindowExt {
@@ -17,3 +19,47 @@ impl WindowExt for Window {
self.window.platform_window() as *mut c_void
}
}
+
+/// 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
+ }
+}
+
+impl From<ActivationPolicy> for NSApplicationActivationPolicy {
+ fn from(activation_policy: ActivationPolicy) -> Self {
+ match activation_policy {
+ ActivationPolicy::Regular =>
+ NSApplicationActivationPolicy::NSApplicationActivationPolicyRegular,
+ ActivationPolicy::Accessory =>
+ NSApplicationActivationPolicy::NSApplicationActivationPolicyAccessory,
+ ActivationPolicy::Prohibited =>
+ NSApplicationActivationPolicy::NSApplicationActivationPolicyProhibited,
+ }
+ }
+}
+
+/// Additional methods on `WindowBuilder` that are specific to MacOS.
+pub trait WindowBuilderExt<'a> {
+ fn with_activation_policy(mut self, activation_policy: ActivationPolicy) -> WindowBuilder<'a>;
+}
+
+impl<'a> WindowBuilderExt<'a> for WindowBuilder<'a> {
+ /// Sets the activation policy for the window being built
+ #[inline]
+ fn with_activation_policy(mut self, activation_policy: ActivationPolicy) -> WindowBuilder<'a> {
+ self.platform_specific.activation_policy = activation_policy;
+ self
+ }
+}
diff --git a/src/window.rs b/src/window.rs
index 6d2f0d3..8e82c1d 100644
--- a/src/window.rs
+++ b/src/window.rs
@@ -16,26 +16,12 @@ use PixelFormatRequirements;
use Robustness;
use Window;
use WindowAttributes;
+use WindowBuilder;
use native_monitor::NativeMonitorId;
use libc;
use platform;
-/// Object that allows you to build windows.
-pub struct WindowBuilder<'a> {
- /// The attributes to use to create the window.
- pub window: WindowAttributes,
-
- /// The attributes to use to create the context.
- pub opengl: GlAttributes<&'a platform::Window>,
-
- // Should be made public once it's stabilized.
- pf_reqs: PixelFormatRequirements,
-
- /// Platform-specific configuration.
- platform_specific: platform::PlatformSpecificWindowBuilderAttributes,
-}
-
impl<'a> WindowBuilder<'a> {
/// Initializes a new `WindowBuilder` with default values.
#[inline]