Fix GUI close: Use JUCE custom title bar (not native) + force app activation via ObjC runtime
Browse files
Source/Helper/HelperPluginHost.cpp
CHANGED
|
@@ -4,15 +4,33 @@
|
|
| 4 |
#include <pthread.h>
|
| 5 |
#include <sched.h>
|
| 6 |
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
class PluginGuiWindow : public juce::DocumentWindow
|
| 9 |
{
|
| 10 |
public:
|
| 11 |
PluginGuiWindow(const juce::String& name)
|
| 12 |
-
: DocumentWindow(name, juce::Colour(0xff1a1a2e),
|
| 13 |
-
DocumentWindow::allButtons)
|
| 14 |
{
|
| 15 |
-
|
|
|
|
|
|
|
| 16 |
}
|
| 17 |
|
| 18 |
void closeButtonPressed() override
|
|
@@ -248,8 +266,8 @@ void HelperPluginHost::showGui()
|
|
| 248 |
{
|
| 249 |
if (!plugin) return;
|
| 250 |
|
| 251 |
-
//
|
| 252 |
-
|
| 253 |
|
| 254 |
// If window exists but hidden, just show it
|
| 255 |
if (guiWindow)
|
|
@@ -265,7 +283,7 @@ void HelperPluginHost::showGui()
|
|
| 265 |
guiWindow = std::make_unique<PluginGuiWindow>(plugin->getName());
|
| 266 |
guiWindow->setContentOwned(editor, true);
|
| 267 |
guiWindow->setResizable(true, true);
|
| 268 |
-
guiWindow->centreWithSize(editor->getWidth(), editor->getHeight());
|
| 269 |
guiWindow->setVisible(true);
|
| 270 |
guiWindow->toFront(true);
|
| 271 |
});
|
|
|
|
| 4 |
#include <pthread.h>
|
| 5 |
#include <sched.h>
|
| 6 |
|
| 7 |
+
#if JUCE_MAC
|
| 8 |
+
#include <objc/objc.h>
|
| 9 |
+
#include <objc/message.h>
|
| 10 |
+
#endif
|
| 11 |
+
|
| 12 |
+
// Force helper process to become a proper GUI app on macOS
|
| 13 |
+
static void makeGuiProcess()
|
| 14 |
+
{
|
| 15 |
+
#if JUCE_MAC
|
| 16 |
+
// [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]
|
| 17 |
+
id nsApp = ((id(*)(id, SEL))objc_msgSend)((id)objc_getClass("NSApplication"),
|
| 18 |
+
sel_registerName("sharedApplication"));
|
| 19 |
+
((void(*)(id, SEL, long))objc_msgSend)(nsApp, sel_registerName("setActivationPolicy:"), 0); // 0 = Regular
|
| 20 |
+
((void(*)(id, SEL, int))objc_msgSend)(nsApp, sel_registerName("activateIgnoringOtherApps:"), 1);
|
| 21 |
+
#endif
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
// Custom window with working close button
|
| 25 |
class PluginGuiWindow : public juce::DocumentWindow
|
| 26 |
{
|
| 27 |
public:
|
| 28 |
PluginGuiWindow(const juce::String& name)
|
| 29 |
+
: DocumentWindow(name, juce::Colour(0xff1a1a2e), DocumentWindow::allButtons, true)
|
|
|
|
| 30 |
{
|
| 31 |
+
// Use JUCE's own title bar — works regardless of macOS activation policy
|
| 32 |
+
setUsingNativeTitleBar(false);
|
| 33 |
+
setTitleBarHeight(28);
|
| 34 |
}
|
| 35 |
|
| 36 |
void closeButtonPressed() override
|
|
|
|
| 266 |
{
|
| 267 |
if (!plugin) return;
|
| 268 |
|
| 269 |
+
// Activate as GUI process (macOS requires this for window interaction)
|
| 270 |
+
makeGuiProcess();
|
| 271 |
|
| 272 |
// If window exists but hidden, just show it
|
| 273 |
if (guiWindow)
|
|
|
|
| 283 |
guiWindow = std::make_unique<PluginGuiWindow>(plugin->getName());
|
| 284 |
guiWindow->setContentOwned(editor, true);
|
| 285 |
guiWindow->setResizable(true, true);
|
| 286 |
+
guiWindow->centreWithSize(editor->getWidth(), editor->getHeight() + 28); // +28 for title bar
|
| 287 |
guiWindow->setVisible(true);
|
| 288 |
guiWindow->toFront(true);
|
| 289 |
});
|