diff --git a/distrho/src/DistrhoUI.cpp b/distrho/src/DistrhoUI.cpp index 9bdb9908..2dfb1d63 100644 --- a/distrho/src/DistrhoUI.cpp +++ b/distrho/src/DistrhoUI.cpp @@ -52,6 +52,7 @@ UI::PrivateData::createNextWindow(UI* const ui, const uint width, const uint hei ewData.height = height; ewData.scaleFactor = pData->scaleFactor; ewData.title = DISTRHO_PLUGIN_NAME; + ewData.isStandalone = DISTRHO_UI_IS_STANDALONE; return ewData; #else pData->window = new PluginWindow(ui, pData->app, pData->winId, width, height, pData->scaleFactor); diff --git a/distrho/src/DistrhoUIPrivateData.hpp b/distrho/src/DistrhoUIPrivateData.hpp index 60575cc8..63c89caa 100644 --- a/distrho/src/DistrhoUIPrivateData.hpp +++ b/distrho/src/DistrhoUIPrivateData.hpp @@ -130,7 +130,6 @@ public: : ui(uiPtr) { app.ui = ui; - ui->pData.isStandalone = DISTRHO_UI_IS_STANDALONE; } // fetch cached data diff --git a/examples/EmbedExternalUI/EmbedExternalExampleUI.cpp b/examples/EmbedExternalUI/EmbedExternalExampleUI.cpp index 2383c2a4..28845f5d 100644 --- a/examples/EmbedExternalUI/EmbedExternalExampleUI.cpp +++ b/examples/EmbedExternalUI/EmbedExternalExampleUI.cpp @@ -43,9 +43,10 @@ @implementation NSExternalWindow { @public bool closed; + bool standalone; } - (BOOL)canBecomeKeyWindow { return YES; } -- (BOOL)canBecomeMainWindow { return NO; } +- (BOOL)canBecomeMainWindow { return standalone ? YES : NO; } - (BOOL)windowShouldClose:(id)_ { closed = true; return YES; } @end #endif @@ -78,17 +79,19 @@ public: #endif fValue(0.0f) { + const bool standalone = isStandalone(); + d_stdout("isStandalone %d", (int)standalone); + #if defined(DISTRHO_OS_MAC) - if (isStandalone()) + NSAutoreleasePool* const pool = [[NSAutoreleasePool alloc]init]; + [NSApplication sharedApplication]; + + if (standalone) { - [[NSApplication sharedApplication]new]; [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; [NSApp activateIgnoringOtherApps:YES]; } - NSAutoreleasePool* const pool = [[NSAutoreleasePool alloc] init]; - [NSApplication sharedApplication]; - fView = [NSView new]; DISTRHO_SAFE_ASSERT_RETURN(fView != nullptr,); @@ -118,6 +121,7 @@ public: DISTRHO_SAFE_ASSERT_RETURN(fWindow != nullptr,); fWindow->closed = false; // is this needed? + fWindow->standalone = standalone; [fWindow setIsVisible:NO]; if (NSString* const nsTitle = [[NSString alloc] @@ -129,7 +133,6 @@ public: [fWindow setContentView:fView]; [fWindow setContentSize:NSMakeSize(getWidth(), getHeight())]; [fWindow makeFirstResponder:fView]; - [fWindow makeKeyAndOrderFront:fWindow]; } [pool release]; @@ -234,6 +237,8 @@ protected: #if defined(DISTRHO_OS_MAC) DISTRHO_SAFE_ASSERT_RETURN(fWindow != nil,); [fWindow orderFrontRegardless]; + [fWindow makeKeyWindow]; + [fWindow makeFirstResponder:fView]; #elif defined(DISTRHO_OS_WINDOWS) #else DISTRHO_SAFE_ASSERT_RETURN(fWindow != 0,); @@ -291,9 +296,18 @@ protected: #if defined(DISTRHO_OS_MAC) DISTRHO_SAFE_ASSERT_RETURN(fView != nullptr,); if (fWindow != nil) + { [fWindow setIsVisible:(visible ? YES : NO)]; + + if (isStandalone()) + [fWindow makeMainWindow]; + + [fWindow makeKeyAndOrderFront:fWindow]; + } else + { [fView setHidden:(visible ? NO : YES)]; + } #elif defined(DISTRHO_OS_WINDOWS) #else DISTRHO_SAFE_ASSERT_RETURN(fWindow != 0,);