Merge pull request #24098 from 0xMihir:4.x

Fix fullscreen behavior for macOS
pull/24221/head
Alexander Smorkalov 1 year ago committed by GitHub
commit e274e72869
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 36
      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" );
@ -725,6 +732,31 @@ void cvSetModeWindow_COCOA( const char* name, double prop_value )
localpool = [[NSAutoreleasePool alloc] init];
#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_6
if ( ([window styleMask] & NSFullScreenWindowMask) && prop_value==CV_WINDOW_NORMAL )
{
[window toggleFullScreen:nil];
window.status=CV_WINDOW_NORMAL;
}
else if( !([window styleMask] & NSFullScreenWindowMask) && prop_value==CV_WINDOW_FULLSCREEN )
{
[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 +768,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 +842,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;
}

Loading…
Cancel
Save