From fd7976ddd7e54814a865015380bd9f3ea3cbf92f Mon Sep 17 00:00:00 2001 From: Marcelo Fernandez Date: Tue, 27 Jun 2017 13:13:03 -0300 Subject: Implemented borderless window code for OSX. --- platform/osx/os_osx.h | 4 ++++ platform/osx/os_osx.mm | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) (limited to 'platform') diff --git a/platform/osx/os_osx.h b/platform/osx/os_osx.h index 123816b22d..dc3e88df2c 100644 --- a/platform/osx/os_osx.h +++ b/platform/osx/os_osx.h @@ -96,6 +96,7 @@ public: CursorShape cursor_shape; MouseMode mouse_mode; + String title; bool minimized; bool maximized; bool zoomed; @@ -200,6 +201,9 @@ public: virtual void request_attention(); virtual String get_joy_guid(int p_device) const; + virtual void set_borderless_window(int p_borderless); + virtual bool get_borderless_window(); + virtual PowerState get_power_state(); virtual int get_power_seconds_left(); virtual int get_power_percent_left(); diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm index 1070de724b..ad1e308ae0 100644 --- a/platform/osx/os_osx.mm +++ b/platform/osx/os_osx.mm @@ -53,6 +53,10 @@ #include #include +#if MAC_OS_X_VERSION_MAX_ALLOWED < 101200 +#define NSWindowStyleMaskBorderless NSBorderlessWindowMask +#endif + static NSRect convertRectToBacking(NSRect contentRect) { #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 @@ -813,7 +817,13 @@ void OS_OSX::initialize(const VideoMode &p_desired, int p_video_driver, int p_au // Don't use accumulation buffer support; it's not accelerated // Aux buffers probably aren't accelerated either - unsigned int styleMask = NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | (p_desired.resizable ? NSResizableWindowMask : 0); + unsigned int styleMask; + + if (p_desired.borderless_window) { + styleMask = NSWindowStyleMaskBorderless; + } else { + styleMask = NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | (p_desired.resizable ? NSResizableWindowMask : 0); + } window_object = [[GodotWindow alloc] initWithContentRect:NSMakeRect(0, 0, p_desired.width, p_desired.height) @@ -1125,6 +1135,7 @@ int OS_OSX::get_mouse_button_state() const { } void OS_OSX::set_window_title(const String &p_title) { + title = p_title; [window_object setTitle:[NSString stringWithUTF8String:p_title.utf8().get_data()]]; } @@ -1403,6 +1414,28 @@ void OS_OSX::request_attention() { [NSApp requestUserAttention:NSCriticalRequest]; } +void OS_OSX::set_borderless_window(int p_borderless) { + + if (p_borderless) + [window_object setStyleMask:NSWindowStyleMaskBorderless]; + else { + [window_object setStyleMask:NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask]; + + // Force update of the window styles + NSRect frameRect = [window_object frame]; + [window_object setFrame:NSMakeRect(frameRect.origin.x, frameRect.origin.y, frameRect.size.width + 1, frameRect.size.height) display:NO]; + [window_object setFrame:frameRect display:NO]; + + // Restore the window title + [window_object setTitle:[NSString stringWithUTF8String:title.utf8().get_data()]]; + } +} + +bool OS_OSX::get_borderless_window() { + + return [window_object styleMask] == NSWindowStyleMaskBorderless; +} + String OS_OSX::get_executable_path() const { int ret; -- cgit v1.2.3