aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorCorey Farwell <coreyf@rwell.org>2016-04-28 19:30:44 -0400
committerCorey Farwell <coreyf@rwell.org>2016-04-29 10:43:30 -0400
commitdc49156fe6bd2d15c4bd5e5f9e1ff6f3ffe7d334 (patch)
tree11e04bd8607b2443b05e0781fa63c58dfff1f19d /src
parente46781979499e47e04697fe96994dfe96b7f1e59 (diff)
downloadglutin-dc49156fe6bd2d15c4bd5e5f9e1ff6f3ffe7d334.tar.gz
glutin-dc49156fe6bd2d15c4bd5e5f9e1ff6f3ffe7d334.zip
Allow OSX WindowBuilder to specify 'activation behavior'.
Diffstat (limited to 'src')
-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
4 files changed, 73 insertions, 22 deletions
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]