From 86617c055046e9d9689f6b056a0b020776d43037 Mon Sep 17 00:00:00 2001 From: jqdg Date: Sun, 8 Aug 2021 23:00:51 -0700 Subject: [PATCH] Fix zombie windows in Mac OS when switching to/from fullscreen --- src/SFML/Window/OSX/SFWindow.h | 12 ++++++++++++ src/SFML/Window/OSX/SFWindow.m | 7 +++++++ src/SFML/Window/OSX/WindowImplCocoa.mm | 6 +++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/SFML/Window/OSX/SFWindow.h b/src/SFML/Window/OSX/SFWindow.h index a59101a9d..7e3d02929 100644 --- a/src/SFML/Window/OSX/SFWindow.h +++ b/src/SFML/Window/OSX/SFWindow.h @@ -57,6 +57,18 @@ //////////////////////////////////////////////////////////// -(BOOL)canBecomeKeyWindow; +//////////////////////////////////////////////////////////// +/// \brief Allow fullscreen windows to become the main window +/// +/// By default, fullscreen windows (using NSBorderlessWindowMask) +/// cannot become the main window, so this method is changed to +/// always return YES. +/// +/// \return YES +/// +//////////////////////////////////////////////////////////// +-(BOOL)canBecomeMainWindow; + //////////////////////////////////////////////////////////// /// \brief Prevent system alert /// diff --git a/src/SFML/Window/OSX/SFWindow.m b/src/SFML/Window/OSX/SFWindow.m index ff60c6c57..507f258bc 100644 --- a/src/SFML/Window/OSX/SFWindow.m +++ b/src/SFML/Window/OSX/SFWindow.m @@ -45,6 +45,13 @@ } +//////////////////////////////////////////////////////// +-(BOOL)canBecomeMainWindow +{ + return YES; +} + + //////////////////////////////////////////////////////// -(void)keyDown:(NSEvent*)theEvent { diff --git a/src/SFML/Window/OSX/WindowImplCocoa.mm b/src/SFML/Window/OSX/WindowImplCocoa.mm index 091b7b2d6..b4453a98a 100644 --- a/src/SFML/Window/OSX/WindowImplCocoa.mm +++ b/src/SFML/Window/OSX/WindowImplCocoa.mm @@ -154,7 +154,11 @@ WindowImplCocoa::~WindowImplCocoa() // Put the next window in front, if any. NSArray* windows = [NSApp orderedWindows]; if ([windows count] > 0) - [[windows objectAtIndex:0] makeKeyAndOrderFront:nil]; + { + NSWindow *nextWindow = [windows objectAtIndex:0]; + if ([nextWindow isVisible]) + [nextWindow makeKeyAndOrderFront:nil]; + } drainThreadPool(); // Make sure everything was freed // This solve some issue when sf::Window::Create is called for the