From e1d0f07c9099a01487bd345109f9b768d7f257bc Mon Sep 17 00:00:00 2001 From: Mihir Patil Date: Wed, 2 Aug 2023 00:01:37 -0400 Subject: [PATCH 1/3] highgui(cocoa): fix fullscreen behavior --- modules/highgui/src/window_cocoa.mm | 39 +++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/modules/highgui/src/window_cocoa.mm b/modules/highgui/src/window_cocoa.mm index 86f38d0ae8..5800ab3f94 100644 --- a/modules/highgui/src/window_cocoa.mm +++ b/modules/highgui/src/window_cocoa.mm @@ -195,6 +195,9 @@ CV_IMPL void cvDestroyWindow( const char* name) //cout << "cvDestroyWindow" << endl; CVWindow *window = cvGetWindow(name); if(window) { + if ([window styleMask] & NSFullScreenWindowMask) { + [window toggleFullScreen:nil]; + } [window close]; [windows removeObjectForKey:[NSString stringWithFormat:@"%s", name]]; } @@ -701,7 +704,11 @@ double cvGetModeWindow_COCOA( const char* name ) void cvSetModeWindow_COCOA( const char* name, double prop_value ) { CVWindow *window = nil; + +#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 NSDictionary *fullscreenOptions = nil; +#endif + NSAutoreleasePool* localpool = nil; CV_FUNCNAME( "cvSetModeWindow_COCOA" ); @@ -724,7 +731,35 @@ void cvSetModeWindow_COCOA( const char* name, double prop_value ) } localpool = [[NSAutoreleasePool alloc] init]; + + // std::cout << "setting mode" << std::endl; +#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_6 + if ( ([window styleMask] & NSFullScreenWindowMask) && prop_value==CV_WINDOW_NORMAL ) + { + // std::cout << "exiting fullscreen" << std::endl; + [window toggleFullScreen:nil]; + + window.status=CV_WINDOW_NORMAL; + } + else if( !([window styleMask] & NSFullScreenWindowMask) && prop_value==CV_WINDOW_FULLSCREEN ) + { + // std::cout << "entering fullscreen" << std::endl; + [window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary]; + NSScreen* screen = [window screen]; + + NSRect frame = [screen frame]; + [window setFrame:frame display:YES]; + + [window setContentSize:frame.size]; + + [window toggleFullScreen:nil]; + + [window setFrameTopLeftPoint: frame.origin]; + + window.status=CV_WINDOW_FULLSCREEN; + } +#else fullscreenOptions = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:NSFullScreenModeSetting]; if ( [[window contentView] isInFullScreenMode] && prop_value==CV_WINDOW_NORMAL ) { @@ -736,7 +771,7 @@ void cvSetModeWindow_COCOA( const char* name, double prop_value ) [[window contentView] enterFullScreenMode:[NSScreen mainScreen] withOptions:fullscreenOptions]; window.status=CV_WINDOW_FULLSCREEN; } - +#endif [localpool drain]; __END__; @@ -810,7 +845,7 @@ void cvSetPropTopmost_COCOA( const char* name, const bool topmost ) CV_ERROR( CV_StsNullPtr, "NULL window" ); } - if ([[window contentView] isInFullScreenMode]) + if (([window styleMask] & NSFullScreenWindowMask)) { EXIT; } From afb406f1dea030fbb39654584778a5dd5c363464 Mon Sep 17 00:00:00 2001 From: Mihir Patil Date: Sun, 6 Aug 2023 20:10:05 -0400 Subject: [PATCH 2/3] style: remove trailing whitespace --- modules/highgui/src/window_cocoa.mm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/highgui/src/window_cocoa.mm b/modules/highgui/src/window_cocoa.mm index 5800ab3f94..5e34b502db 100644 --- a/modules/highgui/src/window_cocoa.mm +++ b/modules/highgui/src/window_cocoa.mm @@ -197,7 +197,7 @@ CV_IMPL void cvDestroyWindow( const char* name) if(window) { if ([window styleMask] & NSFullScreenWindowMask) { [window toggleFullScreen:nil]; - } + } [window close]; [windows removeObjectForKey:[NSString stringWithFormat:@"%s", name]]; } @@ -731,7 +731,7 @@ void cvSetModeWindow_COCOA( const char* name, double prop_value ) } localpool = [[NSAutoreleasePool alloc] init]; - + // std::cout << "setting mode" << std::endl; #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_6 if ( ([window styleMask] & NSFullScreenWindowMask) && prop_value==CV_WINDOW_NORMAL ) @@ -746,11 +746,11 @@ void cvSetModeWindow_COCOA( const char* name, double prop_value ) // std::cout << "entering fullscreen" << std::endl; [window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary]; - NSScreen* screen = [window screen]; + NSScreen* screen = [window screen]; NSRect frame = [screen frame]; [window setFrame:frame display:YES]; - + [window setContentSize:frame.size]; [window toggleFullScreen:nil]; From fb34f36c695c177d34b9303bd175925995cc3daf Mon Sep 17 00:00:00 2001 From: Mihir Patil Date: Mon, 14 Aug 2023 19:11:14 -0400 Subject: [PATCH 3/3] style: remove extraneous std::cout --- modules/highgui/src/window_cocoa.mm | 3 --- 1 file changed, 3 deletions(-) diff --git a/modules/highgui/src/window_cocoa.mm b/modules/highgui/src/window_cocoa.mm index 5e34b502db..7e364220fa 100644 --- a/modules/highgui/src/window_cocoa.mm +++ b/modules/highgui/src/window_cocoa.mm @@ -732,18 +732,15 @@ void cvSetModeWindow_COCOA( const char* name, double prop_value ) localpool = [[NSAutoreleasePool alloc] init]; - // std::cout << "setting mode" << std::endl; #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_6 if ( ([window styleMask] & NSFullScreenWindowMask) && prop_value==CV_WINDOW_NORMAL ) { - // std::cout << "exiting fullscreen" << std::endl; [window toggleFullScreen:nil]; window.status=CV_WINDOW_NORMAL; } else if( !([window styleMask] & NSFullScreenWindowMask) && prop_value==CV_WINDOW_FULLSCREEN ) { - // std::cout << "entering fullscreen" << std::endl; [window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary]; NSScreen* screen = [window screen];