Fix GUI focus: Remove makeAccessoryProcess entirely, use NSWindow level trick to float without activation
Browse files8 unmodified lines910111213141516171819202122232412131415161718301920212223242526272829307 unmodified lines38394044414243229 unmodified lines2732742752802812822762772782792872802812822836 unmodified lines2902912923003012932942952962978 unmodified lines#include <objc/message.h>#endif
// Make helper an accessory app — can show windows but doesn't steal focus or appear in Dockstatic void makeAccessoryProcess(){#if JUCE_MAC id nsApp = ((id(*)(id, SEL))objc_msgSend)((id)objc_getClass("NSApplication"), sel_registerName("sharedApplication")); // NSApplicationActivationPolicyAccessory = 1 (windows allowed, no Dock icon, no focus steal) ((void(*)(id, SEL, long))objc_msgSend)(nsApp, sel_registerName("setActivationPolicy:"), 1);#endif}
// Show window without stealing focus from Abletonstatic void showWindowWithoutFocus(juce::Component* window)// Show window as floating panel without activating this app or stealing focusstatic void showAsFloatingPanel(juce::Component* window){#if JUCE_MAC if (auto* peer = window->getPeer()) { auto* nsWindow = (id)peer->getNativeHandle(); // [nsWindow orderFrontRegardless] — shows window without activating the app
// Set window level to floating (above normal windows) // NSFloatingWindowLevel = 3 ((void(*)(id, SEL, long))objc_msgSend)(nsWindow, sel_registerName("setLevel:"), 3);
// Don't hide on deactivate (stay visible when helper loses focus) ((void(*)(id, SEL, int))objc_msgSend)(nsWindow, sel_registerName("setHidesOnDeactivate:"), 0);
// Show without activating this app ((void(*)(id, SEL))objc_msgSend)(nsWindow, sel_registerName("orderFrontRegardless")); }#endif7 unmodified lines : DocumentWindow(name, juce::Colour(0xff1a1a2e), DocumentWindow::allButtons, true) { setUsingNativeTitleBar(true); setAlwaysOnTop(true); }
void closeButtonPressed() override229 unmodified lines { if (!plugin) return;
// Set as accessory app — allows windows without stealing focus makeAccessoryProcess();
// If window exists but hidden, just show it if (guiWindow) { guiWindow->setVisible(true); showWindowWithoutFocus(guiWindow.get()); showAsFloatingPanel(guiWindow.get()); return; }
6 unmodified lines guiWindow->centreWithSize(editor->getWidth(), editor->getHeight()); guiWindow->setVisible(true);
// Show without stealing focus from Ableton showWindowWithoutFocus(guiWindow.get()); // Make it float without stealing focus showAsFloatingPanel(guiWindow.get()); });}
Source/Helper/HelperPluginHost.cpp+14-21