diff --git a/src/os/macos.rs b/src/os/macos.rs index 68e685ee..19c6331a 100755 --- a/src/os/macos.rs +++ b/src/os/macos.rs @@ -61,9 +61,23 @@ impl From for NSApplicationActivationPolicy { } /// Additional methods on `WindowBuilder` that are specific to MacOS. +/// +/// **Note:** Properties dealing with the titlebar will be overwritten by the `with_decorations` method +/// on the base `WindowBuilder`: +/// +/// - `with_titlebar_transparent` +/// - `with_title_hidden` +/// - `with_titlebar_hidden` +/// - `with_titlebar_buttons_hidden` +/// - `with_fullsize_content_view` pub trait WindowBuilderExt { fn with_activation_policy(self, activation_policy: ActivationPolicy) -> WindowBuilder; fn with_movable_by_window_background(self, movable_by_window_background: bool) -> WindowBuilder; + fn with_titlebar_transparent(self, titlebar_transparent: bool) -> WindowBuilder; + fn with_title_hidden(self, title_hidden: bool) -> WindowBuilder; + fn with_titlebar_hidden(self, titlebar_hidden: bool) -> WindowBuilder; + fn with_titlebar_buttons_hidden(self, titlebar_buttons_hidden: bool) -> WindowBuilder; + fn with_fullsize_content_view(self, fullsize_content_view: bool) -> WindowBuilder; } impl WindowBuilderExt for WindowBuilder { @@ -80,6 +94,41 @@ impl WindowBuilderExt for WindowBuilder { self.platform_specific.movable_by_window_background = movable_by_window_background; self } + + /// Makes the titlebar transparent and allows the content to appear behind it + #[inline] + fn with_titlebar_transparent(mut self, titlebar_transparent: bool) -> WindowBuilder { + self.platform_specific.titlebar_transparent = titlebar_transparent; + self + } + + /// Hides the window titlebar + #[inline] + fn with_titlebar_hidden(mut self, titlebar_hidden: bool) -> WindowBuilder { + self.platform_specific.titlebar_hidden = titlebar_hidden; + self + } + + /// Hides the window titlebar buttons + #[inline] + fn with_titlebar_buttons_hidden(mut self, titlebar_buttons_hidden: bool) -> WindowBuilder { + self.platform_specific.titlebar_buttons_hidden = titlebar_buttons_hidden; + self + } + + /// Hides the window title + #[inline] + fn with_title_hidden(mut self, title_hidden: bool) -> WindowBuilder { + self.platform_specific.title_hidden = title_hidden; + self + } + + /// Makes the window content appear behind the titlebar + #[inline] + fn with_fullsize_content_view(mut self, fullsize_content_view: bool) -> WindowBuilder { + self.platform_specific.fullsize_content_view = fullsize_content_view; + self + } } /// Additional methods on `MonitorId` that are specific to MacOS. diff --git a/src/platform/macos/window.rs b/src/platform/macos/window.rs index aa409c71..b5ba31ea 100644 --- a/src/platform/macos/window.rs +++ b/src/platform/macos/window.rs @@ -13,7 +13,7 @@ use objc::declare::ClassDecl; use cocoa; use cocoa::base::{id, nil}; use cocoa::foundation::{NSPoint, NSRect, NSSize, NSString}; -use cocoa::appkit::{self, NSApplication, NSColor, NSView, NSWindow, NSWindowStyleMask}; +use cocoa::appkit::{self, NSApplication, NSColor, NSView, NSWindow, NSWindowStyleMask, NSWindowButton}; use core_graphics::display::CGDisplay; @@ -255,6 +255,11 @@ impl Drop for WindowDelegate { pub struct PlatformSpecificWindowBuilderAttributes { pub activation_policy: ActivationPolicy, pub movable_by_window_background: bool, + pub titlebar_transparent: bool, + pub title_hidden: bool, + pub titlebar_hidden: bool, + pub titlebar_buttons_hidden: bool, + pub fullsize_content_view: bool, } pub struct Window2 { @@ -404,17 +409,37 @@ impl Window2 { let masks = if screen.is_some() { // Fullscreen window - NSWindowStyleMask::NSBorderlessWindowMask | NSWindowStyleMask::NSResizableWindowMask | + NSWindowStyleMask::NSBorderlessWindowMask | + NSWindowStyleMask::NSResizableWindowMask | NSWindowStyleMask::NSTitledWindowMask - } else if attrs.decorations { - // Window2 with a titlebar - NSWindowStyleMask::NSClosableWindowMask | NSWindowStyleMask::NSMiniaturizableWindowMask | - NSWindowStyleMask::NSResizableWindowMask | NSWindowStyleMask::NSTitledWindowMask - } else { + } else if !attrs.decorations { // Window2 without a titlebar - NSWindowStyleMask::NSClosableWindowMask | NSWindowStyleMask::NSMiniaturizableWindowMask | + NSWindowStyleMask::NSClosableWindowMask | + NSWindowStyleMask::NSMiniaturizableWindowMask | NSWindowStyleMask::NSResizableWindowMask | NSWindowStyleMask::NSFullSizeContentViewWindowMask + } else if pl_attrs.titlebar_hidden { + NSWindowStyleMask::NSBorderlessWindowMask | + NSWindowStyleMask::NSResizableWindowMask + } else if !pl_attrs.titlebar_transparent { + // Window2 with a titlebar + NSWindowStyleMask::NSClosableWindowMask | + NSWindowStyleMask::NSMiniaturizableWindowMask | + NSWindowStyleMask::NSResizableWindowMask | + NSWindowStyleMask::NSTitledWindowMask + } else if pl_attrs.fullsize_content_view { + // Window2 with a transparent titlebar and fullsize content view + NSWindowStyleMask::NSClosableWindowMask | + NSWindowStyleMask::NSMiniaturizableWindowMask | + NSWindowStyleMask::NSResizableWindowMask | + NSWindowStyleMask::NSTitledWindowMask | + NSWindowStyleMask::NSFullSizeContentViewWindowMask + } else { + // Window2 with a transparent titlebar and regular content view + NSWindowStyleMask::NSClosableWindowMask | + NSWindowStyleMask::NSMiniaturizableWindowMask | + NSWindowStyleMask::NSResizableWindowMask | + NSWindowStyleMask::NSTitledWindowMask }; let window = IdRef::new(NSWindow::alloc(nil).initWithContentRect_styleMask_backing_defer_( @@ -429,15 +454,31 @@ impl Window2 { window.setTitle_(*title); window.setAcceptsMouseMovedEvents_(YES); + if pl_attrs.titlebar_transparent { + window.setTitlebarAppearsTransparent_(YES); + } + if pl_attrs.title_hidden { + window.setTitleVisibility_(appkit::NSWindowTitleVisibility::NSWindowTitleHidden); + } + if pl_attrs.titlebar_buttons_hidden { + let button = window.standardWindowButton_(NSWindowButton::NSWindowFullScreenButton); + msg_send![button, setHidden:YES]; + let button = window.standardWindowButton_(NSWindowButton::NSWindowMiniaturizeButton); + msg_send![button, setHidden:YES]; + let button = window.standardWindowButton_(NSWindowButton::NSWindowCloseButton); + msg_send![button, setHidden:YES]; + let button = window.standardWindowButton_(NSWindowButton::NSWindowZoomButton); + msg_send![button, setHidden:YES]; + } + if pl_attrs.movable_by_window_background { + window.setMovableByWindowBackground_(YES); + } + if !attrs.decorations { window.setTitleVisibility_(appkit::NSWindowTitleVisibility::NSWindowTitleHidden); window.setTitlebarAppearsTransparent_(YES); } - if pl_attrs.movable_by_window_background { - window.setMovableByWindowBackground_(YES); - } - if screen.is_some() { window.setLevel_(appkit::NSMainMenuWindowLevel as i64 + 1); }