From 8c17d45e8cd2d834ea688b236c417e8d05f00127 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Thu, 7 Jun 2012 21:03:08 +0000 Subject: [PATCH] osx: Move the detached video dialog to the normal window level when it goes fullscreen as it's hilariously broken otherwise Originally committed to SVN as r6890. --- aegisub/src/Makefile | 1 + aegisub/src/osx_utils.mm | 36 +++++++++++++++++++++++++++++------- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/aegisub/src/Makefile b/aegisub/src/Makefile index 077b0955a..47d2fde7b 100644 --- a/aegisub/src/Makefile +++ b/aegisub/src/Makefile @@ -20,6 +20,7 @@ LDFLAGS += $(LDFLAGS_CCMALLOC) ifeq (yes, $(BUILD_DARWIN)) SRC += osx_utils.mm +osx_utils.o: OBJCXXFLAGS += -fobjc-arc endif ############### diff --git a/aegisub/src/osx_utils.mm b/aegisub/src/osx_utils.mm index bd6ec0ee6..18777e068 100644 --- a/aegisub/src/osx_utils.mm +++ b/aegisub/src/osx_utils.mm @@ -23,20 +23,42 @@ #include "config.h" +// This bit of awfulness is to disable some ARC-incompatible stuff in window.h +// that we don't need +#include +#undef wxOSX_USE_COCOA_OR_IPHONE +#define wxOSX_USE_COCOA_OR_IPHONE 0 +class WXDLLIMPEXP_FWD_CORE wxWidgetImpl; +typedef wxWidgetImpl wxOSXWidgetImpl; + #include #import void AddFullScreenButton(wxWindow *window) { - NSWindow *nsWindow = [window->GetHandle() window]; - if (![nsWindow respondsToSelector:@selector(toggleFullScreen:)]) - return; + NSWindow *nsWindow = [window->GetHandle() window]; + if (![nsWindow respondsToSelector:@selector(toggleFullScreen:)]) + return; - NSWindowCollectionBehavior collectionBehavior = [nsWindow collectionBehavior]; - collectionBehavior |= NSWindowCollectionBehaviorFullScreenPrimary; - [nsWindow setCollectionBehavior:collectionBehavior]; + NSWindowCollectionBehavior collectionBehavior = [nsWindow collectionBehavior]; + collectionBehavior |= NSWindowCollectionBehaviorFullScreenPrimary; + [nsWindow setCollectionBehavior:collectionBehavior]; } void SetFloatOnParent(wxWindow *window) { - [[window->GetHandle() window] setLevel:NSFloatingWindowLevel]; + __unsafe_unretained NSWindow *nsWindow = [window->GetHandle() window]; + [nsWindow setLevel:NSFloatingWindowLevel]; + + if (!([nsWindow collectionBehavior] & NSWindowCollectionBehaviorFullScreenPrimary)) + return; + + NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; + [nc addObserverForName:@"NSWindowWillEnterFullScreenNotification" + object:nsWindow + queue:nil + usingBlock:^(NSNotification *) { [nsWindow setLevel:NSNormalWindowLevel]; }]; + [nc addObserverForName:@"NSWindowWillExitFullScreenNotification" + object:nsWindow + queue:nil + usingBlock:^(NSNotification *) { [nsWindow setLevel:NSFloatingWindowLevel]; }]; }