aboutsummaryrefslogtreecommitdiffstats
path: root/src/api/cocoa
diff options
context:
space:
mode:
Diffstat (limited to 'src/api/cocoa')
-rw-r--r--src/api/cocoa/headless.rs6
-rw-r--r--src/api/cocoa/mod.rs50
-rw-r--r--src/api/cocoa/monitor.rs2
3 files changed, 50 insertions, 8 deletions
diff --git a/src/api/cocoa/headless.rs b/src/api/cocoa/headless.rs
index f9bbffd..eb1a06f 100644
--- a/src/api/cocoa/headless.rs
+++ b/src/api/cocoa/headless.rs
@@ -85,10 +85,12 @@ impl GlContext for HeadlessContext {
Ok(())
}
+ #[inline]
fn is_current(&self) -> bool {
unimplemented!()
}
+ #[inline]
fn get_proc_address(&self, _addr: &str) -> *const libc::c_void {
let symbol_name: CFString = _addr.parse().unwrap();
let framework_name: CFString = "com.apple.opengl".parse().unwrap();
@@ -101,14 +103,17 @@ impl GlContext for HeadlessContext {
symbol as *const libc::c_void
}
+ #[inline]
fn swap_buffers(&self) -> Result<(), ContextError> {
Ok(())
}
+ #[inline]
fn get_api(&self) -> ::Api {
::Api::OpenGl
}
+ #[inline]
fn get_pixel_format(&self) -> PixelFormat {
unimplemented!();
}
@@ -118,6 +123,7 @@ unsafe impl Send for HeadlessContext {}
unsafe impl Sync for HeadlessContext {}
impl Drop for HeadlessContext {
+ #[inline]
fn drop(&mut self) {
unsafe {
gl::DeleteTextures(1, &texture);
diff --git a/src/api/cocoa/mod.rs b/src/api/cocoa/mod.rs
index 539545c..78d0f52 100644
--- a/src/api/cocoa/mod.rs
+++ b/src/api/cocoa/mod.rs
@@ -399,14 +399,24 @@ impl Window {
}
};
- let masks = if screen.is_some() || !attrs.decorations {
- NSBorderlessWindowMask as NSUInteger |
- NSResizableWindowMask as NSUInteger
- } else {
- NSTitledWindowMask as NSUInteger |
- NSClosableWindowMask as NSUInteger |
- NSMiniaturizableWindowMask as NSUInteger |
- NSResizableWindowMask as NSUInteger
+ let masks = match (attrs.decorations, attrs.transparent) {
+ (true, false) =>
+ // Classic opaque window with titlebar
+ NSClosableWindowMask as NSUInteger |
+ NSMiniaturizableWindowMask as NSUInteger |
+ NSResizableWindowMask as NSUInteger |
+ NSTitledWindowMask as NSUInteger,
+ (false, false) =>
+ // Opaque window without a titlebar
+ NSClosableWindowMask as NSUInteger |
+ NSMiniaturizableWindowMask as NSUInteger |
+ NSResizableWindowMask as NSUInteger |
+ NSTitledWindowMask as NSUInteger |
+ NSFullSizeContentViewWindowMask as NSUInteger,
+ (_, true) =>
+ // Fully transparent window.
+ // No shadow, decorations or borders.
+ NSBorderlessWindowMask as NSUInteger
};
let window = IdRef::new(NSWindow::alloc(nil).initWithContentRect_styleMask_backing_defer_(
@@ -419,6 +429,12 @@ impl Window {
let title = IdRef::new(NSString::alloc(nil).init_str(&attrs.title));
window.setTitle_(*title);
window.setAcceptsMouseMovedEvents_(YES);
+
+ if !attrs.decorations {
+ window.setTitleVisibility_(NSWindowTitleVisibility::NSWindowTitleHidden);
+ window.setTitlebarAppearsTransparent_(YES);
+ }
+
if screen.is_some() {
window.setLevel_(NSMainMenuWindowLevel as i64 + 1);
}
@@ -568,10 +584,12 @@ impl Window {
}
}
+ #[inline]
pub fn show(&self) {
unsafe { NSWindow::makeKeyAndOrderFront_(*self.window, nil); }
}
+ #[inline]
pub fn hide(&self) {
unsafe { NSWindow::orderOut_(*self.window, nil); }
}
@@ -606,6 +624,7 @@ impl Window {
}
}
+ #[inline]
pub fn get_inner_size(&self) -> Option<(u32, u32)> {
unsafe {
let view_frame = NSView::frame(*self.view);
@@ -613,6 +632,7 @@ impl Window {
}
}
+ #[inline]
pub fn get_outer_size(&self) -> Option<(u32, u32)> {
unsafe {
let window_frame = NSWindow::frame(*self.window);
@@ -620,22 +640,26 @@ impl Window {
}
}
+ #[inline]
pub fn set_inner_size(&self, width: u32, height: u32) {
unsafe {
NSWindow::setContentSize_(*self.window, NSSize::new(width as f64, height as f64));
}
}
+ #[inline]
pub fn create_window_proxy(&self) -> WindowProxy {
WindowProxy
}
+ #[inline]
pub fn poll_events(&self) -> PollEventsIterator {
PollEventsIterator {
window: self
}
}
+ #[inline]
pub fn wait_events(&self) -> WaitEventsIterator {
WaitEventsIterator {
window: self
@@ -652,14 +676,17 @@ impl Window {
return None;
}
+ #[inline]
pub fn platform_display(&self) -> *mut libc::c_void {
unimplemented!()
}
+ #[inline]
pub fn platform_window(&self) -> *mut libc::c_void {
unimplemented!()
}
+ #[inline]
pub fn set_window_resize_callback(&mut self, callback: Option<fn(u32, u32)>) {
self.delegate.state.resize_handler = callback;
}
@@ -723,24 +750,28 @@ impl Window {
}
}
+ #[inline]
pub fn hidpi_factor(&self) -> f32 {
unsafe {
NSWindow::backingScaleFactor(*self.window) as f32
}
}
+ #[inline]
pub fn set_cursor_position(&self, x: i32, y: i32) -> Result<(), ()> {
unimplemented!();
}
}
impl GlContext for Window {
+ #[inline]
unsafe fn make_current(&self) -> Result<(), ContextError> {
let _: () = msg_send![*self.context, update];
self.context.makeCurrentContext();
Ok(())
}
+ #[inline]
fn is_current(&self) -> bool {
unsafe {
let current = NSOpenGLContext::currentContext(nil);
@@ -765,15 +796,18 @@ impl GlContext for Window {
symbol as *const _
}
+ #[inline]
fn swap_buffers(&self) -> Result<(), ContextError> {
unsafe { self.context.flushBuffer(); }
Ok(())
}
+ #[inline]
fn get_api(&self) -> ::Api {
::Api::OpenGl
}
+ #[inline]
fn get_pixel_format(&self) -> PixelFormat {
self.pixel_format.clone()
}
diff --git a/src/api/cocoa/monitor.rs b/src/api/cocoa/monitor.rs
index 138bbcd..600f7e9 100644
--- a/src/api/cocoa/monitor.rs
+++ b/src/api/cocoa/monitor.rs
@@ -21,6 +21,7 @@ pub fn get_available_monitors() -> VecDeque<MonitorID> {
monitors
}
+#[inline]
pub fn get_primary_monitor() -> MonitorID {
let id = unsafe {
MonitorID(display::CGMainDisplayID())
@@ -37,6 +38,7 @@ impl MonitorID {
Some(format!("Monitor #{}", screen_num))
}
+ #[inline]
pub fn get_native_identifier(&self) -> NativeMonitorId {
let MonitorID(display_id) = *self;
NativeMonitorId::Numeric(display_id)