aboutsummaryrefslogtreecommitdiffstats
path: root/src/api/cocoa/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/api/cocoa/mod.rs')
-rw-r--r--src/api/cocoa/mod.rs50
1 files changed, 42 insertions, 8 deletions
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()
}