aboutsummaryrefslogtreecommitdiffstats
path: root/src/osx/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/osx/mod.rs')
-rw-r--r--src/osx/mod.rs34
1 files changed, 31 insertions, 3 deletions
diff --git a/src/osx/mod.rs b/src/osx/mod.rs
index d41c9c7..78d147f 100644
--- a/src/osx/mod.rs
+++ b/src/osx/mod.rs
@@ -1,4 +1,10 @@
-use {Event, WindowBuilder};
+use Event;
+
+#[cfg(feature = "window")]
+use WindowBuilder;
+
+#[cfg(feature = "headless")]
+use HeadlessRendererBuilder;
use cocoa::base::{id, NSUInteger, nil};
use cocoa::appkit::*;
@@ -11,6 +17,14 @@ pub struct Window {
context: id,
}
+pub struct HeadlessContext(Window);
+
+impl Deref<Window> for HeadlessContext {
+ fn deref(&self) -> &Window {
+ &self.0
+ }
+}
+
pub struct MonitorID;
pub fn get_available_monitors() -> Vec<MonitorID> {
@@ -31,14 +45,28 @@ impl MonitorID {
}
}
+#[cfg(feature = "window")]
impl Window {
- pub fn new(_builder: WindowBuilder) -> Result<Window, String> {
+ pub fn new(builder: WindowBuilder) -> Result<Window, String> {
+ Window::new_impl(builder.dimensions, builder.title.as_slice(), true)
+ }
+}
+
+#[cfg(feature = "headless")]
+impl HeadlessContext {
+ pub fn new(builder: HeadlessRendererBuilder) -> Result<HeadlessContext, String> {
+ Window::new_impl(Some(builder.dimensions), "", false)
+ .map(|w| HeadlessContext(w))
+ }
+}
+impl Window {
+ fn new_impl(dimensions: Option<(uint, uint)>, title: &str, visible: bool) -> Result<Window, String> {
let app = match Window::create_app() {
Some(app) => app,
None => { return Err(format!("Couldn't create NSApplication")); },
};
- let window = match Window::create_window(_builder.dimensions.unwrap_or((800, 600)), _builder.title.as_slice()) {
+ let window = match Window::create_window(dimensions.unwrap_or((800, 600)), title) {
Some(window) => window,
None => { return Err(format!("Couldn't create NSWindow")); },
};