From c860a247d3e21628a0ac799d4d99ae178bb8a4a3 Mon Sep 17 00:00:00 2001 From: Michael Lutz Date: Sun, 3 Jan 2021 15:13:28 +0100 Subject: Change: [OSX] Hide Dock and menu during fullscreen mode. --- src/video/cocoa/cocoa_v.h | 2 +- src/video/cocoa/cocoa_v.mm | 19 ++++++++++++------- src/video/cocoa/cocoa_wnd.h | 1 + src/video/cocoa/cocoa_wnd.mm | 6 ++++++ 4 files changed, 20 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/video/cocoa/cocoa_v.h b/src/video/cocoa/cocoa_v.h index db970d979..52d26c847 100644 --- a/src/video/cocoa/cocoa_v.h +++ b/src/video/cocoa/cocoa_v.h @@ -140,7 +140,7 @@ public: /** Toggle between fullscreen and windowed mode * @return whether switch was successful */ - virtual bool ToggleFullscreen() { return false; }; + virtual bool ToggleFullscreen(bool fullscreen) { return false; }; /** Return the width of the current view * @return width of the current view diff --git a/src/video/cocoa/cocoa_v.mm b/src/video/cocoa/cocoa_v.mm index 6031fa34c..0f3c4c32c 100644 --- a/src/video/cocoa/cocoa_v.mm +++ b/src/video/cocoa/cocoa_v.mm @@ -175,7 +175,7 @@ void QZ_GameSizeChanged() static CocoaSubdriver *QZ_CreateSubdriver(int width, int height, int bpp, bool fullscreen, bool fallback) { CocoaSubdriver *ret = QZ_CreateWindowQuartzSubdriver(width, height, bpp); - if (ret != nullptr && fullscreen) ret->ToggleFullscreen(); + if (ret != nullptr && fullscreen) ret->ToggleFullscreen(fullscreen); if (ret != nullptr) return ret; if (!fallback) return nullptr; @@ -297,7 +297,7 @@ bool VideoDriver_Cocoa::ToggleFullscreen(bool full_screen) { assert(_cocoa_subdriver != NULL); - return _cocoa_subdriver->ToggleFullscreen(); + return _cocoa_subdriver->ToggleFullscreen(full_screen); } /** @@ -355,8 +355,8 @@ public: virtual bool ChangeResolution(int w, int h, int bpp); - virtual bool IsFullscreen() { return false; } - virtual bool ToggleFullscreen(); /* Full screen mode on OSX 10.7 */ + virtual bool IsFullscreen(); + virtual bool ToggleFullscreen(bool fullscreen); /* Full screen mode on OSX 10.7 */ virtual int GetWidth() { return window_width; } virtual int GetHeight() { return window_height; } @@ -474,11 +474,18 @@ void WindowQuartzSubdriver::GetDeviceInfo() CGDisplayModeRelease(cur_mode); } +bool WindowQuartzSubdriver::IsFullscreen() +{ + return this->window != nil && ([ this->window styleMask ] & NSWindowStyleMaskFullScreen) != 0; +} + /** Switch to full screen mode on OSX 10.7 * @return Whether we switched to full screen */ -bool WindowQuartzSubdriver::ToggleFullscreen() +bool WindowQuartzSubdriver::ToggleFullscreen(bool fullscreen) { + if (this->IsFullscreen() == fullscreen) return true; + if ([ this->window respondsToSelector:@selector(toggleFullScreen:) ]) { [ this->window performSelector:@selector(toggleFullScreen:) withObject:this->window ]; return true; @@ -531,8 +538,6 @@ bool WindowQuartzSubdriver::SetVideoMode(int width, int height, int bpp) NSButton* fullscreenButton = [ this->window standardWindowButton:NSWindowFullScreenButton ]; [ fullscreenButton setAction:@selector(toggleFullScreen:) ]; [ fullscreenButton setTarget:this->window ]; - - [ this->window setCollectionBehavior: NSWindowCollectionBehaviorFullScreenPrimary ]; } [ this->window setDriver:this ]; diff --git a/src/video/cocoa/cocoa_wnd.h b/src/video/cocoa/cocoa_wnd.h index 506fbd294..f2890ec0f 100644 --- a/src/video/cocoa/cocoa_wnd.h +++ b/src/video/cocoa/cocoa_wnd.h @@ -67,6 +67,7 @@ extern NSString *OTTDMainLaunchGameEngine; - (BOOL)windowShouldClose:(id)sender; - (void)windowDidEnterFullScreen:(NSNotification *)aNotification; - (void)windowDidChangeScreenProfile:(NSNotification *)aNotification; +- (NSApplicationPresentationOptions)window:(NSWindow *)window willUseFullScreenPresentationOptions:(NSApplicationPresentationOptions)proposedOptions; @end diff --git a/src/video/cocoa/cocoa_wnd.mm b/src/video/cocoa/cocoa_wnd.mm index addf94ba3..a2854adaf 100644 --- a/src/video/cocoa/cocoa_wnd.mm +++ b/src/video/cocoa/cocoa_wnd.mm @@ -860,5 +860,11 @@ static const char *Utf8AdvanceByUtf16Units(const char *str, NSUInteger count) if (!driver->setup) driver->WindowResized(); } +/** Presentation options to use for fullsreen mode. */ +- (NSApplicationPresentationOptions)window:(NSWindow *)window willUseFullScreenPresentationOptions:(NSApplicationPresentationOptions)proposedOptions +{ + return NSApplicationPresentationFullScreen | NSApplicationPresentationHideMenuBar | NSApplicationPresentationHideDock; +} + @end #endif /* WITH_COCOA */ -- cgit v1.2.3-70-g09d2