Fix GUI focus: Remove makeAccessoryProcess entirely, use NSWindow level trick to float without activation
Browse files8 unmodified lines91011121314151617181920212223242526272829303132337 unmodified lines41424344454647229 unmodified lines2772782792802812822832842852862872882892906 unmodified lines2972982993003013023033048 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_MACid 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){#if JUCE_MACif (auto* peer = window->getPeer()){auto* nsWindow = (id)peer->getNativeHandle();// [nsWindow orderFrontRegardless] — shows window without activating the 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 focusmakeAccessoryProcess();// If window exists but hidden, just show itif (guiWindow){guiWindow->setVisible(true);showWindowWithoutFocus(guiWindow.get());return;}6 unmodified linesguiWindow->centreWithSize(editor->getWidth(), editor->getHeight());guiWindow->setVisible(true);// Show without stealing focus from AbletonshowWindowWithoutFocus(guiWindow.get());});}8 unmodified lines91011121314151617181920212223242526272829307 unmodified lines383940414243229 unmodified lines2732742752762772782792802812822836 unmodified lines2902912922932942952962978 unmodified lines#include <objc/message.h>#endif// Show window as floating panel without activating this app or stealing focusstatic void showAsFloatingPanel(juce::Component* window){#if JUCE_MACif (auto* peer = window->getPeer()){auto* nsWindow = (id)peer->getNativeHandle();// 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);}void closeButtonPressed() override229 unmodified lines{if (!plugin) return;// If window exists but hidden, just show itif (guiWindow){guiWindow->setVisible(true);showAsFloatingPanel(guiWindow.get());return;}6 unmodified linesguiWindow->centreWithSize(editor->getWidth(), editor->getHeight());guiWindow->setVisible(true);// Make it float without stealing focusshowAsFloatingPanel(guiWindow.get());});}
Source/Helper/HelperPluginHost.cpp+14-21